本文整理匯總了Java中io.undertow.server.handlers.PathHandler類的典型用法代碼示例。如果您正苦於以下問題:Java PathHandler類的具體用法?Java PathHandler怎麽用?Java PathHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PathHandler類屬於io.undertow.server.handlers包,在下文中一共展示了PathHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
public static void main(String[] args) {
PathHandler path = new PathHandler()
.addPrefixPath("/", resource(new ClassPathResourceManager(Dashboard.class.getClassLoader(),
Dashboard.class.getPackage())).addWelcomeFiles("chart.html"))
.addExactPath("/api", new Dashboard());
Undertow server = Undertow.builder()
.addHttpListener(6001, "127.0.0.1")
.setHandler(path)
.build();
server.start();
try {
Thread.sleep(1000000000);
} catch (InterruptedException e) {
e.printStackTrace();
}
server.stop();
}
示例2: startHttpServer
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
public static Undertow startHttpServer() {
final Undertow httpServer;
try {
final PathHandler path = PathHandlerFactory.create();
httpServer = Undertow.builder()
.addHttpListener(UaiMockServerContext.getInstance().uaiMockServerConfig.getPort(), UaiMockServerContext.getInstance().uaiMockServerConfig.getHost())
.setHandler(path)
.build();
httpServer.start();
} catch (final Exception ex) {
throw new IllegalStateException("Could not start the uaiMockServer.", ex);
}
return httpServer;
}
示例3: startImpl
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
protected void startImpl() {
try {
fathomDeploymentManager = createFathomDeploymentManager();
HttpHandler fathomHandler = fathomDeploymentManager.start();
String contextPath = settings.getContextPath();
// create a handler than redirects non-context requests to the context
PathHandler contextHandler = Handlers.path(Handlers.redirect(contextPath));
// add the handler with the context prefix
contextHandler.addPrefixPath(contextPath, fathomHandler);
GracefulShutdownHandler rootHandler = new GracefulShutdownHandler(contextHandler);
server = createServer(rootHandler);
String version = server.getClass().getPackage().getImplementationVersion();
log.info("Starting Undertow {}", version);
server.start();
} catch (Exception e) {
throw new FathomException(e);
}
}
示例4: init
import io.undertow.server.handlers.PathHandler; //導入依賴的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();
}
示例5: publish
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
private static void publish(final Catalog catalog,final String basePath, final String serializationCachePath, final int port, final String host, final DocumentationStrategy strategy) throws IOException {
LOGGER.debug("* Publishing vocabularies under {}",basePath);
final PathHandler pathHandler=path();
// Module serializations
final SerializationManager manager=publishSerializations(catalog,pathHandler,serializationCachePath);
// Catalog documentation
final DocumentationDeploymentFactory factory = publishDocumentation(catalog,pathHandler,strategy);
// Canonical namespaces
publishCanonicalNamespace(catalog, basePath, pathHandler, manager, factory);
final Undertow server =
Undertow.
builder().
addHttpListener(port,host).
setHandler(new CanonicalPathHandler(pathHandler)).
build();
server.start();
awaitTerminationRequest();
server.stop();
}
示例6: publishCanonicalNamespace
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
private static void publishCanonicalNamespace(final Catalog catalog, final String basePath, final PathHandler pathHandler, final SerializationManager manager, final DocumentationDeploymentFactory factory) {
final ContentNegotiationHandler contentNegotiation = contentNegotiation().
negotiate(
negotiableModuleContent(),
new ModuleRepresentionGenerator(manager));
if(factory!=null) {
contentNegotiation.
negotiate(
NegotiableContent.newInstance().support(HTML),
new ModuleDocumentationRedirector(factory));
}
pathHandler.
addPrefixPath(
basePath,
moduleReverseProxy(
catalog,
methodController(
contentNegotiation).
allow(Methods.GET)
)
);
}
示例7: setUpClass
import io.undertow.server.handlers.PathHandler; //導入依賴的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();
}
示例8: createRoutes
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
/**
* Create routes for WebSockets ServerSentEvent and Resource files
*/
private static void createRoutes() {
if (!error) {
pathHandler = new PathHandler(getRoutingHandler());
for (final Route route : Router.getRoutes()) {
if (RouteType.WEBSOCKET == route.getRouteType()) {
pathHandler.addExactPath(route.getUrl(),
Handlers.websocket(injector.getInstance(WebSocketHandler.class)
.withControllerClass(route.getControllerClass())
.withAuthentication(route.isAuthenticationRequired())));
} else if (RouteType.SERVER_SENT_EVENT == route.getRouteType()) {
pathHandler.addExactPath(route.getUrl(),
Handlers.serverSentEvents(injector.getInstance(ServerSentEventHandler.class)
.withAuthentication(route.isAuthenticationRequired())));
} else if (RouteType.RESOURCE_PATH == route.getRouteType()) {
pathHandler.addPrefixPath(route.getUrl(),
new ResourceHandler(new ClassPathResourceManager(Thread.currentThread().getContextClassLoader(), Default.FILES_FOLDER.toString() + route.getUrl())));
}
}
}
}
示例9: start
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
public void start() throws ServletException, IOException {
DeploymentInfo servletInfo = LuceeServletBuilder.build( libDirs, webroot, webXmlPath, webInfPath );
deploymentManager = defaultContainer().addDeployment( servletInfo );
deploymentManager.deploy();
HttpHandler httpHandler = deploymentManager.start();
PathHandler pathHandler = Handlers.path( Handlers.redirect( "/" ) ).addPrefixPath( "/", httpHandler );
Builder builder = Undertow.builder();
builder.addHttpListener( port, host );
builder.setHandler( pathHandler );
undertowServer = builder.build();
undertowServer.start();
}
示例10: mountServerEndpoints
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
protected PathHandler mountServerEndpoints(final PathHandler pathHandler , List<Class<?>> serverEndpoints) throws ServletException{
if(!serverEndpoints.isEmpty()){
DeploymentInfo builder = new DeploymentInfo()
.setClassLoader(this.getClass().getClassLoader())
.setContextPath("/");
WebSocketDeploymentInfo wsDeployInfo = new WebSocketDeploymentInfo();
wsDeployInfo.setBuffers(new ByteBufferSlicePool(100, 1000));
for(Class<?> serverEndpoint : serverEndpoints ){
wsDeployInfo.addEndpoint( serverEndpoint );
}
builder.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, wsDeployInfo );
builder.setDeploymentName("websocketDeploy.war");
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
pathHandler.addPrefixPath("/", manager.start() );
}
return pathHandler;
}
示例11: mountMethods
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
protected PathHandler mountMethods(PathHandler pathHandler, final Class<?> handlerClass) {
Controller controllerAnnotation = handlerClass.getAnnotation(Controller.class);
Method[] methods = handlerClass.getMethods();
final List<Method> beforeTranslationMethods = identifyBeforeTranslationMethod(methods);
for (final Method method : methods) {
Page methodPagePath = method.getAnnotation(Page.class);
if (methodPagePath != null) {
HttpHandler h = new HandlerCreator()
.forPageClass(handlerClass)
.withPathMethod(method)
.withExecuteBeforeMethods(beforeTranslationMethods)
.mount();
String pageRoot = controllerAnnotation.path();
for (String methodRoot : methodPagePath.value()) {
pathHandler.addExactPath(pageRoot + "/" + methodRoot, h);
}
}
}
return pathHandler;
}
示例12: HttpProtocolReceiver
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
public HttpProtocolReceiver(final UPID localAddress,
final Class<?> messageBaseClass,
final ManagedEventBus eventBus)
{
this.localAddress = localAddress;
this.messageBaseClass = messageBaseClass;
this.eventBus = eventBus;
final PathHandler pathHandler = new PathHandler();
pathHandler.addPrefixPath(localAddress.getId(), new CanonicalPathHandler(new BlockingHandler(this)));
this.shutdownHandler = new GracefulShutdownHandler(pathHandler);
this.httpServer = Undertow.builder()
.setIoThreads(2)
.setWorkerThreads(16)
.addHttpListener(localAddress.getPort(), localAddress.getHost())
.setHandler(shutdownHandler)
.build();
}
示例13: buildGracefulShutdownHandler
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
/**
* buildGracefulShutdownHandler
*
* @param paths
* @return
*/
private static GracefulShutdownHandler buildGracefulShutdownHandler(PathHandler paths) {
return new GracefulShutdownHandler(
new RequestLimitingHandler(new RequestLimit(configuration.getRequestLimit()),
new AllowedMethodsHandler(
new BlockingHandler(
new GzipEncodingHandler(
new ErrorHandler(
new HttpContinueAcceptingHandler(paths)
), configuration.isForceGzipEncoding()
)
), // allowed methods
HttpString.tryFromString(RequestContext.METHOD.GET.name()),
HttpString.tryFromString(RequestContext.METHOD.POST.name()),
HttpString.tryFromString(RequestContext.METHOD.PUT.name()),
HttpString.tryFromString(RequestContext.METHOD.DELETE.name()),
HttpString.tryFromString(RequestContext.METHOD.PATCH.name()),
HttpString.tryFromString(RequestContext.METHOD.OPTIONS.name())
)
)
);
}
示例14: remove
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
public synchronized boolean remove(String path, List<String> vhosts) {
boolean result = false;
if (vhosts == null) {
result = null != activeHandlers.remove(path);
pathHandler.removePrefixPath(path);
} else {
for(String host: vhosts) {
if (null != activeHandlers.remove(host + path)) {
result = true;
PathHandler ph = (PathHandler) vhostHandler.getHosts().get(host);
ph.removePrefixPath(path);
}
}
}
purge();
return result;
}
示例15: start
import io.undertow.server.handlers.PathHandler; //導入依賴的package包/類
public void start() {
PathHandler pathHandler = Handlers.path();
for (String name : handlers.keySet()) {
pathHandler.addPrefixPath(name, handlers.get(name));
}
this.server = Undertow.builder().addHttpListener(port, "0.0.0.0", pathHandler).build();
server.start();
this.graph.storage().listen(this);//stop
}