List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestEntity
public void setRequestEntity(RequestEntity paramRequestEntity)
From source file:com.cloud.ucs.manager.UcsHttpClient.java
public String call(String xml) { PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(xml)); post.setRequestHeader("Content-type", "text/xml"); //post.setFollowRedirects(true); try {// ww w.j av a2s.c om int result = client.executeMethod(post); if (result == 302) { // Handle HTTPS redirect // Ideal way might be to configure from add manager API // for using either HTTP / HTTPS // Allow only one level of redirect String redirectLocation; Header locationHeader = post.getResponseHeader("location"); if (locationHeader != null) { redirectLocation = locationHeader.getValue(); } else { throw new CloudRuntimeException("Call failed: Bad redirect from UCS Manager"); } post.setURI(new URI(redirectLocation)); result = client.executeMethod(post); } // Check for errors if (result != 200) { throw new CloudRuntimeException("Call failed: " + post.getResponseBodyAsString()); } String res = post.getResponseBodyAsString(); if (res.contains("errorCode")) { String err = String.format("ucs call failed:\nsubmitted doc:%s\nresponse:%s\n", xml, res); throw new CloudRuntimeException(err); } return res; } catch (Exception e) { throw new CloudRuntimeException(e.getMessage(), e); } finally { post.releaseConnection(); } }
From source file:com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptorIntegrationTest.java
private PostMethod getPostMethod() { PostMethod post = new PostMethod("http://localhost:3006/blz-service?wsdl"); post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, ""); return post;//from w w w . j a va 2 s.co m }
From source file:info.jtrac.mylyn.JtracClient.java
private String doPost(String url, String message) throws Exception { PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(message, "text/xml", "UTF-8")); String response = null;// w ww.j a v a 2 s .co m int code; try { code = httpClient.executeMethod(post); if (code != HttpURLConnection.HTTP_OK) { throw new HttpException("HTTP Response Code: " + code); } response = post.getResponseBodyAsString(); } finally { post.releaseConnection(); } return response; }
From source file:com.nfl.dm.clubsites.cms.articles.categorization.OpenCalaisRESTPost.java
private Map<String, ArrayList<String>> postString(String input, PostMethod method) throws IOException { method.setRequestEntity(new StringRequestEntity(input, null, null)); return doRequest(input, method); }
From source file:com.predic8.membrane.core.interceptor.rewrite.SimpleURLRewriteInterceptorIntegrationTest.java
private PostMethod getPostMethod() { PostMethod post = new PostMethod("http://localhost:8000/blz-service?wsdl"); post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); post.setRequestHeader(Header.CONTENT_TYPE, "text/xml;charset=UTF-8"); post.setRequestHeader(Header.SOAP_ACTION, ""); return post;// ww w . ja va2s.c o m }
From source file:edu.stanford.epad.plugins.qifpwrapper.QIFPHandler.java
public static String sendRequest(String url, String epadSessionID, File dicomsZip, File dsosZip, String statusURL) throws Exception { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(url); if (epadSessionID != null) postMethod.setRequestHeader("Cookie", "JSESSIONID=" + epadSessionID); try {//from w ww.j a v a2s .com Part[] parts = { new FilePart("dicoms", dicomsZip), new FilePart("dsos", dsosZip), new StringPart("statusUrl", statusURL) }; postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams())); int response = client.executeMethod(postMethod); String responseStr = postMethod.getResponseBodyAsString(); JSONObject responseJson = new JSONObject(responseStr); String instanceId = (String) responseJson.get("workflowInstanceID"); if (response == HttpServletResponse.SC_OK) ; return instanceId; } catch (Exception e) { log.warning("Exception calling ePAD", e); return null; } finally { postMethod.releaseConnection(); } }
From source file:fi.solita.phantomrunner.browserserver.HttpPhantomJsServerNotifier.java
private JsonNode send(Map<String, Object> jsonMap) { try {/*from w w w . j av a2 s . c o m*/ // FIXME: should relly get this port from the JUnit configs but have no real way to pass this // to JavaScript side of things yet, bummer PostMethod method = new PostMethod("http://localhost:18080"); method.setRequestEntity( new StringRequestEntity(mapper.writeValueAsString(jsonMap), "application/json", "UTF-8")); int responseCode = client.executeMethod(method); switch (responseCode) { case HttpServletResponse.SC_INTERNAL_SERVER_ERROR: throw new RuntimeException("Internal server error occured: " + method.getResponseBodyAsString()); default: return mapper.readTree(method.getResponseBodyAsString()); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:colt.nicity.performance.latent.http.ApacheHttpClient.java
public HttpResponse postJson(String path, String postJsonBody) { try {//from w w w.j a v a 2 s . co m PostMethod post = new PostMethod(path); post.setRequestEntity(new StringRequestEntity(postJsonBody, APPLICATION_JSON_CONTENT_TYPE, "UTF-8")); post.setRequestHeader(CONTENT_TYPE_HEADER_NAME, APPLICATION_JSON_CONTENT_TYPE); return execute(post); } catch (Exception e) { String trimmedPostBody = (postJsonBody.length() > JSON_POST_LOG_LENGTH_LIMIT) ? postJsonBody.substring(0, JSON_POST_LOG_LENGTH_LIMIT) : postJsonBody; throw new RuntimeException( "Error executing POST request to: " + client.getHostConfiguration().getHostURL() + " path: " + path + " JSON body: " + trimmedPostBody, e); } }
From source file:at.ac.tuwien.auto.sewoa.http.HttpRetrieverImpl.java
public byte[] postData(String url, String data) { byte[] result = new byte[] {}; HttpClient httpClient = httpClientFactory.createClient(); PostMethod postMethod = new PostMethod(url); postMethod.setRequestEntity(new StringRequestEntity(data)); HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams(); params.setConnectionTimeout((int) TimeUnit.SECONDS.toMillis(CONNECTION_TO)); params.setSoTimeout((int) TimeUnit.SECONDS.toMillis(SOCKET_TO)); postMethod.addRequestHeader("Content-Type", "application/xml"); postMethod.addRequestHeader("Accept", "application/xml"); try {/*from ww w .j av a2 s . co m*/ result = send(httpClient, postMethod); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:com.predic8.membrane.core.transport.http.ServiceInvocationTest.java
private PostMethod createPostMethod() { PostMethod post = new PostMethod("http://localhost:3016/axis2/services/BLZService?wsdl"); post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, ""); return post;//from w ww . j a va 2 s . co m }