use of com.sun.jersey.spi.container.servlet.ServletContainer in project coprhd-controller by CoprHD.
the class AbstractSecuredWebServer method initServer.
/**
* Initialize server handlers, rest resources.
*
* @throws Exception
*/
protected void initServer() throws Exception {
_server = new Server();
initThreadPool();
initConnectors();
// AuthN servlet filters
servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/");
_server.setHandler(servletHandler);
((AbstractSessionManager) servletHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
if (_disabler != null) {
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_disablingFilter));
servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
_log.warn("security checks are disabled... skipped adding security filters");
} else {
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
}
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put("json", MediaType.APPLICATION_JSON_TYPE);
type.put("xml", MediaType.APPLICATION_XML_TYPE);
type.put("octet-stream", MediaType.APPLICATION_OCTET_STREAM_TYPE);
type.put("form-data", MediaType.MULTIPART_FORM_DATA_TYPE);
servletHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
// AuthZ resource filters
Map<String, Object> props = new HashMap<String, Object>();
props.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, _resourceFilterFactory);
// Adding the ContainerResponseFilter
props.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, _responseFilter);
config.setPropertiesAndFeatures(props);
}
if (_dbClient != null) {
// Otherwise there could be a dependency loop between services.
if (startDbClientInBackground) {
_log.info("starting dbclient in background");
new Thread() {
public void run() {
_dbClient.start();
}
}.start();
} else {
_log.info("starting dbclient");
_dbClient.start();
}
}
}
use of com.sun.jersey.spi.container.servlet.ServletContainer in project ANNIS by korpling.
the class AnnisServiceRunner method createWebServer.
private void createWebServer() {
// create beans
ctx = new GenericXmlApplicationContext();
ctx.setValidating(false);
AnnisXmlContextHelper.prepareContext(ctx);
ctx.load("file:" + Utils.getAnnisFile("conf/spring/Service.xml").getAbsolutePath());
ctx.refresh();
ResourceConfig rc = new PackagesResourceConfig("annis.service.internal", "annis.provider", "annis.rest.provider");
final IoCComponentProviderFactory factory = new SpringComponentProviderFactory(rc, ctx);
int port = overridePort == null ? ctx.getBean(QueryServiceImpl.class).getPort() : overridePort;
try {
// only allow connections from localhost
// if the administrator wants to allow external acccess he *has* to
// use a HTTP proxy which also should use SSL encryption
InetSocketAddress addr = new InetSocketAddress("localhost", port);
server = new Server(addr);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
server.setHandler(context);
server.setThreadPool(new ExecutorThreadPool());
ServletContainer jerseyContainer = new ServletContainer(rc) {
@Override
protected void initiate(ResourceConfig rc, WebApplication wa) {
wa.initiate(rc, factory);
}
};
ServletHolder holder = new ServletHolder(jerseyContainer);
context.addServlet(holder, "/*");
context.setInitParameter(EnvironmentLoader.ENVIRONMENT_CLASS_PARAM, MultipleIniWebEnvironment.class.getName());
if (useAuthentification) {
log.info("Using authentification");
context.setInitParameter(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, "file:" + System.getProperty("annis.home") + "/conf/shiro.ini," + "file:" + System.getProperty("annis.home") + "/conf/develop_shiro.ini");
} else {
log.warn("*NOT* using authentification, your ANNIS service *IS NOT SECURED*");
context.setInitParameter(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, "file:" + System.getProperty("annis.home") + "/conf/shiro_no_security.ini");
}
EnumSet<DispatcherType> gzipDispatcher = EnumSet.of(DispatcherType.REQUEST);
context.addFilter(GzipFilter.class, "/*", gzipDispatcher);
// configure Apache Shiro with the web application
context.addEventListener(new EnvironmentLoaderListener());
EnumSet<DispatcherType> shiroDispatchers = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ERROR);
context.addFilter(ShiroFilter.class, "/*", shiroDispatchers);
} catch (IllegalArgumentException ex) {
log.error("IllegalArgumentException at ANNIS service startup", ex);
isShutdownRequested = true;
errorCode = 101;
} catch (NullPointerException ex) {
log.error("NullPointerException at ANNIS service startup", ex);
isShutdownRequested = true;
errorCode = 101;
} catch (AnnisRunnerException ex) {
errorCode = ex.getExitCode();
}
}
use of com.sun.jersey.spi.container.servlet.ServletContainer in project opencast by opencast.
the class RestServiceTestEnv method setUpServer.
/**
* Return the base URL of the HTTP server. <code>http://host:port</code> public URL getBaseUrl() { return baseUrl; }
*
* Call in @BeforeClass annotated method.
*/
public void setUpServer() {
try {
// cut of any base pathbasestUrl might have
int port = baseUrl.getPort();
logger.info("Start http server at port " + port);
hs = new Server(port);
ServletContainer servletContainer = cfg.isSome() ? new ServletContainer(cfg.get()) : new ServletContainer();
ServletHolder jerseyServlet = new ServletHolder(servletContainer);
ServletContextHandler context = new ServletContextHandler(hs, "/");
context.addServlet(jerseyServlet, "/*");
hs.start();
} catch (Exception e) {
chuck(e);
}
}
use of com.sun.jersey.spi.container.servlet.ServletContainer in project coprhd-controller by CoprHD.
the class ErrorHandlingTest method setupServer.
@BeforeClass
public static void setupServer() throws Exception {
_server = new Server(port);
// AuthN servlet filters
ServletContextHandler rootHandler = new ServletContextHandler();
rootHandler.setContextPath("/");
_server.setHandler(rootHandler);
final StorageApplication application = new StorageApplication();
final Set<Object> resources = new HashSet<Object>();
resources.add(new ErrorHandlingTestResource());
resources.add(new ServiceCodeExceptionMapper());
application.setResource(resources);
final ResourceConfig config = new DefaultResourceConfig();
config.add(application);
rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
_server.start();
}
Aggregations