public BlockingWebSocketHttpServerExchange(final HttpServerExchange exchange, Set<WebSocketChannel> peerConnections) { super(exchange, peerConnections); out = exchange.getOutputStream(); in = exchange.getInputStream(); }
private void handleFileRequest(HttpServerExchange exchange) throws FileNotFoundException, IOException { String tempFileToken = exchange.getRelativePath().substring("/file/".length()); File tempFile = daemonWebServer.getFileTokenTempFileFromCache(tempFileToken); if (tempFile != null) { logger.log(Level.INFO, "- Temp file: " + tempFileToken); IOUtils.copy(new FileInputStream(tempFile), exchange.getOutputStream()); exchange.endExchange(); } else { logger.log(Level.WARNING, "Invalid request received; Cannot find file token " + tempFileToken); eventBus.post(new BadRequestResponse(-1, "Invalid request.")); } } }
@Override public void writeInvocationResult(Object result) { if(identifier != null) { cancellationFlags.remove(identifier); } try { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, EjbHeaders.EJB_RESPONSE_VERSION_ONE.toString()); // if (output.getSessionAffinity() != null) { // exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", output.getSessionAffinity()).setPath(WILDFLY_SERVICES)); // } final Marshaller marshaller = HttpServerHelper.RIVER_MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); OutputStream outputStream = exchange.getOutputStream(); final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream)); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(result); // TODO: Do we really need to send this back? PackedInteger.writePackedInteger(marshaller, contextData.size()); for(Map.Entry<String, Object> entry : contextData.entrySet()) { marshaller.writeObject(entry.getKey()); marshaller.writeObject(entry.getValue()); } marshaller.finish(); marshaller.flush(); exchange.endExchange(); } catch (Exception e) { HttpServerHelper.sendException(exchange, 500, e); } } }
/** * 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(); }
private static void doMarshall(HttpServerExchange exchange, Object result) throws IOException { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jndi-jbmar-value;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(exchange.getOutputStream()))); marshaller.writeObject(result); marshaller.finish(); }
public static void sendException(HttpServerExchange exchange, int status, Throwable e) throws IOException { 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); OutputStream outputStream = exchange.getOutputStream(); final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream)); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(e); marshaller.write(0); marshaller.finish(); marshaller.flush(); } }
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 = RIVER_MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); OutputStream outputStream = exchange.getOutputStream(); final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(e); marshaller.write(0); marshaller.finish(); marshaller.flush(); exchange.endExchange(); } catch (Exception ex) { HttpClientMessages.MESSAGES.failedToWriteException(ex); exchange.endExchange(); } } }
@Override public OutputStream getResponseBody() throws IOException { return undertowExchange.getOutputStream(); }
@Override protected OutputStream createOutputStream() { ensureBlocking(); return hse.getOutputStream(); }
public BlockingWebSocketHttpServerExchange(final HttpServerExchange exchange, Set<WebSocketChannel> peerConnections) { super(exchange, peerConnections); out = exchange.getOutputStream(); in = exchange.getInputStream(); }
@Override protected OutputStream createOutputStream() { ensureBlocking(); return hse.getOutputStream(); }
@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 OutputStream getOutputStream() { if (!exchange.isBlocking()) exchange.startBlocking(); return exchange.getOutputStream(); }
@Override public void sendError(int code, String message) { exchange.setResponseCode(code); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); try { exchange.getOutputStream().write(message.getBytes()); } catch (IOException e) { throw new RuntimeException(e); } exchange.endExchange(); }
@Override public void sendError(int code, String message) { exchange.setResponseCode(code); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); try { exchange.getOutputStream().write(message.getBytes()); } catch (IOException e) { throw new RuntimeException(e); } exchange.endExchange(); }
public static void serialize(BinaryResponseBody value, HttpServerExchange exchange) throws IOException { Preconditions.checkNotNull(value, "A BinaryResponseBody value is required"); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, CONTENT_TYPE); value.write(exchange.getOutputStream()); }
@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()); } }
private static void doMarshall(HttpServerExchange exchange, Object result) throws IOException { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jndi-jbmar-value;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(exchange.getOutputStream()))); marshaller.writeObject(result); marshaller.finish(); }
private static void doMarshall(HttpServerExchange exchange, Object result) throws IOException { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jndi-jbmar-value;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(exchange.getOutputStream()))); marshaller.writeObject(result); marshaller.finish(); }