本文整理了Java中org.apache.catalina.Context.addServletMapping()
方法的一些代码示例,展示了Context.addServletMapping()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.addServletMapping()
方法的具体详情如下:
包路径:org.apache.catalina.Context
类名称:Context
方法名:addServletMapping
[英]Add a new servlet mapping, replacing any existing mapping for the specified pattern.
[中]添加新的servlet映射,替换指定模式的任何现有映射。
代码示例来源:origin: apache/geode
public StandardWrapper addServlet(String path, String name, String clazz)
throws ServletException {
StandardWrapper servlet = (StandardWrapper) rootContext.createWrapper();
servlet.setName(name);
servlet.setServletClass(clazz);
servlet.setLoadOnStartup(1);
rootContext.addChild(servlet);
rootContext.addServletMapping(path, name);
servlet.setParent(rootContext);
// servlet.load();
return servlet;
}
代码示例来源:origin: apache/incubator-dubbo
context.addServletMapping("/*", "dispatcher");
ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
代码示例来源:origin: apache/incubator-dubbo
context.addServletMapping("/*", "dispatcher");
ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
代码示例来源:origin: pippo-java/pippo
wrapper.setServlet(pippoServlet);
context.addChild(wrapper);
context.addServletMapping(pippoFilterPath, name);
代码示例来源:origin: stackoverflow.com
Context rootContext = getTomcatsRootContextFromSomewhere();
Servlet dispatcherServlet = getDispatcherServletFromSomewhere();
// add the dispatcher servlet to the root context
Tomcat.addServlet(rootContext, "mySpringService", dispatcherServlet);
// add a mapping to the dispatcher servlet
rootContext.addServletMapping("/api/*", "mySpringService");
代码示例来源:origin: myrrix/myrrix-recommender
private static Wrapper addServlet(Context context, Servlet servlet, String path) {
String name = servlet.getClass().getSimpleName();
Wrapper servletWrapper = Tomcat.addServlet(context, name, servlet);
servletWrapper.setLoadOnStartup(1);
context.addServletMapping(path, name);
return servletWrapper;
}
代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9
@Override
public Set<String> addMapping(String... urlPatterns) {
if (urlPatterns == null) {
return Collections.emptySet();
}
Set<String> conflicts = new HashSet<String>();
for (String urlPattern : urlPatterns) {
if (context.findServletMapping(urlPattern) != null) {
conflicts.add(urlPattern);
}
}
if (!conflicts.isEmpty()) {
return conflicts;
}
for (String urlPattern : urlPatterns) {
context.addServletMapping(urlPattern, wrapper.getName());
}
return Collections.emptySet();
}
代码示例来源:origin: stackoverflow.com
Context context = (Context) wrapper.getParent();
Wrapper newWrapper = context.createWrapper();
newWrapper.setName(name);
newWrapper.setLoadOnStartup(1);
newWrapper.setServletClass(servletClass);
context.addChild(newWrapper);
context.addServletMapping(pattern, name);
代码示例来源:origin: fabric8io/shootout-docker-maven
public static void main(String[] args) throws LifecycleException, SQLException {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
File base = new File(System.getProperty("java.io.tmpdir"));
Context rootCtx = tomcat.addContext("/", base.getAbsolutePath());
Tomcat.addServlet(rootCtx, "log", new LogService());
rootCtx.addServletMapping("/*", "log");
tomcat.start();
tomcat.getServer().await();
}
代码示例来源:origin: org.wso2.ei/service-samples
public void startPeopleService() throws Exception {
final File base = createBaseDirectory();
log.info("Using base folder: " + base.getAbsolutePath());
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir(base.getAbsolutePath());
Context context = tomcat.addContext("/", base.getAbsolutePath());
Tomcat.addServlet(context, "CXFServlet", new CXFServlet());
context.addServletMapping("/rest/*", "CXFServlet");
context.addApplicationListener(ContextLoaderListener.class.getName());
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
context.addParameter("contextConfigLocation", AppConfig.class.getName());
tomcat.start();
tomcat.getServer().await();
}
代码示例来源:origin: org.wso2.esb/service-samples
public static void main(final String[] args) throws Exception {
final File base = createBaseDirectory();
log.info("Using base folder: " + base.getAbsolutePath());
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir( base.getAbsolutePath() );
Context context = tomcat.addContext( "/", base.getAbsolutePath() );
Tomcat.addServlet( context, "CXFServlet", new CXFServlet() );
context.addServletMapping( "/rest/*", "CXFServlet" );
context.addApplicationListener( ContextLoaderListener.class.getName() );
context.setLoader( new WebappLoader( Thread.currentThread().getContextClassLoader() ) );
context.addParameter( "contextClass", AnnotationConfigWebApplicationContext.class.getName() );
context.addParameter( "contextConfigLocation", MusicConfig.class.getName() );
tomcat.start();
tomcat.getServer().await();
}
代码示例来源:origin: org.wso2.ei/service-samples
public static void main(final String[] args) throws Exception {
final File base = createBaseDirectory();
log.info("Using base folder: " + base.getAbsolutePath());
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir( base.getAbsolutePath() );
Context context = tomcat.addContext( "/", base.getAbsolutePath() );
Tomcat.addServlet( context, "CXFServlet", new CXFServlet() );
context.addServletMapping( "/rest/*", "CXFServlet" );
context.addApplicationListener( ContextLoaderListener.class.getName() );
context.setLoader( new WebappLoader( Thread.currentThread().getContextClassLoader() ) );
context.addParameter( "contextClass", AnnotationConfigWebApplicationContext.class.getName() );
context.addParameter( "contextConfigLocation", MusicConfig.class.getName() );
tomcat.start();
tomcat.getServer().await();
}
代码示例来源:origin: org.wso2.esb/service-samples
public void startPeopleService() throws Exception {
final File base = createBaseDirectory();
log.info("Using base folder: " + base.getAbsolutePath());
final Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir(base.getAbsolutePath());
Context context = tomcat.addContext("/", base.getAbsolutePath());
Tomcat.addServlet(context, "CXFServlet", new CXFServlet());
context.addServletMapping("/rest/*", "CXFServlet");
context.addApplicationListener(ContextLoaderListener.class.getName());
context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
context.addParameter("contextConfigLocation", AppConfig.class.getName());
tomcat.start();
tomcat.getServer().await();
}
代码示例来源:origin: chrismattmann/lucene-geo-gazetteer
public static void launchService(int port, String indexPath)
throws IOException, LifecycleException {
Tomcat server = new Tomcat();
Context context = server.addContext("/", new File(".").getAbsolutePath());
System.setProperty(INDEX_PATH_PROP, indexPath);
Wrapper servlet = context.createWrapper();
servlet.setName("CXFNonSpringJaxrs");
servlet.setServletClass(CXFNonSpringJaxrsServlet.class.getName());
servlet.addInitParameter("jaxrs.serviceClasses", SearchResource.class.getName() + " " + HealthCheckAPI.class.getName());
servlet.setLoadOnStartup(1);
context.addChild(servlet);
context.addServletMapping("/api/*", "CXFNonSpringJaxrs");
System.out.println("Starting Embedded Tomcat on port : " + port );
server.setPort(port);
server.start();
server.getServer().await();
}
代码示例来源:origin: com.att.nsa/nsaServerLibrary
public void start () throws IOException
{
// create a servlet and context
final Context rootCtx = fTomcat.addContext ( "", makeTmpDir ( "uiContext" ).getAbsolutePath () );
Tomcat.addServlet ( rootCtx, kServletName, fServlet );
rootCtx.addServletMapping ( "/*", kServletName );
// determine the port
fTomcat.setPort ( fPort );
try
{
fTomcat.start ();
fTomcat.getServer().await ();
}
catch ( Exception e )
{
throw new RuntimeException ( e );
}
}
代码示例来源:origin: apache/tomcat-maven-plugin
private void createStaticContext( final Tomcat container, Context context, Host host )
{
if ( staticContextDocbase != null )
{
Context staticContext = container.addContext( staticContextPath, staticContextDocbase );
staticContext.setPrivileged( true );
Wrapper servlet = context.createWrapper();
servlet.setServletClass( DefaultServlet.class.getName() );
servlet.setName( "staticContent" );
staticContext.addChild( servlet );
staticContext.addServletMapping( "/", "staticContent" );
// see https://issues.apache.org/jira/browse/MTOMCAT-238
//host.addChild( staticContext );
}
}
代码示例来源:origin: net.disy.legato/legato-testing
@Override
public void addServletWithMapping(
final String contextPath,
final String servletClassName,
final String servletMapping) {
final Context context = getContext(contextPath);
final Wrapper wrapper = context.createWrapper();
wrapper.setName(servletClassName);
wrapper.setServletClass(servletClassName);
context.addChild(wrapper);
context.addServletMapping(contextPath + servletMapping, servletClassName);
}
代码示例来源:origin: apache/tomcat-maven-plugin
private void createStaticContext( final Embedded container, Context context, Host host )
{
if ( staticContextDocbase != null )
{
Context staticContext = container.createContext( staticContextPath, staticContextDocbase );
staticContext.setPrivileged( true );
Wrapper servlet = context.createWrapper();
servlet.setServletClass( DefaultServlet.class.getName() );
servlet.setName( "staticContent" );
staticContext.addChild( servlet );
staticContext.addServletMapping( "/", "staticContent" );
host.addChild( staticContext );
}
}
代码示例来源:origin: apache/tomcat-maven-plugin
private void createStaticContext( final Tomcat container, Context context, Host host )
{
if ( staticContextDocbase != null )
{
Context staticContext = container.addContext( staticContextPath, staticContextDocbase );
Tomcat.initWebappDefaults(staticContext);
staticContext.setPrivileged( true );
Wrapper servlet = context.createWrapper();
servlet.setServletClass( DefaultServlet.class.getName() );
servlet.setName( "staticContent" );
staticContext.addChild( servlet );
staticContext.addServletMapping( "/", "staticContent" );
// see https://issues.apache.org/jira/browse/MTOMCAT-238
//host.addChild( staticContext );
}
}
代码示例来源:origin: poutsma/web-function-sample
public void startTomcatServer() throws LifecycleException {
RouterFunction<?> route = routingFunction();
HttpHandler httpHandler = toHttpHandler(route);
Tomcat tomcatServer = new Tomcat();
tomcatServer.setHostname(HOST);
tomcatServer.setPort(PORT);
Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
rootContext.addServletMapping("/", "httpHandlerServlet");
tomcatServer.start();
}
内容来源于网络,如有侵权,请联系作者删除!