Refine search
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.getResponseSender().send("OK"); } }
@Override public void send(final ByteBuffer buffer) throws Exception { exchange.getResponseSender().send(buffer); }
@Override protected CompletableFuture<Optional<Object>> send(final Optional<Object> id, final byte[] data) { synchronized (this) { CompletableFuture<Optional<Object>> promise = new CompletableFuture<>(); Sender sender = exchange.getResponseSender(); sender.send(ByteBuffer.wrap(data), new DoneCallback(promise, id, this::ifClose)); return promise; } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { Writer writer = new StringWriter(); try { TextFormat.write004(writer, registry.metricFamilySamples()); } catch (IOException e) { logger.error("error on put result:", e); } exchange.getResponseSender().send(writer.toString()); } }
private void handleRequestNoHandler(HttpServerExchange exchange) { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); if (webInterfacePlugins.size() == 0) { String responseMessage = "No web interface installed.<br />Use <tt>sy plugin install simpleweb --snapshot</tt> " + "to install a web interface, then restart the daemon."; exchange.getResponseSender().send(responseMessage); } else { String webInterfacePluginsList = StringUtil.join(webInterfacePlugins, ", ", new StringJoinListener<WebInterfacePlugin>() { public String getString(WebInterfacePlugin webInterfacePlugin) { return webInterfacePlugin.getId(); } }); String responseMessage = "Only one web interface can be installed, but " + webInterfacePlugins.size() + " plugins found: " + webInterfacePluginsList + "<br />Use <tt>sy plugin remove <pluginId></tt> to remove plugins, then restart the daemon."; exchange.getResponseSender().send(responseMessage); } } }
private void sendTo(HttpServerExchange serverExchange, Response response) throws Exception { String responseStr = createMessageStr(response); logger.log(Level.INFO, "Sending message to " + serverExchange.getHostAndPort() + ": " + responseStr); serverExchange.getResponseSender().send(responseStr); serverExchange.endExchange(); }
@Override public IoFuture<Void> sendData(final ByteBuffer data) { if (sender == null) { this.sender = exchange.getResponseSender(); } final FutureResult<Void> future = new FutureResult<>(); sender.send(data, new IoCallback() { @Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { future.setResult(null); } @Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); future.setException(exception); } }); return future.getIoFuture(); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders().put( Headers.CONTENT_TYPE, "application/json"); Map<String, Object> resMap = new HashMap<>(); resMap.put("access_token", JwtIssuer.getJwt(mockClaims())); resMap.put("token_type", "bearer"); resMap.put("expires_in", 600); exchange.getResponseSender().send(ByteBuffer.wrap( Config.getInstance().getMapper().writeValueAsBytes( resMap))); }
/** * There are situations that the downstream service returns an error status response and we just * want to bubble up to the caller and eventually to the original caller. * * @param exchange HttpServerExchange * @param status error status */ default void setExchangeStatus(HttpServerExchange exchange, Status status) { exchange.setStatusCode(status.getStatusCode()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json"); status.setDescription(status.getDescription().replaceAll("\\\\", "\\\\\\\\")); exchange.getResponseSender().send(status.toString()); StackTraceElement[] elements = Thread.currentThread().getStackTrace(); logger.error(status.toString() + " at " + elements[2].getClassName() + "." + elements[2].getMethodName() + "(" + elements[2].getFileName() + ":" + elements[2].getLineNumber() + ")"); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); exchange.setResponseCode(StatusCodes.OK); exchange.getResponseSender().send(html); exchange.endExchange(); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if(exchange.getRequestMethod().equals(Methods.TRACE)) { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "message/http"); StringBuilder body = new StringBuilder("TRACE "); body.append(exchange.getRequestURI()); if(!exchange.getQueryString().isEmpty()) { body.append('?'); body.append(exchange.getQueryString()); } body.append(' '); body.append(exchange.getProtocol().toString()); body.append("\r\n"); for(HeaderValues header : exchange.getRequestHeaders()) { for(String value : header) { body.append(header.getHeaderName()); body.append(": "); body.append(value); body.append("\r\n"); } } body.append("\r\n"); exchange.getResponseSender().send(body.toString()); } else { handler.handleRequest(exchange); } }
/** * This method is used to construct a standard error status in JSON format from an error code. * * @param exchange HttpServerExchange * @param code error code * @param args arguments for error description */ default void setExchangeStatus(HttpServerExchange exchange, String code, final Object... args) { Status status = new Status(code, args); if(status.getStatusCode() == 0) { // There is no entry in status.yml for this particular error code. status = new Status(ERROR_NOT_DEFINED, code); } exchange.setStatusCode(status.getStatusCode()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json"); status.setDescription(status.getDescription().replaceAll("\\\\", "\\\\\\\\")); exchange.getResponseSender().send(status.toString()); StackTraceElement[] elements = Thread.currentThread().getStackTrace(); logger.error(status.toString() + " at " + elements[2].getClassName() + "." + elements[2].getMethodName() + "(" + elements[2].getFileName() + ":" + elements[2].getLineNumber() + ")"); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { ServerInfoConfig config = (ServerInfoConfig)Config.getInstance().getJsonObjectConfig(CONFIG_NAME, ServerInfoConfig.class); if(config.isEnableServerInfo()) { Map<String, Object> infoMap = new LinkedHashMap<>(); infoMap.put("deployment", getDeployment()); infoMap.put("environment", getEnvironment(exchange)); infoMap.put("security", getSecurity()); infoMap.put("specification", Config.getInstance().getJsonMapConfigNoCache("swagger")); infoMap.put("component", ModuleRegistry.getRegistry()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(infoMap)); } else { setExchangeStatus(exchange, STATUS_SERVER_INFO_DISABLED); } }
@Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { if (!exchange.isResponseChannelAvailable()) { return false; } Set<Integer> codes = responseCodes; if (codes == null ? exchange.getStatusCode() >= StatusCodes.BAD_REQUEST : codes.contains(Integer.valueOf(exchange.getStatusCode()))) { final String errorPage = "<html><head><title>Error</title></head><body>" + exchange.getStatusCode() + " - " + StatusCodes.getReason(exchange.getStatusCode()) + "</body></html>"; exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + errorPage.length()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); Sender sender = exchange.getResponseSender(); sender.send(errorPage); return true; } return false; } };
/** * Send a simple response string. * * @param exchange the http server exchange * @param response the response string */ static void sendResponse(final HttpServerExchange exchange, final String response) { exchange.setStatusCode(StatusCodes.OK); exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, CONTENT_TYPE); final Sender sender = exchange.getResponseSender(); UndertowLogger.ROOT_LOGGER.mcmpSendingResponse(exchange.getSourceAddress(), exchange.getStatusCode(), exchange.getResponseHeaders(), response); sender.send(response); }
final Sender resp = exchange.getResponseSender(); resp.send(buf.toString());
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, CONTENT_TYPE); final Sender sender = exchange.getResponseSender(); sender.send("failed to process management request");
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final String urlWithIdAndToken = exchange.getRequestURL() + "?" + exchange.getQueryString(); logger.log(Level.INFO, "Got a request to " + urlWithIdAndToken); queue.add(urlWithIdAndToken); TimeUnit.SECONDS.sleep(2); final OAuthWebResponse oauthWebResponse = (OAuthWebResponse) queue.take(); logger.log(Level.INFO, "Got an oauth response with code " + oauthWebResponse.getCode()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); exchange.setResponseCode(oauthWebResponse.getCode()); exchange.getResponseSender().send(oauthWebResponse.getBody()); exchange.endExchange(); queue.add(Boolean.TRUE); } }
return true; exchange.getResponseSender().send(buffer);
public static void sendException(HttpServerExchange exchange, int status, Throwable e) { try { exchange.setStatusCode(status); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jbmar-exception;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); final Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream)); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(e); marshaller.write(0); marshaller.finish(); marshaller.flush(); exchange.getResponseSender().send(ByteBuffer.wrap(outputStream.toByteArray())); } catch (IOException e1) { HttpRemoteTransactionMessages.MESSAGES.debugf(e, "Failed to write exception"); } } }