本文整理匯總了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();
});
}
示例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);
});
}
示例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();
}
}
示例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));
}
}
示例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;
}
示例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("<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: 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());
}
}
示例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));
}
示例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));
}
示例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;
}
示例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;
}
示例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)));
}
示例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;
}
示例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);
}
示例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;
}