本文整理汇总了Java中io.undertow.servlet.Servlets类的典型用法代码示例。如果您正苦于以下问题:Java Servlets类的具体用法?Java Servlets怎么用?Java Servlets使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Servlets类属于io.undertow.servlet包,在下文中一共展示了Servlets类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.undertow.servlet.Servlets; //导入依赖的package包/类
public static void start(String[] args) throws ServletException {
Map<String, String> commands = Arrays.stream(args)
.map(cmd -> cmd.split(REGEX_EQ))
.collect(toMap(cmdArray -> cmdArray[IDX_ZERO], cmdArray -> cmdArray[IDX_ONE]));
Config undertowConf = Configs.DEFAULT.undertow();
Config httpConf = undertowConf.getConfig(KEY_HTTP);
Logger logger = LoggerFactory.getLogger(Server.class);
logger.debug("Commands to AdeptJ Runtime: {}", commands);
int httpPort = handlePortAvailability(httpConf, logger);
logger.info("Starting AdeptJ Runtime @port: [{}]", httpPort);
printBanner(logger);
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo(undertowConf));
manager.deploy();
Builder builder = Undertow.builder();
optimizeWorkerOptions(builder, undertowConf, logger);
ServerOptions.build(builder, undertowConf);
builder.addHttpListener(httpPort, httpConf.getString(KEY_HOST));
enableHttp2(undertowConf, builder, logger);
enableAJP(undertowConf, builder, logger);
GracefulShutdownHandler rootHandler = rootHandler(headersHandler(manager.start(), undertowConf), undertowConf);
Undertow server = builder.setHandler(rootHandler).build();
server.start();
Runtime.getRuntime().addShutdownHook(new ShutdownHook(server, manager, rootHandler));
launchBrowser(commands, httpPort, logger);
if (!Environment.isServerConfFileExists()) {
createServerConfFile(logger);
}
}
示例2: deploymentInfo
import io.undertow.servlet.Servlets; //导入依赖的package包/类
private static DeploymentInfo deploymentInfo(Config cfg) {
return Servlets.deployment()
.setDeploymentName(DEPLOYMENT_NAME)
.setContextPath(CONTEXT_PATH)
.setClassLoader(Server.class.getClassLoader())
.setIgnoreFlush(cfg.getBoolean(KEY_IGNORE_FLUSH))
.setDefaultEncoding(cfg.getString(KEY_DEFAULT_ENCODING))
.setDefaultSessionTimeout(sessionTimeout(cfg))
.setChangeSessionIdOnLogin(cfg.getBoolean(KEY_CHANGE_SESSIONID_ON_LOGIN))
.setInvalidateSessionOnLogout(cfg.getBoolean(KEY_INVALIDATE_SESSION_ON_LOGOUT))
.setIdentityManager(new SimpleIdentityManager(cfg))
.setUseCachedAuthenticationMechanism(cfg.getBoolean(KEY_USE_CACHED_AUTH_MECHANISM))
.setLoginConfig(Servlets.loginConfig(FORM_AUTH, REALM, TOOLS_LOGIN_URI, TOOLS_LOGIN_URI))
.addServletContainerInitalizer(sciInfo())
.addSecurityConstraint(securityConstraint(cfg))
.addServlets(servlets())
.addErrorPages(errorPages(cfg))
.setDefaultMultipartConfig(defaultMultipartConfig(cfg))
.addInitialHandlerChainWrapper(new ServletInitialHandlerWrapper())
.addServletContextAttribute(ATTRIBUTE_NAME, webSocketDeploymentInfo(cfg))
.setServletSessionConfig(sessionConfig(cfg));
}
示例3: initServlet
import io.undertow.servlet.Servlets; //导入依赖的package包/类
private static void initServlet() throws ServletException, NoSuchMethodException {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
DeploymentInfo deploymentInfo = new DeploymentInfo()
.addListener(Servlets.listener(WeldInitialListener.class))
.addListener(Servlets.listener(WeldTerminalListener.class))
.setContextPath("/")
.setDeploymentName("standalone-javax-mvc-app")
.addServlet(
createServletInfo("/resources/*", "JAX-RS Resources", org.glassfish.jersey.servlet.ServletContainer.class)
)
.setResourceManager(new ClassPathResourceManager(classLoader, "META-INF/webapp"))
.setClassIntrospecter(CdiClassIntrospecter.INSTANCE)
.setAllowNonStandardWrappers(true)
.setClassLoader(classLoader);
ServletContainer servletContainer = Servlets.defaultContainer();
DeploymentManager deploymentManager = servletContainer.addDeployment(deploymentInfo);
deploymentManager.deploy();
Undertow server = Undertow.builder()
.addHttpListener(8080, "0.0.0.0")
.setHandler(deploymentManager.start())
.build();
server.start();
}
示例4: createHtmlManager
import io.undertow.servlet.Servlets; //导入依赖的package包/类
private static HttpHandler createHtmlManager() throws ServletException {
final DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(HttpServerUtil.class.getClassLoader())
.setContextPath(SERVLET_CONTEXT_PATH)
.setDeploymentName("uaiMockServer.war")
.addServlets(
servlet("UaiIndexServlet", UaiIndexServlet.class).addMapping("/index"),
servlet("UaiPageServlet", UaiPageServlet.class).addMapping("/page"),
servlet("JavascriptServlet", UaiJavascriptServlet.class).addMapping("/javascript"),
servlet("CssServlet", UaiCssServlet.class).addMapping("/css"),
servlet("CssMapServlet", UaiCssMapServlet.class).addMapping("/bootstrap.css.map"),
servlet("AngularMapServlet", UAiAngularMapServlet.class).addMapping("/angular.js.map"),
servlet("UaiRouteServlet", UaiRouteServlet.class).addMapping("/uaiRoute"),
servlet("UaiRouteCloneServlet", UaiRouteCloneServlet.class).addMapping("/uaiRoute/clone"),
servlet("UaiRootConfigurationsServlet", UaiRootConfigurationsServlet.class).addMapping("/rootConfigurations")
);
final DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo);
manager.deploy();
return manager.start();
}
示例5: undertowDeployment
import io.undertow.servlet.Servlets; //导入依赖的package包/类
static DeploymentInfo undertowDeployment(ResteasyDeployment deployment, String mapping) {
if (mapping == null) {
mapping = "/";
}
if (!mapping.startsWith("/")) {
mapping = '/' + mapping;
}
if (!mapping.endsWith("/")) {
mapping = mapping + '/';
}
mapping = mapping + '*';
String prefix = null;
if (!mapping.equals("/*")) {
prefix = mapping.substring(0, mapping.length() - 2);
}
ServletInfo resteasyServlet = Servlets.servlet("ResteasyServlet", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping(mapping);
if (prefix != null) {
resteasyServlet.addInitParam("resteasy.servlet.mapping.prefix", prefix);
}
return (new DeploymentInfo()).addServletContextAttribute(ResteasyDeployment.class.getName(), deployment).addServlet(resteasyServlet);
}
示例6: deployLogs
import io.undertow.servlet.Servlets; //导入依赖的package包/类
protected void deployLogs(BootContext context, ServletContainer servletContainer) {
String adminLogs = context.properties().getProperty("vas.admin.logs", "false");
if(Boolean.valueOf(adminLogs)) {
DeploymentInfo deploymentInfo = Servlets
.deployment()
.setContextPath("/")
.setDeploymentName("logback.war")
.setClassLoader(getClass().getClassLoader())
.addServlet(
Servlets.servlet("logback", ViewStatusMessagesServlet.class).setEnabled(true).setAsyncSupported(true)
.setLoadOnStartup(1).addMappings("/"));
DeploymentManager deploymentManager = servletContainer.addDeployment(deploymentInfo);
deploymentManager.deploy();
try {
context.pathHandler().addPrefixPath("/admin/logs", deploymentManager.start());
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
}
示例7: init
import io.undertow.servlet.Servlets; //导入依赖的package包/类
private void init(PathHandler pathHandler) throws ServletException {
// Deployment info
ServletContainer servletContainer = Servlets.defaultContainer();
DeploymentInfo deploymentInfo = VasHelper.deploymentInfo();
// Boot context & post processors
context = new BootContextImpl(properties, pathHandler, deploymentInfo, services);
VasHelper.lookupHandlerPostProcessors(context);
// Deployment
DeploymentManager deploymentManager = servletContainer.addDeployment(deploymentInfo);
deploymentManager.deploy();
pathHandler.addPrefixPath(Const.CONTEXT_NAME, deploymentManager.start());
boot();
}
示例8: setUpClass
import io.undertow.servlet.Servlets; //导入依赖的package包/类
/**
* Sets up the test environment, generates data to upload, starts an
* Undertow instance which will receive the client requests.
* @throws Exception If an error occurred with the servlets
*/
@BeforeClass
public static void setUpClass() throws Exception {
DeploymentInfo servletBuilder = Servlets.deployment()
.setClassLoader(UndertowIntegrationTest.class.getClassLoader())
.setContextPath("/")
.setDeploymentName("ROOT.war")
.addServlets(
Servlets.servlet("AsyncUploadServlet", AsyncUploadServlet.class)
.addMapping("/async")
.setAsyncSupported(true),
Servlets.servlet("BlockingUploadServlet", BlockingUploadServlet.class)
.addMapping("/blocking")
.setAsyncSupported(false)
);
DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
manager.deploy();
PathHandler path = Handlers.path(Handlers.redirect("/")).addPrefixPath("/", manager.start());
server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(path)
.build();
server.start();
}
示例9: main
import io.undertow.servlet.Servlets; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ServletException {
final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader());
final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap());
final WebSocketDeploymentInfo webSockets = new WebSocketDeploymentInfo()
.addEndpoint(ClassProvider.class)
.setWorker(xnioWorker);
final DeploymentManager deploymentManager = Servlets.defaultContainer()
.addDeployment(Servlets.deployment()
.setClassLoader(ClassProviderStarter.class.getClassLoader())
.setContextPath("/")
.setDeploymentName("class-provider")
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSockets));
deploymentManager.deploy();
//noinspection deprecation
Undertow.builder()
.addListener(5000, "localhost")
.setHandler(deploymentManager.start())
.build()
.start();
}
示例10: deployApplications
import io.undertow.servlet.Servlets; //导入依赖的package包/类
/**
* Setup the deployment managers for a given set of applications
*
* @param apps
* @return list of deployment managers
*/
public List<DeploymentManager> deployApplications(List<Application> apps) {
List<DeploymentManager> deployManagers = new ArrayList<DeploymentManager>();
for (Application app : apps) {
DeploymentInfo deployInfo = app.getDeploymentInfo();
// Add default listeners
ListenerInfo cdiListener = Servlets.listener(CdiServletRequestListener.class);
deployInfo.addListener(cdiListener);
DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(deployInfo);
try {
deploymentManager.deploy();
deployManagers.add(deploymentManager);
} catch (Exception e) {
logger.log(Level.SEVERE, "stokesdrift:server:start[status=app_deploy_fail,app_type=" + app.getClass().getSimpleName() + "]", e);
}
}
return deployManagers;
}
示例11: getDeploymentInfo
import io.undertow.servlet.Servlets; //导入依赖的package包/类
@Override
public DeploymentInfo getDeploymentInfo() {
FilterInfo filter = Servlets.filter(RACK_FILTER, RackFilter.class);
// TODO extend listener and setup the jruby env based on reloaded gems
// and jars
// Override appfactory?
ListenerInfo listenerInfo = Servlets.listener(ServletContextListener.class);
DeploymentInfo di = new DeploymentInfo().addListener(listenerInfo).setContextPath(config.getRootUrlPath()).addFilter(filter)
.addFilterUrlMapping(RACK_FILTER, "/*", DispatcherType.REQUEST).setDeploymentName(config.getName())
.setClassLoader(ClassLoader.getSystemClassLoader());
setupInitParams(di);
return di;
}
示例12: testUndertowLoading
import io.undertow.servlet.Servlets; //导入依赖的package包/类
@Test
public void testUndertowLoading() throws Exception {
int port = 8888;
FilterInfo filter = Servlets.filter("RackFilter", RackFilter.class);
ListenerInfo listenerInfo = Servlets.listener(RackServletContextListener.class);
DeploymentInfo di = new DeploymentInfo()
.addListener(listenerInfo)
.setContextPath("/")
// .addInitParameter(name, value)
.addFilter(filter)
.addFilterUrlMapping("RackFilter", "/*", DispatcherType.ASYNC)
// .addServlet(servletInfo)
.setDeploymentName("RackServlet")
.setClassLoader(ClassLoader.getSystemClassLoader());
DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(di);
deploymentManager.deploy();
Undertow server = Undertow.builder()
.addHttpListener(port, "localhost")
.setHandler(deploymentManager.start())
.build();
Assert.assertNotNull(server);
// server.start();
}
示例13: SimpleServletServer
import io.undertow.servlet.Servlets; //导入依赖的package包/类
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);
}
}
示例14: main
import io.undertow.servlet.Servlets; //导入依赖的package包/类
public static void main(final String... args) throws Exception {
final DeploymentManager deployment = Servlets.defaultContainer()
.addDeployment(
Servlets.deployment()
.setClassLoader(UndertowContainer.class.getClassLoader())
.setContextPath("/")
.setDeploymentName(UndertowContainer.class.getName())
.addServletContextAttribute(
WebSocketDeploymentInfo.ATTRIBUTE_NAME,
new WebSocketDeploymentInfo()
.addEndpoint(ApplicationConfig.ENDPOINT_CONFIG)
.setWorker(Xnio.getInstance().createWorker(OptionMap.builder().getMap()))
.setBuffers(new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)))
)
);
deployment.deploy();
final HttpHandler servletHandler = deployment.start();
Undertow.builder()
.addHttpListener(Client.PORT, Client.HOST)
.setHandler(servletHandler)
.build()
.start();
}
示例15: main
import io.undertow.servlet.Servlets; //导入依赖的package包/类
public static void main(String[]args){
//Get Port
String host="0.0.0.0";
int port = Integer.parseInt(System.getProperty("port"));
//Create the JAXRS Server
UndertowJaxrsServer server = new UndertowJaxrsServer();
Undertow.Builder serverBuilder = Undertow.builder().addHttpListener(port, host);
server.start(serverBuilder);
//Create the deployment
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(MoneyTransfertApp.class.getName());
deployment.setInjectorFactoryClass(org.jboss.resteasy.cdi.CdiInjectorFactory.class.getName());
//Configure the deployment info
DeploymentInfo di = server.undertowDeployment(deployment, "/api");
di.setClassLoader(MoneyTransferServer.class.getClassLoader())
.setContextPath("/beosbank-undertow-service")
.setDeploymentName("BeosBank Services");
//Add CDI listener
di.addListeners(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class));
//Deploy the API
server.deploy(di);
System.out.println("Undertow MoneyTransfert started on "+host+":"+port);
}