protected HttpEntity createEntity(String ct, byte[] byteArray) { final ByteArrayEntity byteArrayEntity = new ByteArrayEntity(byteArray); byteArrayEntity.setContentType(ct); return byteArrayEntity; }
/** * Set the given serialized remote invocation as request body. * <p>The default implementation simply sets the serialized invocation as the * HttpPost's request body. This can be overridden, for example, to write a * specific encoding and to potentially set appropriate HTTP request headers. * @param config the HTTP invoker configuration that specifies the target service * @param httpPost the HttpPost to set the request body on * @param baos the ByteArrayOutputStream that contains the serialized * RemoteInvocation object * @throws java.io.IOException if thrown by I/O methods */ protected void setRequestBody( HttpInvokerClientConfiguration config, HttpPost httpPost, ByteArrayOutputStream baos) throws IOException { ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray()); entity.setContentType(getContentType()); httpPost.setEntity(entity); }
/** * Set the given serialized remote invocation as request body. * <p>The default implementation simply sets the serialized invocation as the * HttpPost's request body. This can be overridden, for example, to write a * specific encoding and to potentially set appropriate HTTP request headers. * @param config the HTTP invoker configuration that specifies the target service * @param httpPost the HttpPost to set the request body on * @param baos the ByteArrayOutputStream that contains the serialized * RemoteInvocation object * @throws java.io.IOException if thrown by I/O methods */ protected void setRequestBody( HttpInvokerClientConfiguration config, HttpPost httpPost, ByteArrayOutputStream baos) throws IOException { ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray()); entity.setContentType(getContentType()); httpPost.setEntity(entity); }
private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) { if (request.getRequestBody() != null) { ByteArrayEntity entity = new ByteArrayEntity(request.getRequestBody().getBody()); entity.setContentType(request.getRequestBody().getContentType()); requestBuilder.setEntity(entity); } return requestBuilder; }
@Override protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception { HttpPost postMethod = new HttpPost(config.getServiceUrl()); ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray()); entity.setContentType(getContentType()); postMethod.setEntity(entity); BasicHttpContext context = null; if (environment.useSslContext()) { context = new BasicHttpContext(); context.setAttribute(HttpClientContext.USER_TOKEN, goAgentServerHttpClient.principal()); } try (CloseableHttpResponse response = goAgentServerHttpClient.execute(postMethod, context)) { validateResponse(response); InputStream responseBody = getResponseBody(response); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } }
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
protected HttpEntity createEntity(String ct, byte[] byteArray) { final ByteArrayEntity byteArrayEntity = new ByteArrayEntity(byteArray); byteArrayEntity.setContentType(ct); return byteArrayEntity; }
private static HttpUriRequest buildHttpRequest(ClientInvocation request) { // Writers may change headers. Thus buffer the content before committing the headers. // For simplicity's sake the content is buffered in memory. File-buffering (ZeroCopyConsumer...) would be // possible, but resource management is error-prone. HttpRequestBase httpRequest = createHttpMethod(request.getUri(), request.getMethod()); if (request.getEntity() != null) { byte[] requestContent = requestContent(request); ByteArrayEntity entity = new ByteArrayEntity(requestContent); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString())); commitHeaders(request, httpRequest); ((HttpEntityEnclosingRequest) httpRequest).setEntity(entity); } else { commitHeaders(request, httpRequest); } return httpRequest; }
.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString())); entityToBuild = entityToBuildByteArray;
protected static ByteArrayEntity getBytesEntity( byte[] content, String contentType) { if (content == null) { return null; } ByteArrayEntity entity = new ByteArrayEntity(content); if (contentType != null) { entity.setContentType(contentType); } return entity; }
String serveURL = "http://192.168.56.101/testforms/" + data.getString(PARENT_UUID) + "/" + imgUuid; if (docRev != null && !docRev.trim().isEmpty()) { //This is dumb... serveURL += "?rev=" + docRev + "&_rev=" + docRev; } HttpPut post = new HttpPut(serveURL); ByteArrayEntity entity = new ByteArrayEntity(imageData); entity.setContentType(data.getString(MIME_TYPE));; post.setEntity(entity); HttpResponse formServResp = httpClient.execute(post);
try { HttpPost post = new HttpPost(serverURL + path); // post.setHeader("Accept", "application/json"); // post.setHeader("Content-type", "application/json"); ByteArrayEntity content = new ByteArrayEntity(s.getBytes("UTF-8")); content.setContentType("application/json"); post.setEntity(content); client.execute(post); }
private void addEntity ( HttpEntityEnclosingRequestBase req, String contentType, byte[] o ) { final ByteArrayEntity input = new ByteArrayEntity ( o ); input.setContentType ( contentType ); req.addHeader ( "Content-Type", contentType ); req.setEntity ( input ); }
DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); ByteArrayEntity byteArrayEntity = new ByteArrayEntity(dataToPost.getBytes()); byteArrayEntity.setContentEncoding("UTF-8"); byteArrayEntity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpPost.setEntity(byteArrayEntity); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); return streamToString(httpEntity.getContent());
ByteArrayOutputStream bArrOS = new ByteArrayOutputStream(); // reqEntity is the MultipartEntity instance reqEntity.writeTo(bArrOS); bArrOS.flush(); ByteArrayEntity bArrEntity = new ByteArrayEntity(bArrOS.toByteArray()); bArrOS.close(); bArrEntity.setChunked(true); bArrEntity.setContentEncoding(reqEntity.getContentEncoding()); bArrEntity.setContentType(reqEntity.getContentType()); // Set ByteArrayEntity to HttpPost post.setEntity(bArrEntity);
public void receiveResponseEntity(HttpResponse response) throws HttpException, IOException { if (this.response == null) { throw new IOException("receiveResponseEntity() called on closed connection"); } ByteArrayEntity bae = new ByteArrayEntity(this.response.getContent()); bae.setContentType(response.getFirstHeader("Content-Type")); response.setEntity(bae); response = null; }
public void receiveResponseEntity(HttpResponse response) throws HttpException, IOException { if (this.response == null) { throw new IOException("receiveResponseEntity() called on closed connection"); } ByteArrayEntity bae = new ByteArrayEntity(this.response.getContent()); bae.setContentType(response.getFirstHeader("Content-Type")); response.setEntity(bae); response = null; }
@Override public void applyTo(ServerDriverHttpUriRequest request) { HttpUriRequest internalRequest = request.getHttpUriRequest(); if (!(internalRequest instanceof HttpEntityEnclosingRequest)) { return; } HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) internalRequest; entityRequest.setHeader("Content-type", contentType); ByteArrayEntity entity = new ByteArrayEntity(content); entity.setContentType(contentType); entityRequest.setEntity(entity); }
@Override public void applyTo(ServerDriverHttpUriRequest request) { HttpUriRequest internalRequest = request.getHttpUriRequest(); if (!(internalRequest instanceof HttpEntityEnclosingRequest)) { return; } HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) internalRequest; entityRequest.setHeader("Content-type", contentType); ByteArrayEntity entity = new ByteArrayEntity(content); entity.setContentType(contentType); entityRequest.setEntity(entity); }
private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) { if (request.getRequestBody() != null) { ByteArrayEntity entity = new ByteArrayEntity(request.getRequestBody().getBody()); entity.setContentType(request.getRequestBody().getContentType()); requestBuilder.setEntity(entity); } return requestBuilder; }