當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。