List of usage examples for org.apache.commons.httpclient.methods StringRequestEntity StringRequestEntity
public StringRequestEntity(String paramString1, String paramString2, String paramString3) throws UnsupportedEncodingException
From source file:com.zimbra.qa.unittest.TestSoapHarvest.java
private String sendReq(String userId, String authToken, int expectedCode, boolean useGetInfoReq, boolean byAccountId) throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod method = new PostMethod( TestUtil.getSoapUrl() + (useGetInfoReq ? "GetInfoRequest" : "NoOpRequest")); method.setRequestEntity(/*from w w w.j av a 2 s . c om*/ new StringRequestEntity(useGetInfoReq ? getInfoRequest(userId, authToken, byAccountId) : getNoOpRequest(userId, authToken, byAccountId), "application/soap+xml", "UTF-8")); int respCode = HttpClientUtil.executeMethod(client, method); Assert.assertEquals(expectedCode, respCode); return method.getResponseBodyAsString(); }
From source file:com.calclab.emite.j2se.services.HttpConnector.java
private Runnable createSendAction(final String httpBase, final String xml, final ConnectorCallback callback) { return new Runnable() { public void run() { final String id = HttpConnectorID.getNext(); Logger.debug("Connector [{0}] send: {1}", id, xml); final HttpClientParams params = new HttpClientParams(); params.setConnectionManagerTimeout(10000); final HttpClient client = new HttpClient(params); int status = 0; String response = null; final PostMethod post = new PostMethod(httpBase); try { post.setRequestEntity(new StringRequestEntity(xml, "text/xml", "utf-8")); System.out.println("SENDING: " + xml); status = client.executeMethod(post); response = post.getResponseBodyAsString(); } catch (final Exception e) { callback.onError(xml, e); e.printStackTrace();//from ww w. j ava2 s . c o m } finally { post.releaseConnection(); } receiveService.execute(createResponseAction(xml, callback, id, status, response)); } }; }
From source file:com.mobilefirst.fiberlink.Authenticator.java
/** * Description: Create initial post method * @param xml: the xml body payload/*from w w w . j a v a 2 s . c o m*/ * @param url_auth: URL to post * @param billing_id: the unique billing ID for the Fiberlink Customer * @return: PostMethod */ public void createAndSendRequest(String xml, String url_auth, String billing_id) { PostMethod post = new PostMethod(url_auth + billing_id + "/"); try { RequestEntity requestEntity = new StringRequestEntity(xml, "application/xml", "UTF-8"); post.setRequestEntity(requestEntity); post.addRequestHeader("Accept", "application/xml"); } catch (Exception e) { e.printStackTrace(); } sendRequest(post); }
From source file:com.atlassian.jira.web.action.setup.SetupProductBundleHelper.java
public boolean saveLicense() { int status = 0; final String licenseUrl; final String licenseKey = sharedVariables.getBundleLicenseKey(); if (licenseKey == null) { sharedVariables.setBundleHasLicenseError(true); return false; }/*from w w w . j a v a 2s. c o m*/ try { licenseUrl = getLicenseUrl(); } catch (final IllegalStateException e) { sharedVariables.setBundleHasLicenseError(true); return false; } final HttpClient httpClient = prepareClient(); final PutMethod method = new PutMethod(licenseUrl); try { final StringRequestEntity requestEntity = new StringRequestEntity( prepareJSON(ImmutableMap.of("rawLicense", licenseKey)), "application/vnd.atl.plugins+json", "UTF-8"); method.setRequestEntity(requestEntity); status = httpClient.executeMethod(method); } catch (final IOException e) { log.warn("Problem with saving licence during product bundle license installation", e); } finally { method.releaseConnection(); } if (status != 200) { log.warn("Problem with saving licence during product bundle license installation, status code: " + status); sharedVariables.setBundleHasLicenseError(true); return false; } return true; }
From source file:com.kagilum.plugins.icescrum.IceScrumSession.java
public boolean sendBuildStatut(JSONObject build) throws UnsupportedEncodingException { PostMethod method = new PostMethod(settings.getUrl() + "/ws/p/" + settings.getPkey() + "/build"); StringRequestEntity requestEntity = new StringRequestEntity(build.toString(), "application/json", "UTF-8"); method.setRequestEntity(requestEntity); return executeMethod(method, HttpStatus.SC_CREATED); }
From source file:dk.dma.epd.common.prototype.shoreservice.RouteHttp.java
public void setRequestBody(String route) { try {// w w w. j av a 2 s. c om method.setRequestEntity(new StringRequestEntity(route, null, null)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java
/** * Performs a POST method against the API * @param url -> This URL is going to be converted to API_URL:BONFIRE_PORT/url * @param payload message sent in the post method * @return Response object encapsulation all the HTTP information, it returns <code>null</code> if there was an error. *//* w w w . ja va2 s. c om*/ public static Response executePutMethod(String url, String payload, String username, String password) { Response response = null; try { PutMethod put = new PutMethod(url); // We define the request entity RequestEntity requestEntity = new StringRequestEntity(payload, BONFIRE_XML, null); put.setRequestEntity(requestEntity); response = executeMethod(put, BONFIRE_XML, username, password, url); } catch (UnsupportedEncodingException exception) { System.out.println("THE PAYLOAD ENCODING IS NOT SUPPORTED"); System.out.println("ERROR: " + exception.getMessage()); System.out.println("ERROR: " + exception.getStackTrace()); } return response; }
From source file:eu.crowdrec.contest.sender.RequestSenderORP.java
/** * Send a line from a logFile to an HTTP server. * /*from ww w. j av a 2s . co m*/ * @param logline the line that should by sent * * @param connection the connection to the http server, must not be null * * @return the response or null (if an error has been detected) */ static private String excutePostWithHttpClient(final String type, final String body, final String serverURL) { // define the URL parameter String urlParameters = ""; try { urlParameters = String.format("type=%s&body=%s", URLEncoder.encode(type, "UTF-8"), URLEncoder.encode(body, "UTF-8")); } catch (UnsupportedEncodingException e1) { logger.warn(e1.toString()); } PostMethod postMethod = null; try { StringRequestEntity requestEntity = new StringRequestEntity(urlParameters, "application/x-www-form-urlencoded", "UTF-8"); postMethod = new PostMethod(serverURL); postMethod.setParameter("useCache", "false"); postMethod.setRequestEntity(requestEntity); int statusCode = httpClient.executeMethod(postMethod); String response = statusCode == 200 ? postMethod.getResponseBodyAsString() : "statusCode:" + statusCode; return response.trim(); } catch (IOException e) { logger.warn("receiving response failed, ignored."); } finally { if (postMethod != null) { postMethod.releaseConnection(); } } return null; }
From source file:com.honnix.yaacs.adapter.http.ACHttpClient.java
private PostMethod buildPostMethod(String url, String request) { StringBuilder sb = new StringBuilder("http://").append(host).append(':').append(port).append(url); PostMethod postMethod = new PostMethod(sb.toString()); sb = new StringBuilder(ACHttpConstant.HTTP_CONTENT_TYPE).append(" charset=").append(CHARSET); postMethod.setRequestHeader("Content-Type", sb.toString()); try {// ww w .ja v a 2s . co m StringRequestEntity requestEntity = new StringRequestEntity(request, null, CHARSET); postMethod.setRequestEntity(requestEntity); } catch (UnsupportedEncodingException e) { postMethod = null; } return postMethod; }
From source file:com.mycompany.neo4jprotein.neoStart.java
static public String createNode() { String output = null;/*from www. ja v a 2 s . c o m*/ String location = null; try { String nodePointUrl = SERVER_ROOT_URI + "/db/data/node/1"; HttpClient client = new HttpClient(); PostMethod mPost = new PostMethod(nodePointUrl); /** * set headers */ Header mtHeader = new Header(); mtHeader.setName("content-type"); mtHeader.setValue("application/json"); mtHeader.setName("accept"); mtHeader.setValue("application/json"); mPost.addRequestHeader(mtHeader); /** * set json payload */ StringRequestEntity requestEntity = new StringRequestEntity("{}", "application/json", "UTF-8"); mPost.setRequestEntity(requestEntity); int satus = client.executeMethod(mPost); output = mPost.getResponseBodyAsString(); Header locationHeader = mPost.getResponseHeader("location"); location = locationHeader.getValue(); mPost.releaseConnection(); System.out.println("satus : " + satus); System.out.println("location : " + location); System.out.println("output : " + output); } catch (Exception e) { System.out.println("Exception in creating node in neo4j : " + e); } return location; }