List of usage examples for org.apache.http.entity StringEntity StringEntity
public StringEntity(String str) throws UnsupportedEncodingException
From source file:DdaApiUtils.java
public static void queryNotifyDataAvailableEndpoint(String providerCode, String baseUrl) throws Exception { String url = (baseUrl + providerCode + "/data/notifyAvailable"); System.out.println("Request URL is: " + url); StringEntity jsonPacket = new StringEntity( "[{\"seqnum\": 123, \"url\": \"ftp://provider/export.zip\", \"type\": \"TITLE_DATA_FULL\" }]"); CloseableHttpResponse response = HttpUtils.processHttpPostRequest(url, jsonPacket); int serverResponse = HttpUtils.getResponseStatusCode(response); String reasonPhrase = HttpUtils.getReasonPhrase(response); System.out.println();/* ww w . j a v a 2s.c o m*/ if (serverResponse == 200) { System.out.println("Notify Data Available for provider " + providerCode + " was successful."); } else { System.out.println("Notify Data Available for provider " + providerCode + " was NOT successful."); System.out.println("Server response was: " + serverResponse); System.out.println("Server reason phrase was: " + reasonPhrase); } }
From source file:org.opentravel.otm.forum2016.am.CreateAPIOperation.java
/** * @see org.opentravel.otm.forum2016.am.RESTClientOperation#execute() *///from w ww .java 2 s. c om @Override public APIDetails execute() throws IOException { HttpPost request = new HttpPost(APIPublisherConfig.getWSO2PublisherApiBaseUrl()); request.setHeader("Content-Type", "application/json"); request.setEntity(new StringEntity(new Gson().toJson(api.toJson()))); return execute(request); }
From source file:eu.eexcess.partnerdata.evaluation.enrichment.PartnerRecommenderEvaluationTestHelper.java
static public StringEntity createParamsForPartnerRecommender(int records, ArrayList<String> keywords) { StringEntity params = null;//from w w w . j a v a2s .co m try { String userprofile = "<eexcess-secure-user-profile numResults=\"" + records + "\" firstName=\"Hugo\" lastName=\"Boss\" birthDate=\"2013-10-14T05:06:44.550+02:00\"> <contextKeywords> "; for (int i = 0; i < keywords.size(); i++) { userprofile += "<contextKeywords><text>" + keywords.get(i) + "</text></contextKeywords>"; } userprofile += " </contextKeywords></eexcess-secure-user-profile>"; params = new StringEntity(userprofile); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return params; }
From source file:com.automatski.autosim.rest.SampleRestConnection.java
@Override public Object send(Object arg0) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(config.url); StringEntity input = new StringEntity((String) arg0); input.setContentType("application/json"); postRequest.setEntity(input);//from ww w .j a va 2 s .c o m HttpResponse response = httpClient.execute(postRequest); response.getEntity().consumeContent(); // return nothing. we are as of now not interested in the response return null; }
From source file:com.google.developers.gdgfirenze.mockep.AndroidSimulator.java
private static void postData(String url, JSONObject jsonSamplePacket) throws ClientProtocolException, IOException { HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, 10000); HttpConnectionParams.setSoTimeout(myParams, 10000); HttpClient httpclient = new DefaultHttpClient(myParams); HttpPost httppost = new HttpPost(url.toString()); httppost.setHeader("Content-type", "application/json"); StringEntity se = new StringEntity(jsonSamplePacket.toString()); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se);// w w w . j a va 2s . c om HttpResponse response = httpclient.execute(httppost); String temp = EntityUtils.toString(response.getEntity()); System.out.println("JSON post response: " + temp); }
From source file:com.yanzhenjie.andserver.handler.BasicRequestHandler.java
/** * Send a 404 response./*from ww w . ja v a 2 s. c o m*/ * * @param response {@link HttpResponse}. * @param message message. * @throws HttpException {@link HttpException}. * @throws IOException {@link IOException}. */ protected void requestInvalid(HttpResponse response, String message) throws HttpException, IOException { response.setStatusCode(404); response.setEntity(new StringEntity(message)); }
From source file:price.calculation.gateway.service.impl.PriceRequesterServiceImpl.java
@Override public Response calulatePrice(Product product) { res = null;//from ww w.j a va2s.c o m final HttpClient client = new DefaultHttpClient(); final HttpPost post = new HttpPost(url); try { post.setHeader("Content-type", "application/json"); post.setEntity(new StringEntity(product.toJson())); } catch (UnsupportedEncodingException ex) { res = new Response("Invalid encoding", 400); Logger.getLogger(PriceRequesterServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } TimerTask calculationTask = new TimerTask() { @Override public void run() { if (post != null) { res = new CalculationTimedOut(); post.abort(); } } }; new Timer(true).schedule(calculationTask, timeout * 1000); try { HttpResponse httpResponse = client.execute(post); String jsonResp = EntityUtils.toString(httpResponse.getEntity()); res = CalculatedPrice.fromJson(jsonResp); } catch (IOException ex) { res = new Response("Service Unavailable", 503); Logger.getLogger(PriceRequesterServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return res; }
From source file:test.java.ecplugins.weblogic.TestUtils.java
public static void setResourceAndWorkspace(String resourceName, String workspaceName, String pluginName) throws Exception { props = getProperties();/*w w w . j a v a 2s . com*/ HttpClient httpClient = new DefaultHttpClient(); JSONObject jo = new JSONObject(); jo.put("projectName", pluginName); jo.put("resourceName", resourceName); jo.put("workspaceName", workspaceName); HttpPut httpPutRequest = new HttpPut("http://" + props.getProperty(StringConstants.COMMANDER_SERVER) + ":8000/rest/v1.0/projects/" + pluginName); String encoding = new String( org.apache.commons.codec.binary.Base64.encodeBase64(org.apache.commons.codec.binary.StringUtils .getBytesUtf8(props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD)))); StringEntity input = new StringEntity(jo.toString()); input.setContentType("application/json"); httpPutRequest.setEntity(input); httpPutRequest.setHeader("Authorization", "Basic " + encoding); HttpResponse httpResponse = httpClient.execute(httpPutRequest); if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new RuntimeException("Failed to set resource " + resourceName + " to project " + pluginName); } System.out.println("Set the resource as " + resourceName + " and workspace as " + workspaceName + " successfully for " + pluginName); }
From source file:com.gooddata.http.client.TokenUtilsTest.java
private static HttpResponse response(final String body) throws UnsupportedEncodingException { final HttpResponse response = mock(HttpResponse.class); when(response.getEntity()).thenReturn(new StringEntity(body)); return response; }
From source file:FlowPusher.ApacheHttpClient.java
public void postFloodlightClient(String jsonBody) throws UnsupportedEncodingException, IOException { try {//w w w . j a v a 2s . co m CloseableHttpClient httpClient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme("http").setHost(controllerIP + ":8080") .setPath("/wm/staticflowentrypusher/json").build(); HttpPost httpPost = new HttpPost(uri); StringEntity params = new StringEntity(jsonBody); httpPost.addHeader("content-type", "application/json"); httpPost.setEntity(params); HttpResponse response = httpClient.execute(httpPost); String x = "kostas"; } catch (URISyntaxException ex) { Logger.getLogger(ApacheHttpClient.class.getName()).log(Level.SEVERE, null, ex); } }