當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpString類代碼示例

本文整理匯總了Java中io.undertow.util.HttpString的典型用法代碼示例。如果您正苦於以下問題:Java HttpString類的具體用法?Java HttpString怎麽用?Java HttpString使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpString類屬於io.undertow.util包,在下文中一共展示了HttpString類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: BasicAuthHandler

import io.undertow.util.HttpString; //導入依賴的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

示例2: getTestHandler

import io.undertow.util.HttpString; //導入依賴的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,代碼來源:RedisSessionMultipleIT.java

示例3: handleRequest

import io.undertow.util.HttpString; //導入依賴的package包/類
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    Map<String, Object> examples = new HashMap<>();
    if(examples.size() > 0) {
        exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
        exchange.getResponseSender().send((String)examples.get("application/json"));
    } else {
        exchange.endExchange();
    }
}
 
開發者ID:tnscorcoran,項目名稱:light-4-j-plugin-wrapper,代碼行數:11,代碼來源:ServerInfoGetHandler.java

示例4: handleExplicitTransferEncoding

import io.undertow.util.HttpString; //導入依賴的package包/類
private static StreamSinkConduit handleExplicitTransferEncoding(HttpServerExchange exchange, StreamSinkConduit channel, ConduitListener<StreamSinkConduit> finishListener, HeaderMap responseHeaders, String transferEncodingHeader, boolean headRequest) {
    HttpString transferEncoding = new HttpString(transferEncodingHeader);
    if (transferEncoding.equals(Headers.CHUNKED)) {
        if (headRequest) {
            return channel;
        }
        Boolean preChunked = exchange.getAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE);
        if(preChunked != null && preChunked) {
            return new PreChunkedStreamSinkConduit(channel, finishListener, exchange);
        } else {
            return new ChunkedStreamSinkConduit(channel, exchange.getConnection().getBufferPool(), true, !exchange.isPersistent(), responseHeaders, finishListener, exchange);
        }
    } else {

        if (headRequest) {
            return channel;
        }
        log.trace("Cancelling persistence because response is identity with no content length");
        // make it not persistent - very unfortunate for the next request handler really...
        exchange.setPersistent(false);
        responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
        return new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:HttpTransferEncoding.java

示例5: addAll

import io.undertow.util.HttpString; //導入依賴的package包/類
public synchronized RoutingHandler addAll(RoutingHandler routingHandler) {
    for (Entry<HttpString, PathTemplateMatcher<RoutingMatch>> entry : routingHandler.getMatches().entrySet()) {
        HttpString method = entry.getKey();
        PathTemplateMatcher<RoutingMatch> matcher = matches.get(method);
        if (matcher == null) {
            matches.put(method, matcher = new PathTemplateMatcher<>());
        }
        matcher.addAll(entry.getValue());
        // If we use allMethodsMatcher.addAll() we can have duplicate
        // PathTemplates which we want to ignore here so it does not crash.
        for (PathTemplate template : entry.getValue().getPathTemplates()) {
            if (allMethodsMatcher.get(template.getTemplateString()) == null) {
                allMethodsMatcher.add(template, new RoutingMatch());
            }
        }
    }
    return this;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:RoutingHandler.java

示例6: getTestHandler

import io.undertow.util.HttpString; //導入依賴的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: handleRequest

import io.undertow.util.HttpString; //導入依賴的package包/類
@Override
public void handleRequest(HttpServerExchange httpServerExchange) throws Exception {
    if (httpServerExchange.getRequestPath().equals("/rpc/charts")) {
        httpServerExchange.getResponseHeaders().add(new HttpString("Access-Control-Allow-Origin"), "*");
        httpServerExchange.setStatusCode(StatusCodes.OK);
        httpServerExchange.getResponseSender().send(root.get("charts").toString());
    }
}
 
開發者ID:datathings,項目名稱:greycat,代碼行數:9,代碼來源:Server.java

示例8: testGreeting

import io.undertow.util.HttpString; //導入依賴的package包/類
@Test
public void testGreeting() {
  Greeting test = sut.greeting(request, "test");
  assertEquals("Hello, test!", test.getContent());
  verify(request, times(1)).getExchange();
  verify(exchange, times(1)).getConnection();
  verify(connection, times(1)).pushResource(anyString(), any(HttpString.class), any(HeaderMap.class));
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:9,代碼來源:GreetingControllerTest.java

示例9: testGreetingPushBuilder

import io.undertow.util.HttpString; //導入依賴的package包/類
@Test
public void testGreetingPushBuilder() {
  when(request.newPushBuilder()).thenReturn(pushBuilder);
  when(pushBuilder.path(anyString())).thenReturn(pushBuilder);

  Greeting test = sut.greeting(request, "test");
  assertEquals("Hello, test!", test.getContent());
  verify(request, times(1)).getExchange();
  verify(exchange, times(1)).getConnection();
  verify(connection, times(1)).pushResource(anyString(), any(HttpString.class), any(HeaderMap.class));
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:12,代碼來源:GreetingControllerTest.java

示例10: getRequestHeader

import io.undertow.util.HttpString; //導入依賴的package包/類
private static String getRequestHeader(HttpServerExchange exchange, HttpString headerName) {
    if (exchange.getRequestHeaders()
            .contains(headerName)) {
        return exchange.getRequestHeaders()
                .get(headerName)
                .getFirst();
    }
    return null;
}
 
開發者ID:icha024,項目名稱:spur,代碼行數:10,代碼來源:BasicAuthHandler.java

示例11: setPathHandler

import io.undertow.util.HttpString; //導入依賴的package包/類
private <T> SpurServer setPathHandler(HttpString method, String path, BiConsumer<Req<T>, Res> reqRes, Class<T> classType) {
    if (serviceDefined.get()) {
        throw new IllegalStateException(SERVER_ALREADY_DEFINED);
    }
    endpointsMap.putIfAbsent(path, new HashMap<>());
    endpointsMap.get(path)
            .put(method, new Endpoint(method, path, reqRes, classType));
    return this;
}
 
開發者ID:icha024,項目名稱:spur,代碼行數:10,代碼來源:SpurServer.java

示例12: invokePathTemplateHandler

import io.undertow.util.HttpString; //導入依賴的package包/類
private void invokePathTemplateHandler(SpurOptions options, Map<HttpString, Endpoint> methodEndpointsMap, HttpServerExchange exchange) {

        HttpString requestMethod = exchange.getRequestMethod();
        String requestAccessControlRequestMethod = getRequestHeader(exchange, ACCESS_CONTROL_REQUEST_METHOD);
        String requestOrigin = getRequestHeader(exchange, Headers.ORIGIN);
        if (requestMethod.equals(HEAD)) {
            requestMethod = GET;
        } else if (requestMethod.equals(OPTIONS) && requestAccessControlRequestMethod != null && methodEndpointsMap.containsKey(
                new HttpString(requestAccessControlRequestMethod)) && isValidCorsOrigin(options, requestOrigin)) {
            setCorsMethodHeader(options, methodEndpointsMap, exchange);
            exchange.endExchange();
            return;
        }

        Endpoint endpoint = methodEndpointsMap.get(requestMethod);
        if (endpoint == null) {
            exchange.setStatusCode(StatusCodes.METHOD_NOT_ALLOWED);
            exchange.getResponseHeaders()
                    .put(Headers.ALLOW, getAllowedMethods(methodEndpointsMap, options));
            exchange.endExchange();
            return;
        }

        Req req = new Req(exchange, endpoint.getBodyClassType());
        req.parseBody((newExchange, body) -> endpoint.getReqResBiConsumer()
                .accept(req, new Res(newExchange)));
    }
 
開發者ID:icha024,項目名稱:spur,代碼行數:28,代碼來源:SpurServer.java

示例13: getRequestHeader

import io.undertow.util.HttpString; //導入依賴的package包/類
private String getRequestHeader(HttpServerExchange exchange, HttpString headerName) {
    if (exchange.getRequestHeaders()
            .contains(headerName)) {
        return exchange.getRequestHeaders()
                .get(headerName)
                .getFirst();
    }
    return null;
}
 
開發者ID:icha024,項目名稱:spur,代碼行數:10,代碼來源:SpurServer.java

示例14: getAllowedMethods

import io.undertow.util.HttpString; //導入依賴的package包/類
private String getAllowedMethods(Map<HttpString, Endpoint> methodEndpointMap, SpurOptions options) {
    StringBuilder methodsAllowed = new StringBuilder();
    Set<HttpString> methodsDefined = new TreeSet<>(methodEndpointMap.keySet());
    if (methodsDefined.contains(GET)) {
        methodsDefined.add(HEAD);
    }
    if (!options.corsHeaders.isEmpty()) {
        methodsDefined.add(OPTIONS);
    }

    methodsDefined.forEach(httpString -> methodsAllowed.append(", " + httpString));
    return methodsAllowed.toString()
            .substring(2);
}
 
開發者ID:icha024,項目名稱:spur,代碼行數:15,代碼來源:SpurServer.java

示例15: MethodPredicate

import io.undertow.util.HttpString; //導入依賴的package包/類
MethodPredicate(String[] methods) {
    HttpString[] values = new HttpString[methods.length];
    for(int i = 0; i < methods.length; ++i) {
        values[i] = HttpString.tryFromString(methods[i]);
    }
    this.methods = values;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:MethodPredicate.java


注:本文中的io.undertow.util.HttpString類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。