public void process(final HttpServerExchange exchange, final UaiResponse uaiResponse) { Log.infoFormatted("Response that will be sent: [%s]", uaiResponse); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, uaiResponse.getContentType()); exchange.setResponseCode(uaiResponse.getStatusCode()); setResponseHeaders(uaiResponse, exchange); defineResponseBody(exchange, uaiResponse); }
private void setResponseHeaders( final UaiResponse uaiResponse, final HttpServerExchange exchange) { for (UaiHeader uaiHeader : uaiResponse.getHeaderList()) { for (String value : uaiHeader.getValueList()) { exchange.getResponseHeaders().add(new HttpString(uaiHeader.getName()), value); } } }
private void defineResponseBody(HttpServerExchange exchange, UaiResponse uaiResponse) { if (!uaiResponse.isBodyPointingToFile() && uaiResponse.getBody() != null) { exchange.getResponseSender().send(uaiResponse.getBody()); return; } if (uaiResponse.isBodyPointingToFile() && StringUtils.isNotBlank(uaiResponse.getBodyPath())) { final ByteBuffer wrap = FileUtil.getFileAsByteBuffer(uaiResponse.getBodyPath()); exchange.startBlocking(); exchange.getResponseSender().send(wrap); } }