@Override public InputStream in() { blocking.get(); return exchange.getInputStream(); }
public BlockingWebSocketHttpServerExchange(final HttpServerExchange exchange, Set<WebSocketChannel> peerConnections) { super(exchange, peerConnections); out = exchange.getOutputStream(); in = exchange.getInputStream(); }
/** * 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()); } }
private void handleNormalRequest(HttpServerExchange exchange) throws IOException { String message = IOUtils.toString(exchange.getInputStream()); // TODO [high] Read entire file to memory. Dangerous! logger.log(Level.INFO, "REST message received: " + message); try { Request request; switch (requestFormatType) { case JSON: request = JsonMessageFactory.toRequest(message); break; case XML: request = XmlMessageFactory.toRequest(message); break; default: throw new Exception("Unknown request format. Valid formats are " + Joiner.on(", ").join(RequestFormatType.values())); } daemonWebServer.putRequestFormatType(request.getId(), requestFormatType); daemonWebServer.putCacheRestRequest(request.getId(), exchange); eventBus.post(request); } catch (Exception e) { logger.log(Level.WARNING, "Invalid request received; cannot serialize to Request.", e); eventBus.post(new BadRequestResponse(-1, "Invalid request.")); } }
return existing; InputStream inputStream = exchange.getInputStream(); if (inputStream == null) { throw new IOException(UndertowMessages.MESSAGES.requestChannelAlreadyProvided());
/** * 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(); }
@Override protected final Object doOperation(HttpServerExchange exchange, String name) throws NamingException { ContentType contentType = ContentType.parse(exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE)); if (contentType == null || !contentType.getType().equals("application/x-wf-jndi-jbmar-value") || contentType.getVersion() != 1) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); exchange.endExchange(); return null; } final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); try (InputStream inputStream = exchange.getInputStream()) { Unmarshaller unmarshaller = MARSHALLER_FACTORY.createUnmarshaller(marshallingConfiguration); unmarshaller.start(new InputStreamByteInput(inputStream)); Object object = unmarshaller.readObject(); unmarshaller.finish(); doOperation(name, object); } catch (Exception e) { NamingException nm = new NamingException(e.getMessage()); nm.initCause(e); throw nm; } return null; }
InputStream is = exchange.getInputStream(); try { Object body;
Unmarshaller unmarshaller = HttpServerHelper.RIVER_MARSHALLER_FACTORY.createUnmarshaller(marshallingConfiguration); try (InputStream inputStream = exchange.getInputStream()) { unmarshaller.start(new InputStreamByteInput(inputStream)); txConfig = readTransaction(unmarshaller);
@Override public final void handleRequest(HttpServerExchange exchange) throws Exception { ContentType contentType = ContentType.parse(exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE)); if (contentType == null || contentType.getVersion() != 1 || !contentType.getType().equals(TransactionConstants.XID)) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s has incorrect or missing content type", exchange); return; } try { Unmarshaller unmarshaller = MARSHALLER_FACTORY.createUnmarshaller(createMarshallingConf()); unmarshaller.start(new InputStreamByteInput(exchange.getInputStream())); int formatId = unmarshaller.readInt(); int len = unmarshaller.readInt(); byte[] globalId = new byte[len]; unmarshaller.readFully(globalId); len = unmarshaller.readInt(); byte[] branchId = new byte[len]; unmarshaller.readFully(branchId); SimpleXid simpleXid = new SimpleXid(formatId, globalId, branchId); unmarshaller.finish(); ImportResult<LocalTransaction> transaction = transactionContext.findOrImportTransaction(simpleXid, 0); transaction.getTransaction().performFunction((ExceptionBiFunction<ImportResult<LocalTransaction>, HttpServerExchange, Void, Exception>) (o, exchange2) -> { handleImpl(exchange2, o); return null; }, transaction, exchange); } catch (Exception e) { sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e); } }
@Override public InputStream getRequestBody() throws IOException { return undertowExchange.getInputStream(); }
public byte[] getPayload() { if(this.payload == null){ try { this.payload = IOUtils.toByteArray(this.exchange.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } } final byte[] data = new byte[this.payload.length]; System.arraycopy(this.payload, 0, data, 0, this.payload.length); return data; }
public BlockingWebSocketHttpServerExchange(final HttpServerExchange exchange, Set<WebSocketChannel> peerConnections) { super(exchange, peerConnections); out = exchange.getOutputStream(); in = exchange.getInputStream(); }
@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 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(); }
private InputStream getRequestInputStream(HttpServerExchange exchange) { try { if (ParserUtil.isGzipped(exchange.getResponseHeaders().get(Headers.CONTENT_ENCODING))) { return new GZIPInputStream(exchange.getInputStream()); } return exchange.getInputStream(); } catch (Exception e) { throw new RuntimeException("Failed to get request InputStream", e); } } }
private InputStream getRequestInputStream(HttpServerExchange exchange) { try { if (ParserUtil.isGzipped(exchange.getResponseHeaders().get(Headers.CONTENT_ENCODING))) { return new GZIPInputStream(exchange.getInputStream()); } return exchange.getInputStream(); } catch (Exception e) { throw new RuntimeException("Failed to get request InputStream", e); } } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String txnId = exchange.getQueryParameters().getOrDefault(ID, new LinkedList<>()).peekFirst(); respondJson(exchange, app.withToken(getToken(exchange)) .processTransaction(txnId, exchange.getInputStream()).get()); }
@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(); }
@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(); }