本文整理汇总了Java中org.glassfish.jersey.servlet.ServletContainer类的典型用法代码示例。如果您正苦于以下问题:Java ServletContainer类的具体用法?Java ServletContainer怎么用?Java ServletContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletContainer类属于org.glassfish.jersey.servlet包,在下文中一共展示了ServletContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initApi
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
private void initApi() {
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/api");
servletHandler.getSessionHandler().setSessionManager(sessionManager);
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
resourceConfig.packages(ServerResource.class.getPackage().getName());
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);
}
示例2: activate
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
@Activate
void activate() throws Exception {
super.register(JacksonJaxbJsonProvider.class);
super.property(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
Properties props = new Properties();
props.setProperty(JDBC_URL, "jdbc:h2:./ismPlugin");
props.setProperty(JDBC_USER, "admin");
props.setProperty(JDBC_PASSWORD, "abc12345");
DataSource ds = this.jdbcFactory.createDataSource(props);
this.em = this.resourceFactory
.getProviderFor(this.builder, singletonMap("javax.persistence.nonJtaDataSource", (Object) ds), null)
.getResource(this.txControl);
this.domainApis.init(this.em, this.txControl);
this.deviceApis.init(this.em, this.txControl);
this.securityGroupApis.init(this.em, this.txControl);
this.securityGroupInterfaceApis.init(this.em, this.txControl);
super.registerInstances(this.domainApis, this.deviceApis, this.securityGroupApis,
this.securityGroupInterfaceApis);
this.container = new ServletContainer(this);
}
开发者ID:opensecuritycontroller,项目名称:security-mgr-sample-plugin,代码行数:27,代码来源:SecurityManagerServletDelegate.java
示例3: setup
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
/**
* Setup the test by deploying an embedded tomcat and adding the rest endpoints.
* @throws Throwable Throws uncaught throwables for test to fail.
*/
@Before
public void setup() throws Throwable {
registryTomcat = new Tomcat();
registryTomcat.setPort(3000);
registryTomcat.setBaseDir(testWorkingDir);
Context context = registryTomcat.addWebapp(CONTEXT, testWorkingDir);
context.addApplicationListener(RegistryStartup.class.getName());
ResourceConfig restServletConfig = new ResourceConfig();
restServletConfig.register(RegistryREST.class);
restServletConfig.register(Registry.class);
ServletContainer restServlet = new ServletContainer(restServletConfig);
registryTomcat.addServlet(CONTEXT, "restServlet", restServlet);
context.addServletMappingDecoded("/rest/*", "restServlet");
registryTomcat.start();
}
示例4: configure
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
@Override
protected void configure() {
super.configure();
bind(ResourceConfig.class).toProvider(ResourceConfigProvider.class).in(Singleton.class);
bind(ServletContainer.class).to(DefaultServletContainer.class);
contribute(FilterChainConfigurator.class, new FilterChainConfigurator() {
@Override
public void configure(FilterChainManager filterChainManager) {
filterChainManager.createChain("/rest/**", "noSessionCreation, authcBasic");
}
});
contribute(JerseyConfigurator.class, new JerseyConfigurator() {
@Override
public void configure(ResourceConfig resourceConfig) {
resourceConfig.packages(RestModule.class.getPackage().getName());
}
});
}
示例5: jerseyServletRegistration
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
@Bean
public ServletRegistrationBean jerseyServletRegistration(
JerseyProperties jerseyProperties, ResourceConfig config) {
ServletRegistrationBean registration = new ServletRegistrationBean(
new ServletContainer(config));
for (Map.Entry<String, String> entry : jerseyProperties.getInit().entrySet()) {
registration.addInitParameter(entry.getKey(), entry.getValue());
}
registration.addUrlMappings("/" +
(StringUtils.isEmpty(lyreProperties.getApplicationPath()) ? "api" : lyreProperties.getApplicationPath())
+ "/*");
registration.setName(APIx.class.getName());
registration.setLoadOnStartup(1);
return registration;
}
示例6: start
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
@Override
public void start() {
System.out.println("Starting GrizzlyTestContainer...");
try {
this.server = GrizzlyHttpServerFactory.createHttpServer(uri, rc);
// Initialize and register Jersey Servlet
WebappContext context = new WebappContext("WebappContext", "");
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter("javax.ws.rs.Application", rc.getClass().getName());
// Add an init parameter - this could be loaded from a parameter in the constructor
registration.setInitParameter("myparam", "myvalue");
registration.addMapping("/*");
context.deploy(server);
} catch (ProcessingException e) {
throw new TestContainerException(e);
}
}
示例7: createRestService
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
private Handler createRestService() {
ResourceConfig rc = new ResourceConfig();
localRestResources.forEach(rc::register);
rc.register(JacksonFeature.class);
rc.register(CORSFilter.class);
rc.addProperties(new HashMap<String,Object>() {{
// Turn off buffering so results can be streamed
put(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);
}});
ServletHolder holder = new ServletHolder(new ServletContainer(rc));
ServletContextHandler sch = new ServletContextHandler();
sch.setContextPath("/api/v1");
sch.addServlet(holder, "/*");
return sch;
}
示例8: createRestService
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
private Handler createRestService() {
ResourceConfig rc = new ResourceConfig();
rc.register(systemResource);
rc.register(appResource);
rc.register(JacksonFeature.class);
rc.register(CORSFilter.class);
SwaggerDocs.registerSwaggerJsonResource(rc);
rc.addProperties(new HashMap<String,Object>() {{
// Turn off buffering so results can be streamed
put(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);
}});
ServletHolder holder = new ServletHolder(new ServletContainer(rc));
ServletContextHandler sch = new ServletContextHandler();
sch.setContextPath("/api/v1");
sch.addServlet(holder, "/*");
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setHandler(sch);
return gzipHandler;
}
示例9: tomcat
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
@Bean
public TomcatEmbeddedServletContainerFactory tomcat() {
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
Wrapper jerseyServlet = context.createWrapper();
String servletName = Application.class.getName();
jerseyServlet.setName(servletName);
jerseyServlet.setServletClass(ServletContainer.class.getName());
jerseyServlet.setServlet(new ServletContainer());
jerseyServlet.setOverridable(false);
context.addChild(jerseyServlet);
context.addServletMapping("/*", servletName);
}
};
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:JerseyAutoConfigurationServletContainerTests.java
示例10: SchedulerApiServer
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
public SchedulerApiServer(SchedulerConfig schedulerConfig, Collection<Object> resources) {
this.port = schedulerConfig.getApiServerPort();
this.server = JettyHttpContainerFactory.createServer(
UriBuilder.fromUri("http://0.0.0.0/").port(this.port).build(),
new ResourceConfig(MultiPartFeature.class).registerInstances(new HashSet<>(resources)),
false /* don't start yet. wait for start() call below. */);
this.startTimeout = schedulerConfig.getApiServerInitTimeout();
ServletContextHandler context = new ServletContextHandler();
// Metrics + Prometheus
Metrics.configureMetricsEndpoints(context, "/v1/metrics", "/v1/metrics/prometheus");
// Resources
ResourceConfig resourceConfig = new ResourceConfig(MultiPartFeature.class)
.registerInstances(new HashSet<>(resources));
ServletHolder resourceHolder = new ServletHolder(new ServletContainer(resourceConfig));
context.addServlet(resourceHolder, "/*");
final InstrumentedHandler handler = new InstrumentedHandler(Metrics.getRegistry());
handler.setHandler(context);
server.setHandler(handler);
}
示例11: main
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
Logger mainLogger = Logger.getInstance();
mainLogger.out(Level.INFORMATIVE, "Main", "Starting server");
Server server = new Server(8080);
mainLogger.out(Level.INFORMATIVE, "Main", "Set handler");
server.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "view");
server.start();
server.join();
mainLogger.out(Level.INFORMATIVE, "Main", "Server started");
}
示例12: start
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
public void start() {
workingDir.mkdirs();
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("javax.ws.rs.Application", AssemblerApp.class.getCanonicalName());
Server jettyServer = new Server(port);
jettyServer.setHandler(context);
try {
jettyServer.start();
int runningPort = getPort(jettyServer);
System.out.printf("Server started successfully and is running on port %s.\n", runningPort);
writePort(runningPort);
jettyServer.join();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
jettyServer.destroy();
}
}
示例13: contextInitialized
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
ServletContainer servlet = new ServletContainer(new DefaultApplication());
ServletRegistration.Dynamic defaultWebapp = context.addServlet(DEFAULT_WEBAPP, servlet);
if (null != defaultWebapp) {
defaultWebapp.addMapping("/*");
defaultWebapp.setLoadOnStartup(1);
}
ParsecWrapperServlet swaggerServlet = new ParsecWrapperServlet();
ServletRegistration.Dynamic swagger = context.addServlet(SWAGGER_UI, swaggerServlet);
if (null != swagger) {
swagger.addMapping("/static/*");
}
}
示例14: initializeServer
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
private void initializeServer() {
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.packages(GridServices.class.getPackage().getName());
resourceConfig.register(JacksonJaxbJsonProvider.class);
final Grid grid = this;
resourceConfig.register(new AbstractBinder() {
@Override
protected void configure() {
bind(grid).to(Grid.class);
bind(fileManager).to(FileProvider.class);
}
});
ServletContainer servletContainer = new ServletContainer(resourceConfig);
ServletHolder sh = new ServletHolder(servletContainer);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(sh, "/*");
server = new Server(port);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { context});
server.setHandler(contexts);
}
示例15: start
import org.glassfish.jersey.servlet.ServletContainer; //导入依赖的package包/类
public void start(Controller controller) throws Exception {
this.controller = controller;
Server server = new Server(REST_SERVICE_PORT);
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath("");
servletContextHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig(controller))), "/*");
server.setHandler(servletContextHandler);
try {
server.start();
server.join();
} finally {
server.destroy();
}
}