this.requestEntity = new ByteArrayRequestEntity(requestBody); } else if (this.requestStream != null) { this.requestEntity = new InputStreamRequestEntity(
logger.debug("Payload (byte array): " + re.getContent().toString());
logger.debug("Payload (byte array): " + re.getContent().toString());
/** * Generates a request entity from the post parameters, if present. Calls * {@link EntityEnclosingMethod#generateRequestBody()} if parameters have not been set. * * @since 3.0 */ protected RequestEntity generateRequestEntity() { if (!this.params.isEmpty()) { // Use a ByteArrayRequestEntity instead of a StringRequestEntity. // This is to avoid potential encoding issues. Form url encoded strings // are ASCII by definition but the content type may not be. Treating the content // as bytes allows us to keep the current charset without worrying about how // this charset will effect the encoding of the form url encoded string. String content = EncodingUtil.formUrlEncode(getParameters(), getRequestCharSet()); ByteArrayRequestEntity entity = new ByteArrayRequestEntity( EncodingUtil.getAsciiBytes(content), FORM_URL_ENCODED_CONTENT_TYPE ); return entity; } else { return super.generateRequestEntity(); } }
entity.writeTo(os); os.flush(); requestEntity = new ByteArrayRequestEntity(os.toByteArray(), entity.getContentType().toString()); os.close();
public void setRequestBody(byte[] body) { requestBody = new ByteArrayRequestEntity(body); } public void setRequestBody(InputStream body)
public void setRequestBody(byte[] body) { requestBody = new ByteArrayRequestEntity(body); } public void setRequestBody(InputStream body)
public InvocationResult invoke( byte[] request, WiseMapper mapper ) { return invoke(new ByteArrayRequestEntity(request), mapper); }
public void createVersion(String owner, String repository, String packageName, String versionName){ String url = String.format("https://api.bintray.com/packages/%s/%s/%s/versions", owner, repository, packageName); PostMethod post = new PostMethod(url); assertAuthorized(); post.addRequestHeader("Authorization", "Basic "+ new String(Base64.encodeBase64((username+":"+password).getBytes()))); post.setRequestEntity(new ByteArrayRequestEntity(("{\"name\":\""+versionName+"\"}").getBytes(), "application/json")); try{ new HttpClient().executeMethod(post); validateAuthorizedRequestResult(owner, post, 201); } catch (Exception e) { throw new RuntimeException("Failed to create version in package: "+packageName, e); } }
public void publishVersion(String owner, String repository, String packageName, String versionName){ String url = String.format("https://api.bintray.com/content/%s/%s/%s/%s/publish", owner, repository, packageName, versionName); PostMethod post = new PostMethod(url); assertAuthorized(); post.addRequestHeader("Authorization", "Basic "+ new String(Base64.encodeBase64((username+":"+password).getBytes()))); post.setRequestEntity(new ByteArrayRequestEntity(("{\"publish-wait-for-secs\":\"-1\"}").getBytes(), "application/json")); try{ new HttpClient().executeMethod(post); validateAuthorizedRequestResult(owner, post, 200); } catch (Exception e) { throw new RuntimeException("Failed to publish version "+versionName+" in package: "+packageName, e); } } }
@Override protected void onSendAfterWrite(WebServiceMessage message) throws IOException { postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray())); requestBuffer = null; try { httpClient.executeMethod(postMethod); } catch (IllegalStateException ex) { if ("Connection factory has been shutdown.".equals(ex.getMessage())) { // The application context has been closed, resulting in a connection factory shutdown and an ISE. // Let's create a new connection factory for this connection only. connectionManager = new MultiThreadedHttpConnectionManager(); httpClient.setHttpConnectionManager(connectionManager); httpClient.executeMethod(postMethod); } else { throw ex; } } }
@Override protected void onSendAfterWrite(WebServiceMessage message) throws IOException { postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray())); requestBuffer = null; try { httpClient.executeMethod(postMethod); } catch (IllegalStateException ex) { if ("Connection factory has been shutdown.".equals(ex.getMessage())) { // The application context has been closed, resulting in a connection factory shutdown and an ISE. // Let's create a new connection factory for this connection only. connectionManager = new MultiThreadedHttpConnectionManager(); httpClient.setHttpConnectionManager(connectionManager); httpClient.executeMethod(postMethod); } else { throw ex; } } }
@Override protected void onSendAfterWrite(WebServiceMessage message) throws IOException { postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray())); requestBuffer = null; try { httpClient.executeMethod(postMethod); } catch (IllegalStateException ex) { if ("Connection factory has been shutdown.".equals(ex.getMessage())) { // The application context has been closed, resulting in a connection factory shutdown and an ISE. // Let's create a new connection factory for this connection only. connectionManager = new MultiThreadedHttpConnectionManager(); httpClient.setHttpConnectionManager(connectionManager); httpClient.executeMethod(postMethod); } else { throw ex; } } }
@Override protected void onSendAfterWrite(WebServiceMessage message) throws IOException { postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray())); requestBuffer = null; try { httpClient.executeMethod(postMethod); } catch (IllegalStateException ex) { if ("Connection factory has been shutdown.".equals(ex.getMessage())) { // The application context has been closed, resulting in a connection factory shutdown and an ISE. // Let's create a new connection factory for this connection only. connectionManager = new MultiThreadedHttpConnectionManager(); httpClient.setHttpConnectionManager(connectionManager); httpClient.executeMethod(postMethod); } else { throw ex; } } }
protected static void handleRequestData(EntityEnclosingMethod method, Object data) { if (method == null) { throw new IllegalArgumentException("Invalid method, cannot be null"); } if (data != null) { RequestEntity re = null; if (data.getClass().isAssignableFrom(InputStream.class)) { re = new InputStreamRequestEntity((InputStream) data, CONTENT_TYPE_UTF8); } else if (data.getClass().isAssignableFrom(byte[].class)) { re = new ByteArrayRequestEntity((byte[]) data, CONTENT_TYPE_UTF8); } else if (data.getClass().isAssignableFrom(File.class)) { re = new FileRequestEntity((File) data, CONTENT_TYPE_UTF8); } else { // handle as a string try { re = new StringRequestEntity(data.toString(), "text/xml", ENCODING_UTF8); } catch (UnsupportedEncodingException e) { throw new HttpIOException("Encoding data using UTF8 failed :: " + e.getMessage(), e); } } method.setRequestEntity(re); } }
public void commitRequest() throws IOException { checkNotCommitted(); committed = true; method.setRequestEntity(new ByteArrayRequestEntity(funnel.toByteArray())); funnel = null; try { os.close(); } catch (IOException e) { // ignore } os = null; httpClient.executeMethod(method); checkStatusCode(method); is = method.getResponseBodyAsStream(); }
/** * This executes a POST Request to a WSS, the pPostXML Parameter can be created through a createPostXML Method * @param version * @param pPostXML * @return * @throws ServiceException * @throws ClientException */ public Transferable doService(String version, String pPostXML, String pAdditionalPathInfo, String pAddionalQueryString) throws ServiceException, ClientException { pAdditionalPathInfo = (pAdditionalPathInfo == null) ? "":pAdditionalPathInfo; pAddionalQueryString = (pAddionalQueryString == null) ? "":pAddionalQueryString; PostMethod lMethod = new PostMethod( new StringBuffer().append(getWssURLString()).append(pAdditionalPathInfo).append( '?').append(pAddionalQueryString).toString()); lMethod.setRequestHeader("Content-Type","text/xml;charset=UTF-8"); lMethod.setRequestHeader("Content-Encoding","UTF-8"); try { lMethod.setRequestEntity(new ByteArrayRequestEntity(pPostXML.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 not supported. This is very unlikely"); } return execute(lMethod); } /**
request.addRequestHeader("Content-Type", "application/json"); String query = String.format("{\"sql\":\"select count(*) from %s\",\"offset\":0,\"limit\":50000,\"acceptPartial\":true,\"project\":\"%s\"}", tableName, projectName); request.setRequestEntity(new ByteArrayRequestEntity(query.getBytes()));
@Override public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] output) throws IOException { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); for (String headerValue : entry.getValue()) { httpMethod.addRequestHeader(headerName, headerValue); } } if (this.httpMethod instanceof EntityEnclosingMethod) { EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) this.httpMethod; RequestEntity requestEntity = new ByteArrayRequestEntity(output); entityEnclosingMethod.setRequestEntity(requestEntity); } this.httpClient.executeMethod(this.httpMethod); return new CommonsClientHttpResponse(this.httpMethod); }
protected RequestEntity writeMessage(SoapWriter writer) throws Exception { if (getConfiguration().isStreamingEnabled()) { return new StreamingRequestEntity(writer); } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(baos); return new ByteArrayRequestEntity(baos.toByteArray(), writer.getContentType()); } }