本文整理汇总了Java中com.sun.grizzly.http.servlet.ServletAdapter.setContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java ServletAdapter.setContextPath方法的具体用法?Java ServletAdapter.setContextPath怎么用?Java ServletAdapter.setContextPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.grizzly.http.servlet.ServletAdapter
的用法示例。
在下文中一共展示了ServletAdapter.setContextPath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJerseyAdapter
import com.sun.grizzly.http.servlet.ServletAdapter; //导入方法依赖的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;
}
示例2: initRestTestServletAdapter
import com.sun.grizzly.http.servlet.ServletAdapter; //导入方法依赖的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;
}
示例3: instantiateGrizzlyWebServer
import com.sun.grizzly.http.servlet.ServletAdapter; //导入方法依赖的package包/类
/**
* Instantiates the Grizzly Web Server
*/
private void instantiateGrizzlyWebServer() {
webServer = new GrizzlyWebServer(PORT);
final ServletAdapter sa = new ServletAdapter();
Servlet servletInstance = null;
try {
servletInstance = (HttpServlet) Class.forName("com.sun.jersey.spi.container.servlet.ServletContainer").newInstance();
} catch (final Exception ex) {
log.error("Cannot instantiate the Grizzly Servlet Container", ex);
}
sa.setServletInstance(servletInstance);
sa.addFilter(new RestApiLoginFilter(), "jerseyfilter", null);
sa.addInitParameter("javax.ws.rs.Application", OlatRestApplication.class.getName());
sa.setContextPath("/" + CONTEXT_PATH);
webServer.addGrizzlyAdapter(sa, null);
}
示例4: start
import com.sun.grizzly.http.servlet.ServletAdapter; //导入方法依赖的package包/类
/**
* Start HTTP server.
* @see #RestfulServer()
* @todo #1 Would be nice to add exception mapping here, in order
* to properly wrap exception messages sent to clients
*/
private void start() {
final java.util.logging.Logger root =
LogManager.getLogManager().getLogger("");
final Handler[] handlers = root.getHandlers();
for (int pos = 0; pos < handlers.length; pos += 1) {
root.removeHandler(handlers[pos]);
}
SLF4JBridgeHandler.install();
final GrizzlyWebServer gws = new GrizzlyWebServer(this.port(), ".");
final ServletAdapter adapter = new ServletAdapter();
adapter.addInitParameter(
"com.sun.jersey.config.property.packages",
"com.ymock.server"
);
adapter.setContextPath(RestfulServer.CONTEXT);
adapter.setServletInstance(new ServletContainer());
gws.addGrizzlyAdapter(adapter, new String[] {RestfulServer.CONTEXT});
try {
gws.start();
} catch (java.io.IOException ex) {
throw new IllegalStateException(ex);
}
Logger.debug(
this,
"#start(): server started"
);
}
示例5: main
import com.sun.grizzly.http.servlet.ServletAdapter; //导入方法依赖的package包/类
public static void main(String[] args) {
// static content is linked from here
GrizzlyWebServer server = new GrizzlyWebServer(8010);
//For very slow response extractors:
SelectorThread st = server.getSelectorThread();
st.setTransactionTimeout(700000);
//create UI resources
ServletAdapter ui = new ServletAdapter();
ui.addInitParameter(
"javax.ws.rs.Application",
"fr.eurecom.hotspots.web.hypertext.RegisterUI");
ui.setServletInstance(new ServletContainer());
// REST resources
ServletAdapter api = new ServletAdapter();
api.addInitParameter(
"javax.ws.rs.Application",
"fr.eurecom.hotspots.web.api.RegisterAPI");
api.setContextPath("/api");
api.setServletInstance(new ServletContainer());
// static content adapter
ServletAdapter staticContent = new ServletAdapter("ui");
staticContent.setContextPath("/");
staticContent.setHandleStaticResources(true);
// register all above defined adapters
server.addGrizzlyAdapter(api, new String[] {"/api"});
server.addGrizzlyAdapter(staticContent, new String[] {"/"});
// let's Grizzly run
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
}