public UndertowRequest(final HttpServerExchange exchange, final Config conf) throws IOException { this.exchange = exchange; this.blocking = Suppliers.memoize(() -> this.exchange.startBlocking()); this.conf = conf; this.path = Router.decode(exchange.getRequestPath()); }
private void handleRestRequest(HttpServerExchange exchange) throws IOException { logger.log(Level.INFO, "HTTP request received:" + exchange.getRelativePath()); exchange.startBlocking(); if (exchange.getRelativePath().startsWith("/file/")) { handleFileRequest(exchange); } else { handleNormalRequest(exchange); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(handler); } else { handler.handleRequest(exchange); } }
/** * read from input stream, convert it to string, put into this.bodyContent */ private void dumpInputStream(){ //dump request body exchange.startBlocking(); InputStream inputStream = exchange.getInputStream(); try { if(config.isMaskEnabled() && inputStream.available() != -1) { this.bodyContent = Mask.maskJson(inputStream, "requestBody"); } else { try { this.bodyContent = StringUtils.inputStreamToString(inputStream, StandardCharsets.UTF_8); } catch (IOException e) { logger.error(e.toString()); } } } catch (IOException e) { logger.error("undertow inputstream error:" + e.getMessage()); } }
/** * Sends a continue response using blocking IO * * @param exchange The exchange */ public static void sendContinueResponseBlocking(final HttpServerExchange exchange) throws IOException { if (!exchange.isResponseChannelAvailable()) { throw UndertowMessages.MESSAGES.cannotSendContinueResponse(); } if(exchange.getAttachment(ALREADY_SENT) != null) { return; } HttpServerExchange newExchange = exchange.getConnection().sendOutOfBandResponse(exchange); exchange.putAttachment(ALREADY_SENT, true); newExchange.setStatusCode(StatusCodes.CONTINUE); newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0); newExchange.startBlocking(); newExchange.getOutputStream().close(); newExchange.getInputStream().close(); }
return; exchange.startBlocking(); InputStream is = exchange.getInputStream(); try { return; exchange.startBlocking(); try { Object data;
@Override public final void handleRequest(HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { if (executorService == null) { exchange.dispatch(this); } else { exchange.putAttachment(EXECUTOR, executorService); exchange.dispatch(executorService, this); } return; } else if (executorService != null && exchange.getAttachment(EXECUTOR) == null) { exchange.putAttachment(EXECUTOR, executorService); exchange.dispatch(executorService, this); return; } exchange.startBlocking(); handleInternal(exchange); }
private boolean writeFavicon(InputStream inputStream, HttpServerExchange exchange) throws IOException { if (inputStream != null) { exchange.startBlocking(); OutputStream os = exchange.getOutputStream(); byte[] buffer = new byte[1024]; while (inputStream.read(buffer) > -1) { os.write(buffer); } exchange.endExchange(); return true; } return false; }
@Override public OutputStream getOutputStream() { if (!exchange.isBlocking()) exchange.startBlocking(); return exchange.getOutputStream(); }
@Override public void serve(final Sender sender, final HttpServerExchange exchange, final IoCallback ioCallback) { exchange.startBlocking(); final OutputStream outStream = exchange.getOutputStream(); try { Files.copy(path, outStream); ioCallback.onComplete(exchange, sender); } catch (IOException e) { LOG.error("Could not serve content file", e); ioCallback.onException(exchange, sender, e); } }
@Override public InputStream getInputStream(boolean buffered) { if (!exchange.isBlocking()) exchange.startBlocking(); if (inputStream != null) { return inputStream; } if (buffered) { return inputStream = new BufferedInputStream(exchange.getInputStream()); } return exchange.getInputStream(); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(handler); } else { handler.handleRequest(exchange); } }
@Override public InputStream createInputStream() throws IllegalStateException { if (null != body) { return new ByteArrayInputStream(body); } if (!hse.isBlocking()) { hse.startBlocking(new ActBlockingExchange(hse, ActionContext.current())); } return hse.getInputStream(); }
private void ensureBlocking() { if (!blocking()) { hse.startBlocking(new ActBlockingExchange(hse, ActionContext.current())); } }
private void ensureBlocking() { if (!blocking()) { hse.startBlocking(new ActBlockingExchange(hse, ActionContext.current())); } }
private void parseMultipartForm() throws IOException { this.exchange.startBlocking(); final FormDataParser formDataParser = new MultiPartParserDefinition().setTempFileLocation(new File(TMP_DIR).toPath()).setDefaultEncoding(CHARSET).create(this.exchange); if (formDataParser != null) { final FormData formData = formDataParser.parseBlocking(); this.exchange.putAttachment(FormDataParser.FORM_DATA, formData); extractFormParameters(formData); } }
private Body getBody(HttpServerExchange exchange) throws IOException { Body body = new Body(); if (exchange.getRequestMethod().equals(Methods.POST) || exchange.getRequestMethod().equals(Methods.PUT)) { exchange.startBlocking(); body.setContent(IOUtils.toString(exchange.getInputStream())); } return body; }
@Override public Credential readCredential(HttpServerExchange exchange) throws IOException { final Tuple<String,String> contentTypeAndEncoding = URL .fixContentType( exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE ), null ); if ( Mimes.JSON.equals( contentTypeAndEncoding.getFirst() ) && formAuthConfiguration.isTryingToLogin( exchange ) ) { if ( !exchange.isBlocking() ) exchange.startBlocking(); final JSONCredentials json = jackson.objectMapper().readValue(exchange.getInputStream(), JSONCredentials.class); return new UsernameAndPasswordCredential(json.username, json.password); } return null; }
private void parseEncodedForm() throws IOException { this.exchange.startBlocking(); final FormData formData = new FormEncodedDataDefinition().setDefaultEncoding(this.exchange.getRequestCharset()).create(exchange).parseBlocking(); this.exchange.putAttachment(FormDataParser.FORM_DATA, formData); extractFormParameters(formData); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.startBlocking(); exchange.setResponseCode(this.response.getStatusCode()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, ContentType.APPLICATION_OCTETE_STREAM.toString()); exchange.getResponseHeaders().put(Headers.CONTENT_DISPOSITION, "inline; filename=" + this.response.getBinaryFileName()); exchange.getResponseHeaders().put(Headers.SERVER, Default.SERVER.toString()); this.response.getHeaders().forEach((key, value) -> exchange.getResponseHeaders().add(key, value)); //NOSONAR exchange.getOutputStream().write(this.response.getBinaryContent()); } }