本文整理汇总了Java中io.undertow.Handlers类的典型用法代码示例。如果您正苦于以下问题:Java Handlers类的具体用法?Java Handlers怎么用?Java Handlers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Handlers类属于io.undertow包,在下文中一共展示了Handlers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customize
import io.undertow.Handlers; //导入依赖的package包/类
@Override
public void customize(DeploymentInfo deploymentInfo) {
deploymentInfo.addInitialHandlerChainWrapper(handler -> {
return Handlers.path()
.addPrefixPath("/", handler)
.addPrefixPath(path, new ServerSentEventHandler(new EventBusHandler()){
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequest(HttpServerExchange exchange) throws Exception {
if( reservationCheck(exchange) ) {
super.handleRequest(exchange);
}
}
});
}
);
}
示例2: BasicAuthHandler
import io.undertow.Handlers; //导入依赖的package包/类
public BasicAuthHandler(HttpHandler next, String expectedUsername, String expectedPassword) {
this.expectedCredential = "Basic " + Base64.getEncoder()
.encodeToString((expectedUsername + ":" + expectedPassword).getBytes());
this.authChecker = Handlers.predicate(exchange -> {
String userCredential = getRequestHeader(exchange, new HttpString("Authorization"));
if (userCredential == null) {
return false;
} else if (expectedCredential.equals(userCredential)) {
return true;
}
return false;
}, next, exchange -> {
exchange.getResponseHeaders()
.put(new HttpString("WWW-Authenticate"), "Basic realm=\"realm\"");
exchange.setStatusCode(StatusCodes.UNAUTHORIZED)
.endExchange();
});
}
示例3: getPetStoreHandler
import io.undertow.Handlers; //导入依赖的package包/类
RoutingHandler getPetStoreHandler() {
return Handlers.routing()
.add(Methods.POST, "/v1/pets", exchange -> exchange.getResponseSender().send("addPet"))
.add(Methods.GET, "/v1/pets/{petId}", exchange -> exchange.getResponseSender().send("getPetById"))
.add(Methods.DELETE, "/v1/pets/{petId}", exchange -> exchange.getResponseSender().send("deletePetById"))
.add(Methods.GET, "/v1/pets", exchange -> exchange.getResponseSender().send("getPets"));
}
示例4: getTestHandler
import io.undertow.Handlers; //导入依赖的package包/类
static RoutingHandler getTestHandler() {
return Handlers.routing()
.add(Methods.GET, "/get", exchange -> {
SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
Session session = sessionManager.getSession(exchange);
if(session == null) {
session = sessionManager.createSession(exchange);
session.setAttribute(COUNT, 0);
logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
}
Integer count = (Integer) session.getAttribute(COUNT);
logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
session.setAttribute(COUNT, ++count);
});
}
示例5: getHandler
import io.undertow.Handlers; //导入依赖的package包/类
@Override
public HttpHandler getHandler() {
return Handlers.routing()
.add(Methods.GET, GraphqlUtil.config.getPath(), new GraphqlGetHandler())
.add(Methods.POST, GraphqlUtil.config.getPath(), new GraphqlPostHandler())
.add(Methods.GET, "/server/info", new ServerInfoGetHandler())
;
}
示例6: getTestHandler
import io.undertow.Handlers; //导入依赖的package包/类
static RoutingHandler getTestHandler() {
return Handlers.routing()
.add(Methods.GET, "/v2/pet/{petId}", exchange -> {
Map<String, Object> examples = new HashMap<>();
examples.put("application/xml", StringEscapeUtils.unescapeHtml4("<Pet> <id>123456</id> <name>doggie</name> <photoUrls> <photoUrls>string</photoUrls> </photoUrls> <tags> </tags> <status>string</status></Pet>"));
examples.put("application/json", StringEscapeUtils.unescapeHtml4("{ "photoUrls" : [ "aeiou" ], "name" : "doggie", "id" : 123456789, "category" : { "name" : "aeiou", "id" : 123456789 }, "tags" : [ { "name" : "aeiou", "id" : 123456789 } ], "status" : "aeiou"}"));
if(examples.size() > 0) {
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send((String)examples.get("application/json"));
} else {
exchange.endExchange();
}
})
.add(Methods.GET, "/v2/pet", exchange -> exchange.getResponseSender().send("get"));
}
示例7: WSSharedServer
import io.undertow.Handlers; //导入依赖的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));
}
示例8: start
import io.undertow.Handlers; //导入依赖的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
}
示例9: WSServer
import io.undertow.Handlers; //导入依赖的package包/类
public WSServer(GraphBuilder p_builder, int p_port) {
this.builder = p_builder;
this.port = p_port;
peers = new HashSet<WebSocketChannel>();
handlers = new HashMap<String, HttpHandler>();
handlers.put(PREFIX, Handlers.websocket(this));
}
示例10: start
import io.undertow.Handlers; //导入依赖的package包/类
public void start() {
final 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();
if (builder.storage != null) {
builder.storage.listen(this);
} else if (builder.storageFactory != null) {
builder.storageFactory.listen(this);
}
}
示例11: Server
import io.undertow.Handlers; //导入依赖的package包/类
public Server() {
Undertow server = Undertow.builder().addHttpListener(port, "0.0.0.0",
Handlers.path()
.addPrefixPath("rpc", this)
.addPrefixPath("/", new ResourceHandler(new ClassPathResourceManager(Server.class.getClassLoader(), "static")).addWelcomeFiles("index.html").setDirectoryListingEnabled(false))
).build();
server.start();
System.out.println("Server running at : 9077");
}
示例12: main
import io.undertow.Handlers; //导入依赖的package包/类
public static void main(String[] args) {
final String urltoConnect = "ws://localhost:5678";
final String serverUrl = "0.0.0.0";
final int serverPort = 8080;
Undertow server = Undertow.builder()
.addHttpListener(serverPort,serverUrl)
.setHandler(
Handlers.path(
Handlers.resource(
new PathResourceManager(Paths.get("plugins/visualizer/src/main/resources").toAbsolutePath(),0)
)
)
)
.build();
server.start();
StringBuilder goToBuilder = new StringBuilder();
goToBuilder.append("http://")
.append(serverUrl)
.append(":")
.append(serverPort)
.append("?q=")
.append(urltoConnect);
System.out.println("Go to: " + goToBuilder);
System.out.println();
}
示例13: customize
import io.undertow.Handlers; //导入依赖的package包/类
@Override
public void customize(DeploymentInfo deploymentInfo) {
deploymentInfo.addInitialHandlerChainWrapper(handler -> {
return Handlers.path()
.addPrefixPath("/", handler)
.addPrefixPath(path, new WebSocketProtocolHandshakeHandler(new WSHandler()) {
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (reservationCheck(exchange)) {
super.handleRequest(exchange);
}
}
});
}
);
}
示例14: main
import io.undertow.Handlers; //导入依赖的package包/类
public static void main(String[] args) {
DeploymentInfo servletBuilder
= Servlets.deployment()
.setClassLoader(MainVaadin.class.getClassLoader())
.setContextPath(CONTEXT_PATH)
.setDeploymentName("ROOT.war")
.setDefaultEncoding("UTF-8")
.addServlets(
servlet(
MainServlet.class.getSimpleName(),
MainServlet.class).addMapping("/*")
);
DeploymentManager manager = Servlets
.defaultContainer()
.addDeployment(servletBuilder);
manager.deploy();
try {
HttpHandler httpHandler = manager.start();
PathHandler path = Handlers.path(redirect(CONTEXT_PATH))
.addPrefixPath(CONTEXT_PATH, httpHandler);
Undertow undertowServer = Undertow.builder()
.addHttpListener(8080, "0.0.0.0")
.setHandler(path)
.build();
undertowServer.start();
undertow = Result.success(undertowServer);
undertowServer.getListenerInfo().forEach(System.out::println);
} catch (ServletException e) {
e.printStackTrace();
undertow = Result.failure(e.getMessage());
}
}
示例15: getHandler
import io.undertow.Handlers; //导入依赖的package包/类
@Override
public HttpHandler getHandler() {
return Handlers.routing()
.add(Methods.GET, "/apib/data10", new Data10GetHandler())
.add(Methods.GET, "/apib/data11", new Data11GetHandler())
.add(Methods.GET, "/apib/data12", new Data12GetHandler())
.add(Methods.GET, "/apib/data13", new Data13GetHandler())
.add(Methods.GET, "/apib/data14", new Data14GetHandler())
.add(Methods.GET, "/apib/data15", new Data15GetHandler())
.add(Methods.GET, "/apib/data16", new Data16GetHandler())
.add(Methods.GET, "/apib/data17", new Data17GetHandler())
.add(Methods.GET, "/apib/data18", new Data18GetHandler())
.add(Methods.GET, "/apib/data19", new Data19GetHandler())
.add(Methods.GET, "/apib/data1", new Data1GetHandler())
.add(Methods.GET, "/apib/data20", new Data20GetHandler())
.add(Methods.GET, "/apib/data21", new Data21GetHandler())
.add(Methods.GET, "/apib/data22", new Data22GetHandler())
.add(Methods.GET, "/apib/data23", new Data23GetHandler())
.add(Methods.GET, "/apib/data24", new Data24GetHandler())
.add(Methods.GET, "/apib/data25", new Data25GetHandler())
.add(Methods.GET, "/apib/data2", new Data2GetHandler())
.add(Methods.GET, "/apib/data3", new Data3GetHandler())
.add(Methods.GET, "/apib/data4", new Data4GetHandler())
.add(Methods.GET, "/apib/data5", new Data5GetHandler())
.add(Methods.GET, "/apib/data6", new Data6GetHandler())
.add(Methods.GET, "/apib/data7", new Data7GetHandler())
.add(Methods.GET, "/apib/data8", new Data8GetHandler())
.add(Methods.GET, "/apib/data9", new Data9GetHandler())
.add(Methods.GET, "/apib/server/info", new ServerInfoGetHandler())
;
}