本文整理了Java中io.undertow.servlet.Servlets.deployment()
方法的一些代码示例,展示了Servlets.deployment()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Servlets.deployment()
方法的具体详情如下:
包路径:io.undertow.servlet.Servlets
类名称:Servlets
方法名:deployment
[英]Creates a new servlet deployment info structure
[中]创建一个新的servlet部署信息结构
代码示例来源:origin: openzipkin/brave
protected int initServer() throws Exception {
DeploymentInfo servletBuilder = Servlets.deployment()
.setClassLoader(getClass().getClassLoader())
.setContextPath("/")
.setDeploymentName("test.war");
init(servletBuilder);
DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
manager.deploy();
server = Undertow.builder()
.addHttpListener(0, "127.0.0.1")
.setHandler(manager.start()).build();
server.start();
return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
}
代码示例来源:origin: spring-projects/spring-framework
DeploymentInfo servletBuilder = deployment()
.setClassLoader(UndertowTestServer.class.getClassLoader())
.setDeploymentName("undertow-websocket-test")
代码示例来源:origin: org.springframework.boot/spring-boot
private DeploymentManager createDeploymentManager(
ServletContextInitializer... initializers) {
DeploymentInfo deployment = Servlets.deployment();
registerServletContainerInitializerToDriveServletContextInitializers(deployment,
initializers);
代码示例来源:origin: pippo-java/pippo
protected DeploymentManager createPippoDeploymentManager() {
DeploymentInfo info = Servlets.deployment();
info.setDeploymentName("Pippo");
info.setClassLoader(this.getClass().getClassLoader());
info.setContextPath(getSettings().getContextPath());
info.setIgnoreFlush(true);
// inject application as context attribute
info.addServletContextAttribute(PIPPO_APPLICATION, getApplication());
// add pippo filter
addPippoFilter(info);
// add initializers
info.addListener(new ListenerInfo(PippoServletContextListener.class));
// add listeners
listeners.forEach(listener -> info.addListener(new ListenerInfo(listener)));
ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class);
defaultServlet.addMapping("/");
MultipartConfigElement multipartConfig = createMultipartConfigElement();
defaultServlet.setMultipartConfig(multipartConfig);
info.addServlets(defaultServlet);
DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info);
deploymentManager.deploy();
return deploymentManager;
}
代码示例来源:origin: com.fitbur.testify/server-undertow
@Override
public DeploymentInfo configuration(ServerDescriptor descriptor) {
try {
App app = descriptor.getApp();
Set<Class<?>> handles = descriptor.getHandlesType();
String name = descriptor.getTestClassName();
Class<? extends ServletContainerInitializer> servletType = descriptor.getServletContainerInitializer();
ServletContainerInitializer servlet = servletType.newInstance();
ImmediateInstanceFactory<ServletContainerInitializer> factory = new ImmediateInstanceFactory<>(servlet);
URI uri = URI.create("http://0.0.0.0:0/");
ServletContainerInitializerInfo initInfo
= new ServletContainerInitializerInfo(servletType, factory, handles);
DeploymentInfo deploymentInfo = Servlets.deployment()
.addServletContainerInitalizer(initInfo)
.setClassLoader(descriptor.getTestClass().getClassLoader())
.setHostName(uri.getHost())
.setContextPath(uri.getPath())
.setDeploymentName(name)
.addServlet(Servlets.servlet(name, DefaultServlet.class));
return deploymentInfo;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: com.fitbur.testify.server/server-undertow
@Override
public DeploymentInfo configuration(ServerDescriptor descriptor) {
try {
App app = descriptor.getApp();
Set<Class<?>> handles = descriptor.getHandlesType();
String name = descriptor.getTestClassName();
ServletContainerInitializer initializer = descriptor.getServletContainerInitializer();
ImmediateInstanceFactory<ServletContainerInitializer> factory = new ImmediateInstanceFactory<>(initializer);
URI uri = URI.create("http://0.0.0.0:0/");
ServletContainerInitializerInfo initInfo
= new ServletContainerInitializerInfo(initializer.getClass(),
factory, handles);
ServletInfo servletInfo = Servlets.servlet(name, DefaultServlet.class)
.setAsyncSupported(true);
DeploymentInfo deploymentInfo = Servlets.deployment()
.addServletContainerInitalizer(initInfo)
.setClassLoader(descriptor.getTestClass().getClassLoader())
.setHostName(uri.getHost())
.setContextPath(uri.getPath())
.setDeploymentName(name)
.addServlet(servletInfo);
return deploymentInfo;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: cassiomolin/jersey-jwt
DeploymentInfo servletBuilder = Servlets.deployment()
.setClassLoader(Application.class.getClassLoader())
.setContextPath("/")
代码示例来源:origin: com.github.skjolber.mockito-rest-spring/undertow
private Undertow configureUndertow(MockitoSpringWebApplicationContext context, URL url) throws ServletException {
// https://github.com/yarosla/spring-undertow/blob/master/src/main/java/ys/undertow/UndertowMain.java
DeploymentInfo servletBuilder = Servlets.deployment()
.setClassLoader(Undertow.class.getClassLoader())
.setContextPath(url.getPath())
.setDeploymentName("mock")
.addServlet(createDispatcherServlet(context))
.addListener(createContextLoaderListener(context));
DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
manager.deploy();
PathHandler path = Handlers.path(Handlers.redirect("/"))
.addPrefixPath(CONTEXT_PATH, manager.start());
return Undertow.builder()
.addHttpListener(url.getPort(), url.getHost())
.setHandler(path)
.build();
}
代码示例来源:origin: com.jwebmp/jwebmp-undertow
.addEndpoint(JWebMPSocket.class)
.setWorker(xnioWorker);
DeploymentInfo websocketDeployment = deployment()
.setContextPath("/jwebmpwssocket")
.addServletContextAttribute(ATTRIBUTE_NAME, JWebMPUndertowWebSocketConfiguration.webSocketDeploymentInfo)
代码示例来源: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: org.testifyproject.server/undertow
deploymentInfo = Servlets.deployment()
.addServletContainerInitalizer(initInfo)
.setClassLoader(classLoader)
代码示例来源: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: 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: org.seedstack.seed/seed-web-undertow
private DeploymentInfo configureDeploymentInfo() {
DeploymentInfo deploymentInfo = Servlets.deployment()
.setEagerFilterInit(true)
.setClassLoader(mostCompleteClassLoader)
.setDeploymentName(applicationConfig.getId())
.setDisplayName(applicationConfig.getName())
.setDefaultSessionTimeout(serverConfig.sessions().getTimeout())
.addServletContextAttribute(
WebSocketDeploymentInfo.ATTRIBUTE_NAME,
new WebSocketDeploymentInfo()
.setBuffers(new DefaultByteBufferPool(
undertowConfig.isDirectBuffers(),
undertowConfig.getBufferSize()))
.setWorker(xnioWorker)
)
.setContextPath(serverConfig.getContextPath());
for (Map.Entry<String, String> initParameter : initParameters.entrySet()) {
deploymentInfo.addInitParameter(initParameter.getKey(), initParameter.getValue());
}
for (ServletContainerInitializer servletContainerInitializer : loadServletContainerInitializers()) {
deploymentInfo.addServletContainerInitalizer(
createServletContainerInitializerInfo(servletContainerInitializer));
}
return deploymentInfo;
}
代码示例来源:origin: pl.allegro.tech.hermes/hermes-test-helper
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: 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();
}
代码示例来源:origin: gitblit/fathom
protected DeploymentManager createFathomDeploymentManager() throws ServletException {
DeploymentInfo info = Servlets.deployment();
info.setDeploymentName("Fathom");
info.setClassLoader(this.getClass().getClassLoader());
info.setContextPath(settings.getContextPath());
info.setIgnoreFlush(true);
info.setDefaultEncoding("UTF-8");
FilterInfo guiceFilter = new FilterInfo("GuiceFilter", GuiceFilter.class);
guiceFilter.setAsyncSupported(true);
info.addFilterUrlMapping("GuiceFilter", "/*", DispatcherType.REQUEST);
info.addFilters(guiceFilter);
ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class);
defaultServlet.setAsyncSupported(true);
defaultServlet.addMapping("/");
ServletContextListener fathomListener = new ServletContextListener(settings);
info.addListeners(new ListenerInfo(ServletContextListener.class, new ImmediateInstanceFactory<>(fathomListener)));
MultipartConfigElement multipartConfig = new MultipartConfigElement(settings.getUploadFilesLocation(), settings.getUploadFilesMaxSize(), -1L, 0);
defaultServlet.setMultipartConfig(multipartConfig);
info.addServlets(defaultServlet);
DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info);
deploymentManager.deploy();
return deploymentManager;
}
代码示例来源:origin: apache/cxf
protected void run() {
try {
final DeploymentInfo servletBuilder = deployment()
.setClassLoader(AbstractUndertowServer.class.getClassLoader())
.setContextPath(contextPath)
.setDeploymentName("sse-test")
.addServlets(
servlet("MessageServlet", CXFNonSpringJaxrsServlet.class)
.addInitParam("jaxrs.providers", JacksonJsonProvider.class.getName())
.addInitParam("jaxrs.serviceClasses", BookStore.class.getName())
.setAsyncSupported(true)
.setLoadOnStartup(1)
.addMapping("/rest/*")
);
final DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
manager.deploy();
PathHandler path = Handlers
.path(Handlers.redirect("/"))
.addPrefixPath("/", manager.start());
server = Undertow.builder()
.addHttpListener(port, "localhost")
.setHandler(path)
.build();
server.start();
} catch (final Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
代码示例来源:origin: yangfuhai/jboot
private DeploymentInfo buildDeploymentInfo(JbootServerClassloader classloader) {
DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(classloader)
.setResourceManager(new ClassPathResourceManager(classloader))
代码示例来源:origin: com.obsidiandynamics.socketx/socketx-undertow
manager = new UndertowEndpointManager(scanner, config.idleTimeoutMillis, config, listener);
final DeploymentInfo servletBuilder = Servlets.deployment()
.setClassLoader(UndertowServer.class.getClassLoader())
.setDeploymentName("servlet").setContextPath("");
内容来源于网络,如有侵权,请联系作者删除!