@Override public void handle(final Request request, final Response response) { final ResponseWriter responseWriter = new ResponseWriter(response, scheduler); final URI baseUri = getBaseUri(request); final URI requestUri = getRequestUri(request, baseUri); try { final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod(), getSecurityContext(request), new MapPropertiesDelegate()); requestContext.setEntityStream(request.getInputStream()); for (final String headerName : request.getNames()) { requestContext.headers(headerName, request.getValue(headerName)); } requestContext.setWriter(responseWriter); requestContext.setRequestScopedInitializer(injectionManager -> { injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request); injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response); }); appHandler.handle(requestContext); } catch (final Exception ex) { throw new RuntimeException(ex); } finally { if (!responseWriter.isSuspended()) { close(response); } } }
public InputStream getBodyAsStream() throws IOException { return request.getInputStream(); }
@Override public InputStream getRequestEntityStream(long size) { try { return this.request.getInputStream(); } catch (Exception ex) { return null; } }
@Override public InputStream inputStream() throws IOException { return request.getInputStream(); }
/** * This is used to read the content body. The specifics of the data * that is read from this <code>InputStream</code> can be determined * by the <code>getContentLength</code> method. If the data sent by * the client is chunked then it is decoded, see RFC 2616 section * 3.6. Also multipart data is available as <code>Part</code> objects * however the raw content of the multipart body is still available. * * @exception Exception signifies that there is an I/O problem * * @return returns the input stream containing the message body */ public InputStream getInputStream() throws IOException { return request.getInputStream(); }
/** * This is used to read the content body. The specifics of the data * that is read from this <code>InputStream</code> can be determined * by the <code>getContentLength</code> method. If the data sent by * the client is chunked then it is decoded, see RFC 2616 section * 3.6. Also multipart data is available as <code>Part</code> objects * however the raw content of the multipart body is still available. * * @exception Exception signifies that there is an I/O problem * * @return returns the input stream containing the message body */ public InputStream getInputStream() throws IOException { return request.getInputStream(); }
/** * This is used to read the content body. The specifics of the data * that is read from this <code>InputStream</code> can be determined * by the <code>getContentLength</code> method. If the data sent by * the client is chunked then it is decoded, see RFC 2616 section * 3.6. Also multipart data is available as <code>Part</code> objects * however the raw content of the multipart body is still available. * * @exception Exception signifies that there is an I/O problem * * @return returns the input stream containing the message body */ public InputStream getInputStream() throws IOException { return request.getInputStream(); }
@Override public InputStream getInputStream() throws IOException { try { return baseRequest.getInputStream(); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override public InputStream getContentStream() throws IOException { /* maybe we could do this buffering only in dev mode? It is used to be able to read data again in case of json processing error. */ if (bufferedInputStream == null) { bufferedInputStream = new BufferedInputStream(request.getInputStream()) { @Override public void close() throws IOException { // NO OP, see #closeContentStream } }; bufferedInputStream.mark(10 * 1024); } return bufferedInputStream; }
@Override public InputStream getContentStream() throws IOException { /* maybe we could do this buffering only in dev mode? It is used to be able to read data again in case of json processing error. */ if (bufferedInputStream == null) { bufferedInputStream = new BufferedInputStream(request.getInputStream()) { @Override public void close() throws IOException { // NO OP, see #closeContentStream } }; bufferedInputStream.mark(10 * 1024); } return bufferedInputStream; }
public byte[] getBody() { try { return RequestUtils.readBody(request.getInputStream()); } catch (IOException e) { throw new RuntimeException("error getting body", e); } }
public void handle(Request request, Response response) { WebApplication target = application; final URI baseUri = getBaseUri(request); final URI requestUri = baseUri.resolve(request.getTarget()); try { final ContainerRequest cRequest = new ContainerRequest( target, request.getMethod(), baseUri, requestUri, getHeaders(request), request.getInputStream()); target.handleRequest(cRequest, new Writer(request, response)); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(response); } }
public static FullHttpRequest convert(final Request request) { byte[] data = null; try { final InputStream inputStream = request.getInputStream(); try { data = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } } catch (final IOException e) { LOGGER.error("IOException when getting request content.", e); } final FullHttpRequestImpl httpRequest = new FullHttpRequestImpl(); httpRequest.domain(request.getAddress().getDomain()); httpRequest.port(request.getAddress().getPort()); httpRequest.method(Method.valueOf(request.getMethod())); httpRequest.path(request.getPath().getPath()); if (data.length > 0) { httpRequest.content(data); } for (final String headerField : request.getNames()) { for (final String headerFieldValue : request.getValues(headerField)) { httpRequest.httpMessageHeader(headerField, headerFieldValue); } } for (final Entry<String, String> entry : request.getQuery().entrySet()) { httpRequest.queryParameter(entry.getKey(), entry.getValue()); } return httpRequest; }
public void handle( Request req, Response resp ) { try { PrintStream out = resp.getPrintStream(1024); String address = req.getAddress().toString(); if( address.equals(DEFAULT_ENPOINT) ) { String content = readInputStreamAsString(req.getInputStream()); JaxbCommandsRequest cmdsReq = (JaxbCommandsRequest) jaxbSerializationProvider.deserialize(content); String [] headerNames = { TEST_HEADER_NAME, ANOTHER_TEST_HEADER_NAME, NOT_SENT_HEADER_NAME }; List<String> headerValues = new ArrayList<String>(); for( String headerName : headerNames ) { String headerVal = req.getValue(headerName); if( headerVal != null ) { headerValues.add(headerVal); } } String output = handleJaxbCommandsRequest(cmdsReq, headerValues); resp.setCode(HttpURLConnection.HTTP_OK); out.print(output); } else { resp.setCode(HttpURLConnection.HTTP_BAD_REQUEST); } out.close(); } catch( Exception e ) { e.printStackTrace(); } }
req.getInputStream().close(); req.getChannel().close(); } catch( IOException e ) {
@Override public void handle(final Request request, final Response response) { final ResponseWriter responseWriter = new ResponseWriter(response, scheduler); final URI baseUri = getBaseUri(request); final URI requestUri = getRequestUri(request, baseUri); try { final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod(), getSecurityContext(request), new MapPropertiesDelegate()); requestContext.setEntityStream(request.getInputStream()); for (final String headerName : request.getNames()) { requestContext.headers(headerName, request.getValue(headerName)); } requestContext.setWriter(responseWriter); requestContext.setRequestScopedInitializer(injectionManager -> { injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request); injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response); }); appHandler.handle(requestContext); } catch (final Exception ex) { throw new RuntimeException(ex); } finally { if (!responseWriter.isSuspended()) { close(response); } } }