io.undertow.util.HttpString Java Examples
The following examples show how to use
io.undertow.util.HttpString.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestUtils.java From mangooio with Apache License 2.0 | 6 votes |
/** * Return if a given HTTP method results in a read or write request to a resource * * GET = read * POST = write * PUT = write * DELETE = write * PATCH = write * OPTIONS = read * HEAD = read * * @param method The HTTP method * @return read or write if HTTP method is found, blank otherwise */ public static String getOperation(HttpString method) { String operation = ""; if (Methods.POST.equals(method)) { operation = WRITE; } else if (Methods.PUT.equals(method)) { operation = WRITE; } else if (Methods.DELETE.equals(method)) { operation = WRITE; } else if (Methods.GET.equals(method)) { operation = READ; } else if (Methods.PATCH.equals(method)) { operation = WRITE; } else if (Methods.OPTIONS.equals(method)) { operation = READ; } else if (Methods.HEAD.equals(method)) { operation = READ; } else { // ignore everything else } return operation; }
Example #2
Source File: HttpClientConnection.java From lams with GNU General Public License v2.0 | 6 votes |
private void prepareResponseChannel(ClientResponse response, ClientExchange exchange) { String encoding = response.getResponseHeaders().getLast(Headers.TRANSFER_ENCODING); boolean chunked = encoding != null && Headers.CHUNKED.equals(new HttpString(encoding)); String length = response.getResponseHeaders().getFirst(Headers.CONTENT_LENGTH); if (exchange.getRequest().getMethod().equals(Methods.HEAD)) { connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener)); } else if (chunked) { connection.getSourceChannel().setConduit(new ChunkedStreamSourceConduit(connection.getSourceChannel().getConduit(), pushBackStreamSourceConduit, bufferPool, responseFinishedListener, exchange, connection)); } else if (length != null) { try { long contentLength = Long.parseLong(length); connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), contentLength, responseFinishedListener)); } catch (NumberFormatException e) { handleError(e); throw e; } } else if (response.getProtocol().equals(Protocols.HTTP_1_1) && !Connectors.isEntityBodyAllowed(response.getResponseCode())) { connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener)); } else { connection.getSourceChannel().setConduit(new FinishableStreamSourceConduit(connection.getSourceChannel().getConduit(), responseFinishedListener)); state |= CLOSE_REQ; } }
Example #3
Source File: Oauth2ServiceServiceIdEndpointGetHandler.java From light-oauth2 with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { IMap<String, List<ServiceEndpoint>> serviceEndpoints = CacheStartupHookProvider.hz.getMap("serviceEndpoints"); String serviceId = exchange.getQueryParameters().get("serviceId").getFirst(); List<ServiceEndpoint> values = serviceEndpoints.get(serviceId); if(values == null || values.size() == 0) { setExchangeStatus(exchange, SERVICE_ENDPOINT_NOT_FOUND, serviceId); processAudit(exchange); return; } exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values)); processAudit(exchange); }
Example #4
Source File: HttpClientConnection.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) { if(http2Delegate != null) { http2Delegate.sendRequest(request, clientCallback); return; } if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) { clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState()); return; } final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this); boolean ssl = this.connection instanceof SslConnection; if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) { //this is the first request, as we want to try a HTTP2 upgrade request.getRequestHeaders().put(new HttpString("HTTP2-Settings"), Http2ClearClientProvider.createSettingsFrame(options, bufferPool)); request.getRequestHeaders().put(Headers.UPGRADE, Http2Channel.CLEARTEXT_UPGRADE_STRING); request.getRequestHeaders().put(Headers.CONNECTION, "Upgrade, HTTP2-Settings"); http2Tried = true; } if (currentRequest == null) { initiateRequest(httpClientExchange); } else { pendingQueue.add(httpClientExchange); } }
Example #5
Source File: Handler.java From light-4j with Apache License 2.0 | 6 votes |
/** * Add a PathChain (having a non-null path) to the handler data structures. */ private static void addPathChain(PathChain pathChain) { HttpString method = new HttpString(pathChain.getMethod()); // Use a random integer as the id for a given path. Integer randInt = new Random().nextInt(); while (handlerListById.containsKey(randInt.toString())) { randInt = new Random().nextInt(); } // Flatten out the execution list from a mix of middleware chains and handlers. List<HttpHandler> handlers = getHandlersFromExecList(pathChain.getExec()); if(handlers.size() > 0) { // If a matcher already exists for the given type, at to that instead of // creating a new one. PathTemplateMatcher<String> pathTemplateMatcher = methodToMatcherMap.containsKey(method) ? methodToMatcherMap.get(method) : new PathTemplateMatcher<>(); if(pathTemplateMatcher.get(pathChain.getPath()) == null) { pathTemplateMatcher.add(pathChain.getPath(), randInt.toString()); } methodToMatcherMap.put(method, pathTemplateMatcher); handlerListById.put(randInt.toString(), handlers); } }
Example #6
Source File: DnlFileRule.java From light with Apache License 2.0 | 6 votes |
public boolean execute(Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); String token = (String) data.get("token"); String path = null; Map<String, Object> fileMap = ServiceLocator.getInstance().getMemoryImage("fileMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)fileMap.get("cache"); if(cache != null) { path = (String)cache.get(token); } if(path == null) { inputMap.put("result", "Token is expired."); inputMap.put("responseCode", 400); return false; } else { HttpServerExchange exchange = (HttpServerExchange)inputMap.get("exchange"); File file = new File(path); String name = file.getName(); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-download"); exchange.getResponseHeaders().put(new HttpString("Content-disposition"), "attachment; filename=" + name); writeToOutputStream(file, exchange.getOutputStream()); return true; } }
Example #7
Source File: Oauth2RefreshTokenGetHandler.java From light-oauth2 with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens"); Deque<String> userIdDeque = exchange.getQueryParameters().get("userId"); String userId = userIdDeque == null? "%" : userIdDeque.getFirst() + "%"; int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1; Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize"); int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst()); if(logger.isDebugEnabled()) logger.debug("userId = " + userId + " page = " + page + " pageSize = " + pageSize); LikePredicate likePredicate = new LikePredicate("userId", userId); PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new RefreshTokenComparator(), pageSize); pagingPredicate.setPage(page); Collection<RefreshToken> values = tokens.values(pagingPredicate); exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values)); processAudit(exchange); }
Example #8
Source File: CorsUtilTest.java From light-4j with Apache License 2.0 | 6 votes |
/** * Test of matchOrigin method, of class CorsUtil. */ @Test public void testMatchOrigin() throws Exception { HeaderMap headerMap = new HeaderMap(); headerMap.add(HOST, "localhost:80"); headerMap.add(ORIGIN, "http://localhost"); HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10); exchange.setRequestScheme("http"); exchange.setRequestMethod(HttpString.EMPTY); Collection<String> allowedOrigins = null; assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost")); allowedOrigins = Collections.singletonList("http://www.example.com:9990"); //Default origin assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost")); headerMap.clear(); headerMap.add(HOST, "localhost:80"); headerMap.add(ORIGIN, "http://www.example.com:9990"); assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://www.example.com:9990")); headerMap.clear(); headerMap.add(HOST, "localhost:80"); headerMap.add(ORIGIN, "http://www.example.com"); assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is(nullValue())); headerMap.addAll(ORIGIN, Arrays.asList("http://localhost:8080", "http://www.example.com:9990", "http://localhost")); allowedOrigins = Arrays.asList("http://localhost", "http://www.example.com:9990"); assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost")); }
Example #9
Source File: HeaderLogParamTest.java From core-ng-project with Apache License 2.0 | 6 votes |
@Test void append() { var headers = new HeaderMap(); HttpString name = new HttpString("client-id"); headers.put(name, "client1"); var builder = new StringBuilder(); var param = new HeaderLogParam(name, headers.get(name)); param.append(builder, Set.of(), 1000); assertThat(builder.toString()).isEqualTo("client1"); headers.add(name, "client2"); builder = new StringBuilder(); param = new HeaderLogParam(name, headers.get(name)); param.append(builder, Set.of(), 1000); assertThat(builder.toString()).isEqualTo("[client1, client2]"); }
Example #10
Source File: ExtendedAccessLogParser.java From lams with GNU General Public License v2.0 | 6 votes |
protected ExchangeAttribute getServerToClientElement( PatternTokenizer tokenizer) throws IOException { if (tokenizer.hasSubToken()) { String token = tokenizer.getToken(); if ("status".equals(token)) { return ResponseCodeAttribute.INSTANCE; } else if ("comment".equals(token)) { return new ConstantExchangeAttribute("?"); } } else if (tokenizer.hasParameter()) { String parameter = tokenizer.getParameter(); if (parameter == null) { UndertowLogger.ROOT_LOGGER.extendedAccessLogMissingClosing(); return null; } return new QuotingExchangeAttribute(new ResponseHeaderAttribute(new HttpString(parameter))); } UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecode(tokenizer.getRemains()); return null; }
Example #11
Source File: TracingHandlerTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testWithSerializedContextData() throws Throwable { TracingHandler handler = new TracingHandler(httpHandler); HttpServerExchange exchange = buildExchange(); exchange.getRequestHeaders() .put(HttpString.tryFromString(SW8CarrierItem.HEADER_NAME), "1-My40LjU=-MS4yLjM=-3-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA="); handler.handleRequest(exchange); exchange.endExchange(); assertThat(segmentStorage.getTraceSegments().size(), is(1)); TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment); assertHttpSpan(spans.get(0)); assertTraceSegmentRef(traceSegment.getRefs().get(0)); }
Example #12
Source File: ForwardRequestHandler.java From light-rest-4j with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String responseBody = null; if(exchange.getAttachment(BodyHandler.REQUEST_BODY) != null) { responseBody = Config.getInstance().getMapper().writeValueAsString(exchange.getAttachment(BodyHandler.REQUEST_BODY)); } List<HttpString> headerNames = exchange.getRequestHeaders().getHeaderNames().stream() .filter( s -> s.toString().startsWith("todo")) .collect(Collectors.toList()); for(HttpString headerName : headerNames) { String headerValue = exchange.getRequestHeaders().get(headerName).getFirst(); exchange.getResponseHeaders().put(headerName, headerValue); } exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, ContentType.APPLICATION_JSON.value()); exchange.getResponseSender().send(responseBody); }
Example #13
Source File: Oauth2ClientGetHandler.java From light-oauth2 with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients"); Deque<String> clientNameDeque = exchange.getQueryParameters().get("clientName"); String clientName = clientNameDeque == null? "%" : clientNameDeque.getFirst() + "%"; int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1; Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize"); int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst()); LikePredicate likePredicate = new LikePredicate("clientName", clientName); PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new ClientComparator(), pageSize); pagingPredicate.setPage(page); Collection<Client> values = clients.values(pagingPredicate); List results = new ArrayList(); for (Client value : values) { Client c = Client.copyClient(value); c.setClientSecret(null); results.add(c); } exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(results)); processAudit(exchange); }
Example #14
Source File: Oauth2ClientClientIdGetHandler.java From light-oauth2 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void handleRequest(HttpServerExchange exchange) throws Exception { String clientId = exchange.getQueryParameters().get("clientId").getFirst(); IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients"); Client client = clients.get(clientId); if(client == null) { setExchangeStatus(exchange, CLIENT_NOT_FOUND, clientId); processAudit(exchange); return; } Client c = Client.copyClient(client); c.setClientSecret(null); exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(c)); processAudit(exchange); }
Example #15
Source File: MCMPHandler.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Handle a management+ request. * * @param method the http method * @param exchange the http server exchange * @throws Exception */ protected void handleRequest(final HttpString method, HttpServerExchange exchange) throws Exception { final RequestData requestData = parseFormData(exchange); boolean persistent = exchange.isPersistent(); exchange.setPersistent(false); //UNDERTOW-947 MCMP should not use persistent connections if (CONFIG.equals(method)) { processConfig(exchange, requestData); } else if (ENABLE_APP.equals(method)) { processCommand(exchange, requestData, MCMPAction.ENABLE); } else if (DISABLE_APP.equals(method)) { processCommand(exchange, requestData, MCMPAction.DISABLE); } else if (STOP_APP.equals(method)) { processCommand(exchange, requestData, MCMPAction.STOP); } else if (REMOVE_APP.equals(method)) { processCommand(exchange, requestData, MCMPAction.REMOVE); } else if (STATUS.equals(method)) { processStatus(exchange, requestData); } else if (INFO.equals(method)) { processInfo(exchange); } else if (DUMP.equals(method)) { processDump(exchange); } else if (PING.equals(method)) { processPing(exchange, requestData); } else { exchange.setPersistent(persistent); next.handleRequest(exchange); } }
Example #16
Source File: HttpServletResponseImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void addHeader(final String name, final String value) { if(name == null) { throw UndertowServletMessages.MESSAGES.headerNameWasNull(); } addHeader(HttpString.tryFromString(name), value); }
Example #17
Source File: SpecDisplayHandler.java From light-rest-4j with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { SpecificationConfig config = (SpecificationConfig)Config.getInstance().getJsonObjectConfig(CONFIG_NAME, SpecificationConfig.class); final String payload = Config.getInstance().getStringFromFile(config.getFileName()); exchange.getResponseHeaders().add(new HttpString("Content-Type"), config.getContentType()); exchange.getResponseSender().send(payload); }
Example #18
Source File: HttpServletResponseImpl.java From lams with GNU General Public License v2.0 | 5 votes |
public void addHeader(final HttpString name, final String value) { if(name == null) { throw UndertowServletMessages.MESSAGES.headerNameWasNull(); } if (insideInclude || ignoredFlushPerformed || treatAsCommitted) { return; } if(name.equals(Headers.CONTENT_TYPE) && !exchange.getResponseHeaders().contains(Headers.CONTENT_TYPE)) { setContentType(value); } else { exchange.getResponseHeaders().add(name, value); } }
Example #19
Source File: ProxyHandler.java From lams with GNU General Public License v2.0 | 5 votes |
ProxyHandler(Builder builder) { this.proxyClient = builder.proxyClient; this.maxRequestTime = builder.maxRequestTime; this.next = builder.next; this.rewriteHostHeader = builder.rewriteHostHeader; this.reuseXForwarded = builder.reuseXForwarded; this.maxConnectionRetries = builder.maxConnectionRetries; this.idempotentRequestPredicate = builder.idempotentRequestPredicate; for(Map.Entry<HttpString, ExchangeAttribute> e : builder.requestHeaders.entrySet()) { requestHeaders.put(e.getKey(), e.getValue()); } }
Example #20
Source File: SavedRequest.java From lams with GNU General Public License v2.0 | 5 votes |
public SavedRequest(byte[] data, int dataLength, HttpString method, String requestPath, HeaderMap headerMap) { this.data = data; this.dataLength = dataLength; this.method = method; this.requestPath = requestPath; for(HeaderValues val : headerMap) { this.headerMap.put(val.getHeaderName(), new ArrayList<>(val)); } }
Example #21
Source File: ResponseHeaderAttribute.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public ExchangeAttribute build(final String token) { if (token.startsWith("%{o,") && token.endsWith("}")) { final HttpString headerName = HttpString.tryFromString(token.substring(4, token.length() - 1)); return new ResponseHeaderAttribute(headerName); } return null; }
Example #22
Source File: JwtVerifyHandlerTest.java From light-rest-4j with Apache License 2.0 | 5 votes |
static RoutingHandler getTestHandler() { return Handlers.routing() .add(Methods.GET, "/v1/pets/{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, "/v1/pets", exchange -> exchange.getResponseSender().send("get")); }
Example #23
Source File: MCMPHandler.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Send an error message. * * @param type the error type * @param errString the error string * @param exchange the http server exchange */ static void processError(String type, String errString, HttpServerExchange exchange) { exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, CONTENT_TYPE); exchange.getResponseHeaders().add(new HttpString("Version"), VERSION_PROTOCOL); exchange.getResponseHeaders().add(new HttpString("Type"), type); exchange.getResponseHeaders().add(new HttpString("Mess"), errString); exchange.endExchange(); UndertowLogger.ROOT_LOGGER.mcmpProcessingError(type, errString); }
Example #24
Source File: ValidatorHandlerTest.java From light-rest-4j with Apache License 2.0 | 5 votes |
@Test public void testResponseContentValidationWithNoError() throws ClientException, URISyntaxException, ExecutionException, InterruptedException { ClientRequest clientRequest = new ClientRequest(); clientRequest.getRequestHeaders().put(new HttpString("todo_Header1"), "header_1"); CompletableFuture<ClientResponse> future = sendResponse(clientRequest, "response1"); String statusCode = future.get().getStatus(); Assert.assertEquals("OK", statusCode); List<String> errorLines = getErrorLinesFromLogFile(); Assert.assertTrue(errorLines.size() == 0); }
Example #25
Source File: RoutingHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public synchronized RoutingHandler add(HttpString method, String template, HttpHandler handler) { PathTemplateMatcher<RoutingMatch> matcher = matches.get(method); if (matcher == null) { matches.put(method, matcher = new PathTemplateMatcher<>()); } RoutingMatch res = matcher.get(template); if (res == null) { matcher.add(template, res = new RoutingMatch()); } if (allMethodsMatcher.get(template) == null) { allMethodsMatcher.add(template, res); } res.defaultHandler = handler; return this; }
Example #26
Source File: HpackEncoder.java From lams with GNU General Public License v2.0 | 5 votes |
private void writeHuffmanEncodableName(ByteBuffer target, HttpString headerName) { if (hpackHeaderFunction.shouldUseHuffman(headerName)) { if(HPackHuffman.encode(target, headerName.toString(), true)) { return; } } target.put((byte) 0); //to use encodeInteger we need to place the first byte in the buffer. encodeInteger(target, headerName.length(), 7); for (int j = 0; j < headerName.length(); ++j) { target.put(Hpack.toLower(headerName.byteAt(j))); } }
Example #27
Source File: ValidatorHandlerTest.java From light-rest-4j with Apache License 2.0 | 5 votes |
@Test public void testNoResponseContentValidation() throws ClientException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException { ClientRequest clientRequest = new ClientRequest(); clientRequest.getRequestHeaders().put(new HttpString("todo_Header1"), "header_1"); CompletableFuture<ClientResponse> future = sendResponse(clientRequest, ""); String statusCode = future.get().getStatus(); Assert.assertNotEquals("OK", statusCode); }
Example #28
Source File: HpackEncoder.java From lams with GNU General Public License v2.0 | 5 votes |
TableEntry(HttpString name, String value, int position) { this.name = name; this.value = value; this.position = position; if (value != null) { this.size = 32 + name.length() + value.length(); } else { this.size = -1; } }
Example #29
Source File: UndertowHttpHandler.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void handleRequest(HttpServerExchange exchange) throws Exception { try { ContainerRequest request = createContainerRequest(exchange); request.setWriter(new UndertowResponseWriter(exchange, container)); container.getApplicationHandler().handle(request); } catch (Throwable e) { if (exchange.isResponseChannelAvailable()) { exchange.setStatusCode(500); exchange.getResponseHeaders().add(new HttpString("Content-Type"), "text/plain"); exchange.getResponseSender().send(Exceptions.stackTrace(e)); } } }
Example #30
Source File: UndertowAdapter.java From enkan with Eclipse Public License 1.0 | 5 votes |
private void setResponseHeaders(Headers headers, HttpServerExchange exchange) { HeaderMap map = exchange.getResponseHeaders(); headers.keySet().forEach(headerName -> headers.getList(headerName) .forEach(v -> { if (v instanceof String) { map.add(HttpString.tryFromString(headerName), (String) v); } else if (v instanceof Number) { map.add(HttpString.tryFromString(headerName), ((Number) v).longValue()); } })); }