本文整理了Java中io.undertow.servlet.Servlets.servlet()
方法的一些代码示例,展示了Servlets.servlet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Servlets.servlet()
方法的具体详情如下:
包路径:io.undertow.servlet.Servlets
类名称:Servlets
方法名:servlet
[英]Creates a new servlet description with the given class. The servlet name is inferred from the simple name of the class.
[中]使用给定的类创建新的servlet描述。servlet名称是从类的简单名称推断出来的。
代码示例来源:origin: openzipkin/brave
@Override protected void init(DeploymentInfo servletBuilder) {
addFilterMappings(servletBuilder);
servletBuilder.addServlets(
Servlets.servlet("HelloServlet", HelloServlet.class).addMapping("/*")
);
}
代码示例来源:origin: openzipkin/brave
@Override protected void init(DeploymentInfo servletBuilder) {
servletBuilder.addServlets(
servlet("Unsampled", ServletContainer.class)
.setLoadOnStartup(1)
.addInitParam("javax.ws.rs.Application", Unsampled.class.getName())
.addMapping("/unsampled"),
servlet("Traced", ServletContainer.class)
.setLoadOnStartup(1)
.addInitParam("javax.ws.rs.Application", TracedApp.class.getName())
.addMapping("/traced"),
servlet("TracedExtra", ServletContainer.class)
.setLoadOnStartup(1)
.addInitParam("javax.ws.rs.Application", TracedExtraApp.class.getName())
.addMapping("/tracedextra"),
servlet("Traced128", ServletContainer.class)
.setLoadOnStartup(1)
.addInitParam("javax.ws.rs.Application", Traced128App.class.getName())
.addMapping("/traced128"),
servlet("App", ServletContainer.class)
.setLoadOnStartup(1)
.addInitParam("javax.ws.rs.Application", App.class.getName())
.addMapping("/*")
);
}
代码示例来源:origin: spring-projects/spring-framework
ServletInfo servletInfo = servlet("DispatcherServlet", DispatcherServlet.class, servletFactory)
.addMapping("/").setAsyncSupported(true);
DeploymentInfo servletBuilder = deployment()
代码示例来源:origin: openzipkin/brave
@Override protected void init(DeploymentInfo servletBuilder) {
servletBuilder.addFilter(new FilterInfo("Unsampled", Unsampled.class))
.addFilterUrlMapping("Unsampled", "/unsampled", REQUEST)
.addFilterUrlMapping("Unsampled", "/unsampled/api", REQUEST)
.addFilter(new FilterInfo("OnlySampledLocal", OnlySampledLocal.class))
.addFilterUrlMapping("OnlySampledLocal", "/onlysampledlocal", REQUEST)
.addFilterUrlMapping("OnlySampledLocal", "/onlysampledlocal/api", REQUEST)
.addFilter(new FilterInfo("Traced", Traced.class))
.addFilterUrlMapping("Traced", "/traced", REQUEST)
.addFilterUrlMapping("Traced", "/traced/api", REQUEST)
.addFilter(new FilterInfo("TracedExtra", TracedExtra.class))
.addFilterUrlMapping("TracedExtra", "/tracedextra", REQUEST)
.addFilterUrlMapping("TracedExtra", "/tracedextra/api", REQUEST)
.addFilter(new FilterInfo("TracedCorrelated", TracedCorrelated.class))
.addFilterUrlMapping("TracedCorrelated", "/tracedcorrelated", REQUEST)
.addFilterUrlMapping("TracedCorrelated", "/tracedcorrelated/api", REQUEST)
.addFilter(new FilterInfo("Traced128", Traced128.class))
.addFilterUrlMapping("Traced128", "/traced128", REQUEST)
.addFilterUrlMapping("Traced128", "/traced128/api", REQUEST)
.addServlets(Servlets.servlet("HelloServlet", HelloServlet.class).addMapping("/*"));
}
代码示例来源:origin: wildfly/wildfly
ServletInfo defaultServlet = Servlets.servlet(DEFAULT_SERVLET_NAME, DefaultServlet.class);
handleServletMappings(is22OrOlder, seenMappings, servletMappings, defaultServlet);
代码示例来源:origin: org.springframework.boot/spring-boot
deployment.setDeploymentName("spring-boot");
if (isRegisterDefaultServlet()) {
deployment.addServlet(Servlets.servlet("default", DefaultServlet.class));
代码示例来源:origin: resteasy/Resteasy
String prefix = null;
if (!mapping.equals("/*")) prefix = mapping.substring(0, mapping.length() - 2);
ServletInfo resteasyServlet = servlet("ResteasyServlet", HttpServlet30Dispatcher.class)
.setAsyncSupported(true)
.setLoadOnStartup(1)
代码示例来源:origin: io.undertow/undertow-servlet
/**
* Creates a new servlet description with the given class. The servlet name is inferred from the simple name of the class.
*
* @param servletClass The servlet class
* @return A new servlet description
*/
public static ServletInfo servlet(final Class<? extends Servlet> servletClass) {
return servlet(servletClass.getSimpleName(), servletClass);
}
代码示例来源:origin: com.github.skjolber.mockito-rest-spring/undertow
private static ServletInfo createDispatcherServlet(WebApplicationContext context) {
InstanceFactory<DispatcherServlet> factory = new ImmediateInstanceFactory<>(new DispatcherServlet(context));
return Servlets.servlet("DispatcherServlet", DispatcherServlet.class, factory)
.addMapping(SPRING_DISPATCHER_MAPPING_URL)
.setLoadOnStartup(1);
}
}
代码示例来源:origin: org.commonjava.indy/indy-subsys-jaxrs
@Override
public DeploymentInfo getDeploymentInfo( String contextRoot, Application application )
{
if ( !config.isMetricsEnabled() )
{
return null;
}
final ServletInfo servlet =
Servlets.servlet( "healthcheck", HealthCheckServlet.class ).addMapping( "/healthcheck" );
final DeploymentInfo di = new DeploymentInfo().addListener(
Servlets.listener( IndyHealthCheckServletContextListener.class ) )
.setContextPath( contextRoot )
.addServlet( servlet )
.setDeploymentName( "HealthCheck Deployment" )
.setClassLoader( ClassLoader.getSystemClassLoader() );
logger.info( "Returning deployment info for health check" );
return di;
}
}
代码示例来源:origin: arun-gupta/wildfly-samples
public SimpleServletServer() {
DeploymentInfo deploymentInfo = deployment()
.setClassLoader(SimpleServletServer.class.getClassLoader())
.setContextPath("/helloworld")
.setDeploymentName("helloworld.war")
.addServlets(
Servlets.servlet("MyServlet", MyServlet.class)
.addInitParam("message", "Hello World")
.addMapping("/MyServlet"),
Servlets.servlet("MyAnotherServlet", MyAnotherServlet.class)
.addMapping("/MyAnotherServlet")
);
DeploymentManager manager = defaultContainer().addDeployment(deploymentInfo);
manager.deploy ();
try {
server = Undertow.builder()
.addListener(8080, "localhost")
.setHandler(manager.start())
.build();
} catch (ServletException ex) {
Logger.getLogger(SimpleServletServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
代码示例来源:origin: vdevigere/undertow-cdi-jaxrs
public static void main(String[] args) throws ServletException {
MyServer myServer = new MyServer(8080, "0.0.0.0");
DeploymentInfo di = myServer.deployApplication("/rest", MyApplication.class)
.setClassLoader(MyServer.class.getClassLoader())
.setContextPath("/myApp")
.setDeploymentName("My Application")
.addServlets(Servlets.servlet("helloServlet", org.viddu.poc.HelloServlet.class).addMapping("/hello"))
.addListeners(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class));
myServer.deploy(di);
}
}
代码示例来源:origin: org.commonjava.indy/indy-dot-maven-jaxrs
@Override
public DeploymentInfo getDeploymentInfo( String contextRoot, Application application )
{
final ServletInfo servletInfo = Servlets.servlet( "DotMaven", DotMavenServlet.class )
.setAsyncSupported( true )
.setLoadOnStartup( 3 )
.addMapping( "/mavdav*" )
.addMapping( "/mavdav/*" );
servletInfo.setInstanceFactory( new ImmediateInstanceFactory<Servlet>( servlet ) );
return new DeploymentInfo().addServlet( servletInfo );
}
}
代码示例来源:origin: org.commonjava.aprox/aprox-dot-maven-jaxrs
@Override
public DeploymentInfo getDeploymentInfo()
{
final ServletInfo servletInfo = Servlets.servlet( "DotMaven", DotMavenServlet.class )
.setAsyncSupported( true )
.setLoadOnStartup( 3 )
.addMapping( "/mavdav*" )
.addMapping( "/mavdav/*" );
servletInfo.setInstanceFactory( new ImmediateInstanceFactory<Servlet>( servlet ) );
return new DeploymentInfo().addServlet( servletInfo );
}
}
代码示例来源:origin: io.silverware/http-server-microservice-provider
@Override
@SuppressWarnings("unchecked")
public void deployServlet(final String contextPath, final String deploymentName,
final List<ServletDescriptor> servletDescriptors) throws SilverWareException {
final DeploymentInfo servletBuilder = Servlets
.deployment()
.setClassLoader(this.getClass().getClassLoader())
.setContextPath(contextPath)
.setDeploymentName(deploymentName);
if (servletDescriptors != null) {
servletDescriptors.forEach(servletDescriptor -> {
final ServletInfo servletInfo = Servlets
.servlet(servletDescriptor.getName(), (Class<Servlet>) servletDescriptor.getServletClass());
servletInfo.addMapping(servletDescriptor.getMapping());
servletDescriptor
.getProperties()
.forEach((key, value) -> servletInfo.addInitParam((String) key, (String) value));
servletBuilder.addServlet(servletInfo);
});
}
this.server.deploy(servletBuilder);
}
代码示例来源:origin: allegro/hermes
private PathHandler createPathHandler() {
try {
Servlet tokenServlet = new OAuthAccessTokenServlet(storage);
Servlet resourceServlet = new OAuthResourceServlet(storage);
DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(OAuthTestServer.class.getClassLoader())
.setContextPath("/")
.setDeploymentName("OAuthTestServer")
.addServlets(
Servlets.servlet("AuthTokenServlet", OAuthAccessTokenServlet.class,
new ImmediateInstanceFactory<>(tokenServlet))
.addMapping(OAUTH2_TOKEN_ENDPOINT),
Servlets.servlet("ResourceServlet", OAuthResourceServlet.class,
new ImmediateInstanceFactory<>(resourceServlet))
.addMapping(OAUTH2_RESOURCE_ENDPOINT)
);
DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(deploymentInfo);
deploymentManager.deploy();
HttpHandler servletHandler = deploymentManager.start();
return Handlers.path().addPrefixPath("/", servletHandler);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: io.squark.yggdrasil.yggdrasil-framework-provider/yggdrasil-servlet-provider
private ServletInfo convertServletInfo(YggdrasilServletInfo servlet) {
ServletInfo result =
Servlets.servlet(servlet.getName(), servlet.getClazz()).setLoadOnStartup(servlet.getLoadOnStartup())
.setAsyncSupported(servlet.getAsyncSupported()).setRequireWelcomeFileMapping(servlet.getRequireWelcomeFileMapping());
for (String mapping : servlet.getMappings()) {
result.addMapping(mapping);
}
return result;
}
代码示例来源:origin: ws.ament.hammock/web-undertow
@Override
public ServletInfo apply(ServletDescriptor servletDescriptor) {
ServletInfo servletInfo = Servlets.servlet(servletDescriptor.name(), servletDescriptor.servletClass())
.setAsyncSupported(servletDescriptor.asyncSupported())
.setLoadOnStartup(servletDescriptor.loadOnStartup())
.addMappings(servletDescriptor.urlPatterns());
if(servletDescriptor.initParams() != null) {
for(WebInitParam param : servletDescriptor.initParams()) {
servletInfo.addInitParam(param.name(), param.value());
}
}
return servletInfo;
}
}
代码示例来源:origin: hammock-project/hammock
@Override
public ServletInfo apply(ServletDescriptor servletDescriptor) {
ServletInfo servletInfo = Servlets.servlet(servletDescriptor.name(), servletDescriptor.servletClass())
.setAsyncSupported(servletDescriptor.asyncSupported())
.setLoadOnStartup(servletDescriptor.loadOnStartup())
.addMappings(servletDescriptor.urlPatterns());
if(servletDescriptor.initParams() != null) {
for(WebInitParam param : servletDescriptor.initParams()) {
servletInfo.addInitParam(param.name(), param.value());
}
}
return servletInfo;
}
}
代码示例来源:origin: fstab/http2-examples
public static void main(final String[] args) throws Exception {
assertJavaVersion8();
DeploymentInfo servletBuilder = deployment()
.setClassLoader(HelloWorldServlet.class.getClassLoader())
.setContextPath(MYAPP)
.setDeploymentName("hello-world.war")
.addServlets(
servlet("HelloWorldServlet", HelloWorldServlet.class)
.addInitParam("message", "Hello World")
.addMapping("/api/hello-world"));
DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
manager.deploy();
HttpHandler servletHandler = manager.start();
PathHandler path = Handlers.path(Handlers.redirect(MYAPP))
.addPrefixPath(MYAPP, servletHandler);
String bindAddress = System.getProperty("bind.address", "localhost");
SSLContext sslContext = createSSLContext(loadKeyStore("server.keystore"), loadKeyStore("server.truststore"));
Undertow server = Undertow.builder()
.setServerOption(UndertowOptions.ENABLE_HTTP2, true)
.addHttpsListener(8443, bindAddress, sslContext)
.setHandler(path)
.build();
server.start();
}
内容来源于网络,如有侵权,请联系作者删除!