NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package uol.gaudi.rest;

import java.util.Enumeration;
import java.util.jar.Manifest;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.servlet.ServletContext;
import javax.ws.rs.ApplicationPath;

import org.apache.log4j.Logger;
import org.glassfish.hk2.api.DynamicConfiguration;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.jersey.internal.inject.Injections;
import org.glassfish.jersey.process.internal.RequestScoped;
import org.glassfish.jersey.server.ResourceConfig;

import uol.gaudi.rest.cache.RestCache;
import uol.gaudi.rest.cache.RestCacheImpl;
import uol.gaudi.rest.configuration.Config;
import uol.gaudi.rest.configuration.ConfigImpl;
import uol.gaudi.rest.configuration.SymmetricKeyConfigurationImpl;
import uol.gaudi.rest.db.DBService;
import uol.gaudi.rest.db.dao.ServiceUserLastSigninDao;
import uol.gaudi.rest.model.SymmetricKey;
import uol.gaudi.rest.service.AuthorizationServiceFactory;
import uol.gaudi.rest.service.CryptoServiceFactory;
import uol.gaudi.rest.service.InscriptionServiceFactory;
import uol.gaudi.rest.service.SaltServiceFactory;
import uol.gaudi.rest.service.SymmetricKeyConfigurationFactory;
import uol.gaudi.rest.service.SymmetricKeyFactory;
import uol.gaudi.rest.service.implementation.AuthorizationServiceFactoryImpl;
import uol.gaudi.rest.service.implementation.CryptoServiceFactoryImpl;
import uol.gaudi.rest.service.implementation.InscriptionServiceFactoryImpl;
import uol.gaudi.rest.service.implementation.SaltServiceFactoryImpl;
import uol.gaudi.rest.service.implementation.SymmetricKeyFactoryImpl;
import uol.gaudi.rest.util.Version;

@ApplicationPath("/")
public final class GaudiRestApplication extends ResourceConfig
{

private static final Logger LOGGER = Logger.getLogger(GaudiRestApplication.class);

@Inject
public GaudiRestApplication(final ServiceLocator serviceLocator)
{
try
{
final ServletContext ctx = getServletContext();

LOGGER.info(String.format("%s versao: %s", ctx.getServletContextName(),
new Version(new Manifest(ctx.getResourceAsStream("/META-INF/MANIFEST.MF"))).getVersionString()));
LOGGER.info(String.format("container versao: %s", ctx.getServerInfo()));
LOGGER.info(String.format("servlet API: %s.%s", ctx.getMajorVersion(), ctx.getMinorVersion()));

if (LOGGER.isDebugEnabled())
{

final Enumeration<String> initParamsNames = ctx.getInitParameterNames();
final StringBuilder initParams = new StringBuilder();

while (initParamsNames.hasMoreElements())
{
final String key = initParamsNames.nextElement();
initParams.append(key);
initParams.append('=');
initParams.append(ctx.getInitParameter(key));
initParams.append(',');
}

LOGGER.debug(String.format("Parametros de inicializacao da servlet (web.xml) [%s]", initParams));
}

packages(ctx.getInitParameter("com.sun.jersey.config.property.packages").split(";"));

LOGGER.info(String.format("Classes mapeadas como recursos: n%s", getClasses()));

// inicialzando

// inicializacao de classes singletons obrigatorias
final Config cfg = new ConfigImpl(ctx);
final SymmetricKeyConfigurationFactory symmetricKeyConfigurationFactory = new SymmetricKeyConfigurationImpl(
cfg);
final CustomConnectionManagerFactory connFactory = new CustomConnectionManagerFactory(cfg);
final AuthorizationServiceFactory authFactory = new AuthorizationServiceFactoryImpl(cfg, connFactory);
final InscriptionServiceFactory inscAuthFactory = new InscriptionServiceFactoryImpl(cfg, connFactory);
final SaltServiceFactory saltServiceFactory = new SaltServiceFactoryImpl(connFactory);
final CryptoServiceFactory cryptoServiceFactory = new CryptoServiceFactoryImpl(connFactory,
ctx.getInitParameter("maxNumberCryptoConfig"), cfg);
final SymmetricKeyFactory symmetricKeyFactory = new SymmetricKeyFactoryImpl(
symmetricKeyConfigurationFactory, connFactory);
final RestCache<Integer, SymmetricKey> restCache = new RestCacheImpl<Integer, SymmetricKey>();

LOGGER.info("Registrando injectables ...");

final DynamicConfiguration dc = Injections.getConfiguration(serviceLocator);

// singleton instance binding

Injections.addBinding(Injections.newBinder(cfg).to(Config.class), dc);
Injections.addBinding(
Injections.newBinder(symmetricKeyConfigurationFactory).to(SymmetricKeyConfigurationFactory.class),
dc);
Injections.addBinding(Injections.newBinder(authFactory).to(AuthorizationServiceFactory.class), dc);
Injections.addBinding(Injections.newBinder(inscAuthFactory).to(InscriptionServiceFactory.class), dc);
Injections.addBinding(Injections.newBinder(saltServiceFactory).to(SaltServiceFactory.class), dc);
Injections.addBinding(Injections.newBinder(symmetricKeyFactory).to(SymmetricKeyFactory.class), dc);
Injections.addBinding(
Injections.newBinder(restCache).to(new TypeLiteral<RestCache<Integer, SymmetricKey>>() {
}), dc);
Injections.addBinding(Injections.newBinder(cryptoServiceFactory).to(CryptoServiceFactory.class), dc);

Injections.addBinding(
Injections.newFactoryBinder(new EntityManagerFactoryInjector()).to(EntityManager.class)
.in(RequestScoped.class), dc);
Injections.addBinding(Injections.newBinder(DBService.class).to(DBService.class), dc);
Injections.addBinding(
Injections.newBinder(ServiceUserLastSigninDao.class).to(ServiceUserLastSigninDao.class), dc);

// commits changes
dc.commit();
}
catch (Exception e)
{
LOGGER.fatal(
"O Gaudi Server sera encerrado pois houve erro na sua inicializacao, por favor verifique todas as dependencias para depois fazer o restart",
e);
System.exit(-1);
}
}

private ServletContext getServletContext()
{
try
{
final ClassLoader parentClassLoader = this.getClassLoader().getParent();

final Class<?> webAppCtx = Class
.forName("org.eclipse.jetty.webapp.WebAppContext", false, parentClassLoader);
final Class<?> ctxHandler = Class.forName("org.eclipse.jetty.server.handler.ContextHandler", false,
parentClassLoader);

final Object obj = webAppCtx.getDeclaredMethod("getCurrentWebAppContext").invoke(webAppCtx);

return (ServletContext) ctxHandler.getDeclaredMethod("getServletContext").invoke(obj);
}
catch (Exception e)
{
throw new RuntimeException("Falha ao acessar o contexto do Jetty", e);
}
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.