private static byte[] requestContent(ClientInvocation request) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); request.getDelegatingOutputStream().setDelegate(baos); try { request.writeRequestBody(request.getEntityStream()); baos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
request.writeRequestBody(request.getEntityStream()); baos.close(); commitHeaders(request, connection);
/** * Creates the request OutputStream, to be sent to the end Service invoked, as a * <a href="http://commons.apache.org/io/api-release/org/apache/commons/io/output/DeferredFileOutputStream.html" * >DeferredFileOutputStream</a>. * * * @param request - * @return - DeferredFileOutputStream with the ClientRequest written out per HTTP specification. * @throws IOException - */ private DeferredFileOutputStream writeRequestBodyToOutputStream(final ClientInvocation request) throws IOException { DeferredFileOutputStream memoryManagedOutStream = new DeferredFileOutputStream( this.fileUploadInMemoryThresholdLimit * getMemoryUnitMultiplier(), getTempfilePrefix(), ".tmp", this.fileUploadTempFileDir); request.getDelegatingOutputStream().setDelegate(memoryManagedOutStream); request.writeRequestBody(request.getEntityStream()); memoryManagedOutStream.close(); return memoryManagedOutStream; }
final ByteArrayOutputStream os = new ByteArrayOutputStream(); try { invocation.writeRequestBody(os); } catch (IOException e) { future.completeExceptionally(e);
private static byte[] requestContent(ClientInvocation request) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); request.getDelegatingOutputStream().setDelegate(baos); try { request.writeRequestBody(request.getEntityStream()); baos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
private static byte[] requestContent(ClientInvocation request) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); request.getDelegatingOutputStream().setDelegate(baos); try { request.writeRequestBody(request.getEntityStream()); baos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
protected void executeRequest(ClientInvocation request, HttpURLConnection connection) { connection.setInstanceFollowRedirects(request.getMethod().equals("GET")); if (request.getEntity() != null) { if (request.getMethod().equals("GET")) { throw new ProcessingException(Messages.MESSAGES.getRequestCannotHaveBody()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); request.getDelegatingOutputStream().setDelegate(baos); try { request.writeRequestBody(request.getEntityStream()); baos.close(); this.commitHeaders(request, connection); connection.setDoOutput(true); OutputStream e = connection.getOutputStream(); e.write(baos.toByteArray()); e.flush(); e.close(); } catch (IOException ex) { throw new RuntimeException(ex); } } else { this.commitHeaders(request, connection); } }
protected void executeRequest(ClientInvocation request, HttpURLConnection connection) { connection.setInstanceFollowRedirects(request.getMethod().equals("GET")); if (request.getEntity() != null) { if (request.getMethod().equals("GET")) { throw new ProcessingException(Messages.MESSAGES.getRequestCannotHaveBody()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); request.getDelegatingOutputStream().setDelegate(baos); try { request.writeRequestBody(request.getEntityStream()); baos.close(); this.commitHeaders(request, connection); connection.setDoOutput(true); OutputStream e = connection.getOutputStream(); e.write(baos.toByteArray()); e.flush(); e.close(); } catch (IOException ex) { throw new RuntimeException(ex); } } else { this.commitHeaders(request, connection); } }
private RequestBody createRequestBody(final ClientInvocation request) { if (request.getEntity() == null) { return null; } // NOTE: this will invoke WriterInterceptors which can possibly change the request, // so it must be done first, before reading any header. final Buffer buffer = new Buffer(); try { request.writeRequestBody(buffer.outputStream()); } catch (IOException e) { throw new RuntimeException(e); } javax.ws.rs.core.MediaType mediaType = request.getHeaders().getMediaType(); final MediaType contentType = (mediaType == null) ? null : MediaType.parse(mediaType.toString()); return new RequestBody() { @Override public long contentLength() throws IOException { return buffer.size(); } @Override public MediaType contentType() { return contentType; } @Override public void writeTo(BufferedSink sink) throws IOException { buffer.copyTo(sink.buffer(), 0, buffer.size()); } }; }
request.writeRequestBody(request.getEntityStream()); baos.close(); commitHeaders(request, connection);
request.writeRequestBody(request.getEntityStream()); baos.close(); commitHeaders(request, connection);
/** * Creates the request OutputStream, to be sent to the end Service invoked, as a * <a href="http://commons.apache.org/io/api-release/org/apache/commons/io/output/DeferredFileOutputStream.html" * >DeferredFileOutputStream</a>. * * * @param request - * @return - DeferredFileOutputStream with the ClientRequest written out per HTTP specification. * @throws IOException - */ private DeferredFileOutputStream writeRequestBodyToOutputStream(final ClientInvocation request) throws IOException { DeferredFileOutputStream memoryManagedOutStream = new DeferredFileOutputStream(this.fileUploadInMemoryThresholdLimit * getMemoryUnitMultiplier(), getTempfilePrefix(), ".tmp", this.fileUploadTempFileDir); request.getDelegatingOutputStream().setDelegate(memoryManagedOutStream); request.writeRequestBody(request.getEntityStream()); memoryManagedOutStream.close(); return memoryManagedOutStream; }
/** * Creates the request OutputStream, to be sent to the end Service invoked, as a * <a href="http://commons.apache.org/io/api-release/org/apache/commons/io/output/DeferredFileOutputStream.html" * >DeferredFileOutputStream</a>. * * * @param request - * @return - DeferredFileOutputStream with the ClientRequest written out per HTTP specification. * @throws IOException - */ private DeferredFileOutputStream writeRequestBodyToOutputStream(final ClientInvocation request) throws IOException { DeferredFileOutputStream memoryManagedOutStream = new DeferredFileOutputStream(this.fileUploadInMemoryThresholdLimit * getMemoryUnitMultiplier(), getTempfilePrefix(), ".tmp", this.fileUploadTempFileDir); request.getDelegatingOutputStream().setDelegate(memoryManagedOutStream); request.writeRequestBody(request.getEntityStream()); memoryManagedOutStream.close(); return memoryManagedOutStream; }