当前位置: 首页>>代码示例>>Java>>正文


Java Handlers类代码示例

本文整理汇总了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);
                        }
                    }
                });
        }
    );
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:18,代码来源:EventBusToServerSentEvents.java

示例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();
    });
}
 
开发者ID:icha024,项目名称:spur,代码行数:19,代码来源:BasicAuthHandler.java

示例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"));
}
 
开发者ID:networknt,项目名称:light-rest-4j,代码行数:8,代码来源:ValidatorHandlerTest.java

示例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);
            });
}
 
开发者ID:networknt,项目名称:light-session-4j,代码行数:17,代码来源:JdbcSessionMultipleTest.java

示例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())
            ;
}
 
开发者ID:networknt,项目名称:light-graphql-4j,代码行数:9,代码来源:GraphqlRouter.java

示例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("&lt;Pet&gt;  &lt;id&gt;123456&lt;/id&gt;  &lt;name&gt;doggie&lt;/name&gt;  &lt;photoUrls&gt;    &lt;photoUrls&gt;string&lt;/photoUrls&gt;  &lt;/photoUrls&gt;  &lt;tags&gt;  &lt;/tags&gt;  &lt;status&gt;string&lt;/status&gt;&lt;/Pet&gt;"));
                examples.put("application/json", StringEscapeUtils.unescapeHtml4("{  &quot;photoUrls&quot; : [ &quot;aeiou&quot; ],  &quot;name&quot; : &quot;doggie&quot;,  &quot;id&quot; : 123456789,  &quot;category&quot; : {    &quot;name&quot; : &quot;aeiou&quot;,    &quot;id&quot; : 123456789  },  &quot;tags&quot; : [ {    &quot;name&quot; : &quot;aeiou&quot;,    &quot;id&quot; : 123456789  } ],  &quot;status&quot; : &quot;aeiou&quot;}"));
                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"));
}
 
开发者ID:networknt,项目名称:light-graphql-4j,代码行数:16,代码来源:JwtVerifyHandlerTest.java

示例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));
}
 
开发者ID:datathings,项目名称:greycat,代码行数:8,代码来源:WSSharedServer.java

示例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
}
 
开发者ID:datathings,项目名称:greycat,代码行数:10,代码来源:WSSharedServer.java

示例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));
}
 
开发者ID:datathings,项目名称:greycat,代码行数:8,代码来源:WSServer.java

示例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);
    }
}
 
开发者ID:datathings,项目名称:greycat,代码行数:14,代码来源:WSServer.java

示例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");
}
 
开发者ID:datathings,项目名称:greycat,代码行数:10,代码来源:Server.java

示例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();

    }
 
开发者ID:datathings,项目名称:greycat,代码行数:34,代码来源:DebugVisualizerServer.java

示例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);
                        }
                    }
                });
        }
    );
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:18,代码来源:EventBusToWebSocket.java

示例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());
    }
  }
 
开发者ID:Java-Publications,项目名称:javamagazin-009-microkernel,代码行数:41,代码来源:MainVaadin.java

示例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())
    ;
}
 
开发者ID:tnscorcoran,项目名称:light-4-j-plugin-wrapper,代码行数:32,代码来源:PathHandlerProvider.java


注:本文中的io.undertow.Handlers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。