本文整理匯總了Java中com.sun.jersey.spi.container.servlet.ServletContainer類的典型用法代碼示例。如果您正苦於以下問題:Java ServletContainer類的具體用法?Java ServletContainer怎麽用?Java ServletContainer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServletContainer類屬於com.sun.jersey.spi.container.servlet包,在下文中一共展示了ServletContainer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: WebServer
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
public WebServer(URI endpoint) throws IOException {
this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {
@Override
public void service(Request rqst, Response rspns) throws Exception {
rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
rspns.getWriter().write("404: not found");
}
});
WebappContext context = new WebappContext("WebappContext", BASE_PATH);
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
PackagesResourceConfig.class.getName());
StringJoiner sj = new StringJoiner(",");
for (String s : PACKAGES) {
sj.add(s);
}
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
registration.addMapping(BASE_PATH);
context.deploy(server);
}
示例2: createJerseyAdapter
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
private ServletAdapter createJerseyAdapter(Endpoint e) {
ServletAdapter jersey = new ServletAdapter();
jersey.setServletInstance(new ServletContainer());
jersey.addInitParameter("com.sun.jersey.config.property.packages",
"org.apache.zookeeper.server.jersey.resources");
jersey.setContextPath(e.getContext());
Credentials c = Credentials.join(e.getCredentials(), cfg
.getCredentials());
if (!c.isEmpty()) {
jersey.addFilter(new HTTPBasicAuth(c), e.getContext()
+ "-basic-auth", null);
}
return jersey;
}
示例3: configureWebAppServlets
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
protected void configureWebAppServlets() {
// Add in the web services filters/serves if app has them.
// Using Jersey/guice integration module. If user has web services
// they must have also bound a default one in their webapp code.
if (this.wsName != null) {
// There seems to be an issue with the guice/jersey integration
// where we have to list the stuff we don't want it to serve
// through the guicecontainer. In this case its everything except
// the the web services api prefix. We can't just change the filter
// from /* below - that doesn't work.
String regex = "(?!/" + this.wsName + ")";
serveRegex(regex).with(DefaultWrapperServlet.class);
Map<String, String> params = new HashMap<String, String>();
params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
params.put(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING, "true");
params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
filter("/*").through(getWebAppFilterClass(), params);
}
}
示例4: validate
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
private static void validate(VersionModel model) {
assertNotNull(model);
assertNotNull(model.getRESTVersion());
assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
String osVersion = model.getOSVersion();
assertNotNull(osVersion);
assertTrue(osVersion.contains(System.getProperty("os.name")));
assertTrue(osVersion.contains(System.getProperty("os.version")));
assertTrue(osVersion.contains(System.getProperty("os.arch")));
String jvmVersion = model.getJVMVersion();
assertNotNull(jvmVersion);
assertTrue(jvmVersion.contains(System.getProperty("java.vm.vendor")));
assertTrue(jvmVersion.contains(System.getProperty("java.version")));
assertTrue(jvmVersion.contains(System.getProperty("java.vm.version")));
assertNotNull(model.getServerVersion());
String jerseyVersion = model.getJerseyVersion();
assertNotNull(jerseyVersion);
assertEquals(jerseyVersion, ServletContainer.class.getPackage()
.getImplementationVersion());
}
示例5: testGetStargateVersionText
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
@Test
public void testGetStargateVersionText() throws IOException {
Response response = client.get("/version", Constants.MIMETYPE_TEXT);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
String body = Bytes.toString(response.getBody());
assertTrue(body.length() > 0);
assertTrue(body.contains(RESTServlet.VERSION_STRING));
assertTrue(body.contains(System.getProperty("java.vm.vendor")));
assertTrue(body.contains(System.getProperty("java.version")));
assertTrue(body.contains(System.getProperty("java.vm.version")));
assertTrue(body.contains(System.getProperty("os.name")));
assertTrue(body.contains(System.getProperty("os.version")));
assertTrue(body.contains(System.getProperty("os.arch")));
assertTrue(body.contains(ServletContainer.class.getPackage()
.getImplementationVersion()));
}
示例6: start
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
/**
* Starts the server, which will listen to the given path going forward.
* @throws Exception
*/
public void start() throws Exception {
logger.info("Starting API server on {}:{}{}", HOST, port, contextPath);
server = new Server();
server.addListener(String.format("%s:%d", HOST, port));
ServletHttpContext context = (ServletHttpContext) server.getContext(contextPath);
context.addServlet(SERVLET_NAME, SERVLET_PATH, ServletContainer.class.getName());
context.getServletHandler().getServletHolder(SERVLET_NAME)
.setInitParameter(INIT_PARAM_PACKAGES, getClass().getPackage().getName());
if (!Strings.isNullOrEmpty(adsPropertiesPath)) {
context.getServletHandler().getServletHolder(SERVLET_NAME)
.setInitParameter(INIT_PARAM_ADS_PROPERTIES, adsPropertiesPath);
}
if (!Strings.isNullOrEmpty(propertiesPath)) {
context.getServletHandler().getServletHolder(SERVLET_NAME)
.setInitParameter(INIT_PARAM_PROPERTIES, propertiesPath);
}
server.start();
}
示例7: createComputeRealtimeServer
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
/**
* Creates a new {@link ComputeRealtimeServer}
*
* @param config
* The chatalytics config
* @return A newly created {@link ComputeRealtimeServer}
*/
public ComputeRealtimeServer createComputeRealtimeServer() {
Server server = new Server(config.computeConfig.rtComputePort);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
StatusResource.class.getPackage().toString());
server.setHandler(context);
ServerContainer wscontainer;
try {
wscontainer = WebSocketServerContainerInitializer.configureContext(context);
wscontainer.addEndpoint(RealtimeResource.class);
} catch (ServletException | DeploymentException e) {
throw new RuntimeException("Can't instantiate websocket. Reason: " + e.getMessage());
}
return new ComputeRealtimeServer(server);
}
示例8: initRestTestServletAdapter
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
public static ServletAdapter initRestTestServletAdapter(Class<?> applicationConfigClass, int testServerPort,
String testContextPath, String testServletPath, boolean enableJPA) {
final ServletAdapter adapter = new ServletAdapter();
adapter.addInitParameter(ServletContainer.APPLICATION_CONFIG_CLASS, applicationConfigClass.getName());
adapter.addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", LoggingFilter.class.getName());
adapter.addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", LoggingFilter.class.getName());
adapter.addServletListener(ContextLoaderListener.class.getName());
if (enableJPA) {
adapter.addFilter(new OpenEntityManagerInViewFilter(), "openEntityManagerInViewFilter", null);
}
adapter.setServletInstance(new SpringServlet());
adapter.setContextPath(testContextPath);
adapter.setServletPath(testServletPath);
return adapter;
}
示例9: getJerseyContext
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
/**
* Function to generate the Jersey handler, with configurations for resource scanning and filter inclusion
*
* @return
* @throws IOException
* @throws MalformedURLException
*/
private static ServletContextHandler getJerseyContext()
throws IOException {
// Code to add Jersey Servlet to the Jetty Handlers
log.info("Initializing Jersey Servlet configuration");
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
ServletHolder h = new ServletHolder(new ServletContainer());
h.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
h.setInitParameter("com.sun.jersey.config.property.packages",
"com.topology.resource");
h.setInitOrder(1);
context.addServlet(h, "/rest/*");
return context;
}
示例10: startServer
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
/**
* @throws Exception
* @throws InterruptedException
*/
public static void startServer() throws Exception, InterruptedException {
Server server = new Server(8089);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig");
servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "rest");
servletHolder.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
context.addServlet(servletHolder, "/*");
server.setHandler(context);
server.start();
server.join();
}
示例11: configureServlets
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
@Override
public void configureServlets() {
setup();
serve("/", "/__stop").with(Dispatcher.class);
for (String path : this.getServePathSpecs()) {
serve(path).with(Dispatcher.class);
}
String regex = "(?!/ws)";
serveRegex(regex).with(SliderDefaultWrapperServlet.class);
Map<String, String> params = new HashMap<String, String>();
params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
params.put(ResourceConfig.FEATURE_XMLROOTELEMENT_PROCESSING, "true");
params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
//params.put("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
//params.put("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
//params.put("com.sun.jersey.config.feature.Trace", "true");
params.put("com.sun.jersey.config.property.WadlGeneratorConfig",
AMWadlGeneratorConfig.CLASSNAME);
filter("/*").through(GuiceContainer.class, params);
}
示例12: startServer
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
public void startServer(int port, String classBound) throws BindException,
Exception {
sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter(
"com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig");
sh.setInitParameter("com.sun.jersey.config.property.packages",
classBound);
// custom parameters
// Map<String, Object> initParameters = getCustomInitParamters(port);
// sh.setInitParameters(initParameters);
Server server = new Server(port);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(sh, "/*");
server.start();
}
示例13: configure
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
@Override
protected void configure() {
bind(RefAppResource.class);
// Install servlet module setting a the Jersey/Guice integration.
install(new ServletModule() {
@Override
protected void configureServlets() {
filter("/*").through(GuiceContainer.class,
ImmutableMap.of(JSONConfiguration.FEATURE_POJO_MAPPING, "true",
ResourceConfig.FEATURE_TRACE, "true",
ResourceConfig.FEATURE_TRACE_PER_REQUEST, "true",
ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true"));
}
});
}
示例14: start
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
public static void start() {
WebappContext webappContext = new WebappContext("TestContext");
ServletRegistration registration = webappContext.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, "org.moskito.central.connectors.rest;org.codehaus.jackson.jaxrs");
registration.addMapping("/*");
SSLContextConfigurator sslConfigurator = new SSLContextConfigurator();
sslConfigurator.setKeyStoreFile("./target/test-classes/central_server_keystore.jks");
sslConfigurator.setKeyStorePass("moskito");
SSLContext sslContext = sslConfigurator.createSSLContext();
try {
server = GrizzlyServerFactory.createHttpServer(
getBaseURI(),
null,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)
);
webappContext.deploy(server);
server.start();
} catch (Exception e) {
System.out.println("Error while starting the test server: " + e);
}
}
示例15: testWebAppBuilder
import com.sun.jersey.spi.container.servlet.ServletContainer; //導入依賴的package包/類
@Test
public void testWebAppBuilder() throws Exception {
assertThat(webappServerBuilder.servletConfigurations.size(), equalTo(2));
ServletConfiguration jaxRsConfig = webappServerBuilder.servletConfigurations.get(0);
assertThat(jaxRsConfig.servletClass.equals(ServletContainer.class), equalTo(true));
assertThat(jaxRsConfig.initParameters.get("com.sun.jersey.config.property.packages"), equalTo(jerseyScanPackages));
assertThat(jaxRsConfig.initParameters.get("com.sun.jersey.api.json.POJOMappingFeature"), equalTo("true"));
assertThat(jaxRsConfig.pathSpecs.get(0), equalTo(restPathSpec));
ServletConfiguration staticConfig = webappServerBuilder.servletConfigurations.get(1);
assertThat(staticConfig.servletClass.equals(DefaultServlet.class), equalTo(true));
assertThat(staticConfig.initParameters.get("resourceBase"), equalTo(resourceBase));
assertThat(staticConfig.pathSpecs.get(0), equalTo("/"));
assertThat(server.port, equalTo(serverPort));
assertThat(server.contextName, equalTo("/"));
server.toString();
}