本文整理汇总了Java中io.undertow.server.HttpHandler类的典型用法代码示例。如果您正苦于以下问题:Java HttpHandler类的具体用法?Java HttpHandler怎么用?Java HttpHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpHandler类属于io.undertow.server包,在下文中一共展示了HttpHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBalancerHttpToHttps
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public static HttpHandler loadBalancerHttpToHttps(HttpHandler next) {
return (HttpServerExchange exchange) -> {
HttpUrl currentUrl = Exchange.urls().currentUrl(exchange);
String protocolForward = Exchange.headers().getHeader(exchange, "X-Forwarded-Proto").orElse(null);
if (null != protocolForward && protocolForward.equalsIgnoreCase("http")) {
log.debug("non https switching to https {}", currentUrl.host());
HttpUrl newUrl = currentUrl.newBuilder()
.scheme("https")
.port(443)
.build();
exchange.setStatusCode(301);
exchange.getResponseHeaders().put(Headers.LOCATION, newUrl.toString());
exchange.endExchange();
return;
}
next.handleRequest(exchange);
};
}
示例2: setUp
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@Before
public void setUp() {
if(server == null) {
logger.info("starting server");
HttpHandler handler = getPetStoreHandler();
ValidatorHandler validatorHandler = new ValidatorHandler();
validatorHandler.setNext(handler);
handler = validatorHandler;
BodyHandler bodyHandler = new BodyHandler();
bodyHandler.setNext(handler);
handler = bodyHandler;
OpenApiHandler openApiHandler = new OpenApiHandler();
openApiHandler.setNext(handler);
handler = openApiHandler;
server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(handler)
.build();
server.start();
}
}
示例3: handleRequest
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public void handleRequest(final HttpServerExchange exchange, final HttpHandler next) throws Exception {
long oldVal, newVal;
do {
oldVal = state;
final long current = oldVal & MASK_CURRENT;
final long max = (oldVal & MASK_MAX) >> 32L;
if (current >= max) {
exchange.dispatch(SameThreadExecutor.INSTANCE, new Runnable() {
@Override
public void run() {
if (!queue.offer(new SuspendedRequest(exchange, next))) {
Connectors.executeRootHandler(failureHandler, exchange);
}
}
});
return;
}
newVal = oldVal + 1;
} while (!stateUpdater.compareAndSet(this, oldVal, newVal));
exchange.addExchangeCompleteListener(COMPLETION_LISTENER);
next.handleRequest(exchange);
}
示例4: setUp
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@BeforeClass
public static void setUp() {
if(server == null) {
logger.info("starting server");
HttpHandler handler = getTestHandler();
JwtVerifyHandler jwtVerifyHandler = new JwtVerifyHandler();
jwtVerifyHandler.setNext(handler);
SwaggerHandler swaggerHandler = new SwaggerHandler();
swaggerHandler.setNext(jwtVerifyHandler);
server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(swaggerHandler)
.build();
server.start();
}
}
示例5: redirector
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public static HttpHandler redirector(HttpHandler next) {
return (HttpServerExchange exchange) -> {
HttpUrl currentUrl = Exchange.urls().currentUrl(exchange);
String protocolForward = Exchange.headers().getHeader(exchange, "X-Forwarded-Proto").orElse(null);
String host = currentUrl.host();
boolean redirect = false;
Builder newUrlBuilder = currentUrl.newBuilder();
if (host.equals("stubbornjava.com")) {
host = "www." + host;
newUrlBuilder.host(host);
redirect = true;
logger.debug("Host {} does not start with www redirecting to {}", currentUrl.host(), host);
}
if (null != protocolForward && protocolForward.equalsIgnoreCase("http")) {
logger.debug("non https switching to https", currentUrl.host(), host);
newUrlBuilder.scheme("https")
.port(443);
redirect = true;
}
if (redirect) {
HttpUrl newUrl = newUrlBuilder.build();
exchange.setStatusCode(301);
exchange.getResponseHeaders().put(Headers.LOCATION, newUrl.toString());
exchange.endExchange();
return;
}
next.handleRequest(exchange);
};
}
示例6: ServletInitialHandler
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public ServletInitialHandler(final ServletPathMatches paths, final HttpHandler next, final CompositeThreadSetupAction setupAction, final ServletContextImpl servletContext) {
this.next = next;
this.setupAction = setupAction;
this.servletContext = servletContext;
this.paths = paths;
this.listeners = servletContext.getDeployment().getApplicationListeners();
if(System.getSecurityManager() != null) {
//handle request can use doPrivilidged
//we need to make sure this is not abused
AccessController.checkPermission(PERMISSION);
}
ExceptionHandler handler = servletContext.getDeployment().getDeploymentInfo().getExceptionHandler();
if(handler != null) {
this.exceptionHandler = handler;
} else {
this.exceptionHandler = LoggingExceptionHandler.DEFAULT;
}
}
示例7: setUp
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@BeforeClass
public static void setUp() {
if(server == null) {
logger.info("starting server");
HttpHandler handler = getTestHandler();
JwtVerifyHandler jwtVerifyHandler = new JwtVerifyHandler();
jwtVerifyHandler.setNext(handler);
OpenApiHandler openApiHandler = new OpenApiHandler();
openApiHandler.setNext(jwtVerifyHandler);
server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(openApiHandler)
.build();
server.start();
}
}
示例8: wrapWithMiddleware
import io.undertow.server.HttpHandler; //导入依赖的package包/类
private static HttpHandler wrapWithMiddleware(HttpHandler handler) {
/*
* Undertow has I/O threads for handling inbound connections and non blocking IO.
* If you are doing any blocking you should use the BlockingHandler. This
* will push work into a separate Executor with customized thread pool
* which is made for blocking work. I am blocking immediately here because I am lazy.
* Don't block if you don't need to. Remember you can configure only certain routes block.
* When looking at logs you can tell if you are blocking or not by the thread name.
* I/O non blocking thread - [XNIO-1 I/O-{threadnum}] - You should NOT be blocking here.
* Blocking task threads - [XNIO-1 task-{threadnum}] This pool is made for blocking.
*/
return MiddlewareBuilder.begin(BlockingHandler::new)
.next(CustomHandlers::gzip)
.next(CustomHandlers::accessLog)
.next(CustomHandlers::statusCodeMetrics)
.next(MiddlewareServer::exceptionHandler)
.complete(handler);
}
示例9: setUp
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@BeforeClass
public static void setUp() {
if(server == null) {
logger.info("starting server");
HttpHandler handler = getTestHandler();
JwtVerifyHandler jwtVerifyHandler = new JwtVerifyHandler();
jwtVerifyHandler.setNext(handler);
server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(jwtVerifyHandler)
.build();
server.start();
}
}
示例10: setUp
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@BeforeAll
public static void setUp() {
if(server == null) {
logger.info("starting server");
HttpHandler handler = getTestHandler();
server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(handler)
.build();
server.start();
}
}
示例11: WSSharedServer
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public WSSharedServer(Graph p_graph, int p_port) {
this.graph = p_graph;
this.port = p_port;
peers = new HashSet<WebSocketChannel>();
handlers = new HashMap<String, HttpHandler>();
handlers.put(PREFIX, Handlers.websocket(this));
}
示例12: main
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public static void main(String[]args){
Undertow server = Undertow.builder()
.addHttpListener(7070, "localhost")
.setHandler(new HttpHandler()
{
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Beos Bank !");
}
}).build();
server.start();
}
示例13: getHandler
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@Override
public HttpHandler getHandler() {
return Handlers.routing()
.add(Methods.GET, "/apic/data10", new Data10GetHandler())
.add(Methods.GET, "/apic/data11", new Data11GetHandler())
.add(Methods.GET, "/apic/data12", new Data12GetHandler())
.add(Methods.GET, "/apic/data13", new Data13GetHandler())
.add(Methods.GET, "/apic/data14", new Data14GetHandler())
.add(Methods.GET, "/apic/data15", new Data15GetHandler())
.add(Methods.GET, "/apic/data16", new Data16GetHandler())
.add(Methods.GET, "/apic/data17", new Data17GetHandler())
.add(Methods.GET, "/apic/data18", new Data18GetHandler())
.add(Methods.GET, "/apic/data19", new Data19GetHandler())
.add(Methods.GET, "/apic/data1", new Data1GetHandler())
.add(Methods.GET, "/apic/data20", new Data20GetHandler())
.add(Methods.GET, "/apic/data21", new Data21GetHandler())
.add(Methods.GET, "/apic/data22", new Data22GetHandler())
.add(Methods.GET, "/apic/data23", new Data23GetHandler())
.add(Methods.GET, "/apic/data24", new Data24GetHandler())
.add(Methods.GET, "/apic/data25", new Data25GetHandler())
.add(Methods.GET, "/apic/data2", new Data2GetHandler())
.add(Methods.GET, "/apic/data3", new Data3GetHandler())
.add(Methods.GET, "/apic/data4", new Data4GetHandler())
.add(Methods.GET, "/apic/data5", new Data5GetHandler())
.add(Methods.GET, "/apic/data6", new Data6GetHandler())
.add(Methods.GET, "/apic/data7", new Data7GetHandler())
.add(Methods.GET, "/apic/data8", new Data8GetHandler())
.add(Methods.GET, "/apic/data9", new Data9GetHandler())
.add(Methods.GET, "/apic/server/info", new ServerInfoGetHandler())
;
}
示例14: getHandler
import io.undertow.server.HttpHandler; //导入依赖的package包/类
@Override
public HttpHandler getHandler() {
return Handlers.routing()
.add(Methods.GET, "/apid/data10", new Data10GetHandler())
.add(Methods.GET, "/apid/data11", new Data11GetHandler())
.add(Methods.GET, "/apid/data12", new Data12GetHandler())
.add(Methods.GET, "/apid/data13", new Data13GetHandler())
.add(Methods.GET, "/apid/data14", new Data14GetHandler())
.add(Methods.GET, "/apid/data15", new Data15GetHandler())
.add(Methods.GET, "/apid/data16", new Data16GetHandler())
.add(Methods.GET, "/apid/data17", new Data17GetHandler())
.add(Methods.GET, "/apid/data18", new Data18GetHandler())
.add(Methods.GET, "/apid/data19", new Data19GetHandler())
.add(Methods.GET, "/apid/data1", new Data1GetHandler())
.add(Methods.GET, "/apid/data20", new Data20GetHandler())
.add(Methods.GET, "/apid/data21", new Data21GetHandler())
.add(Methods.GET, "/apid/data22", new Data22GetHandler())
.add(Methods.GET, "/apid/data23", new Data23GetHandler())
.add(Methods.GET, "/apid/data24", new Data24GetHandler())
.add(Methods.GET, "/apid/data25", new Data25GetHandler())
.add(Methods.GET, "/apid/data2", new Data2GetHandler())
.add(Methods.GET, "/apid/data3", new Data3GetHandler())
.add(Methods.GET, "/apid/data4", new Data4GetHandler())
.add(Methods.GET, "/apid/data5", new Data5GetHandler())
.add(Methods.GET, "/apid/data6", new Data6GetHandler())
.add(Methods.GET, "/apid/data7", new Data7GetHandler())
.add(Methods.GET, "/apid/data8", new Data8GetHandler())
.add(Methods.GET, "/apid/data9", new Data9GetHandler())
.add(Methods.GET, "/apid/server/info", new ServerInfoGetHandler())
;
}
示例15: SpdyReceiveListener
import io.undertow.server.HttpHandler; //导入依赖的package包/类
public SpdyReceiveListener(HttpHandler rootHandler, OptionMap undertowOptions, int bufferSize) {
this.rootHandler = rootHandler;
this.undertowOptions = undertowOptions;
this.bufferSize = bufferSize;
this.maxEntitySize = undertowOptions.get(UndertowOptions.MAX_ENTITY_SIZE, UndertowOptions.DEFAULT_MAX_ENTITY_SIZE);
this.allowEncodingSlash = undertowOptions.get(UndertowOptions.ALLOW_ENCODED_SLASH, false);
this.decode = undertowOptions.get(UndertowOptions.DECODE_URL, true);
if (undertowOptions.get(UndertowOptions.DECODE_URL, true)) {
this.encoding = undertowOptions.get(UndertowOptions.URL_CHARSET, "UTF-8");
} else {
this.encoding = null;
}
}