List of usage examples for org.apache.http.client.methods HttpPost HttpPost
public HttpPost(final String uri)
From source file:org.eclipse.lyo.testsuite.server.trsutils.SendUtil.java
/** * /*www . java2 s. c om*/ * @param uri resource uri for creation factory * @param httpClient client used to post to the uri * @param httpContext http context to use for the call * @param contentType content type to be used in the creation * @param content content to be used in the creation * @throws SendException if an error occurs in posting to the uri */ public static String createResource(String uri, HttpClient httpClient, HttpContext httpContext, String contentType, String content) throws SendException { String createdResourceUri = ""; if (uri == null) throw new IllegalArgumentException(Messages.getServerString("send.util.uri.null")); //$NON-NLS-1$ if (httpClient == null) throw new IllegalArgumentException(Messages.getServerString("send.util.httpclient.null")); //$NON-NLS-1$ try { new URL(uri); // Make sure URL is valid HttpPost post = new HttpPost(uri); StringEntity entity = new StringEntity(content); post.setEntity(entity); post.setHeader(HttpConstants.ACCEPT, HttpConstants.CT_APPLICATION_RDF_XML);//$NON-NLS-1$ post.addHeader(HttpConstants.CONTENT_TYPE, contentType); post.addHeader(HttpConstants.CACHE_CONTROL, "max-age=0"); //$NON-NLS-1$ HttpResponse resp = httpClient.execute(post); try { if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) { HttpErrorHandler.responseToException(resp); } createdResourceUri = resp.getFirstHeader(HttpConstants.LOCATION).getValue(); HttpResponseUtil.finalize(resp); } finally { try { if (entity != null) { EntityUtils.consume(entity); } } catch (IOException e) { // ignore } } } catch (Exception e) { String uriLocation = Messages.getServerString("send.util.uri.unidentifiable"); //$NON-NLS-1$ if (uri != null && !uri.isEmpty()) { uriLocation = uri; } throw new SendException(MessageFormat.format(Messages.getServerString("send.util.retrieve.error"), //$NON-NLS-1$ uriLocation)); } return createdResourceUri; }
From source file:org.talend.dataprep.api.service.command.transformation.SuggestActionParams.java
private SuggestActionParams(final HystrixCommand<InputStream> content, final String action, final String columnId) { super(content); execute(() -> {/*from www . j a va 2 s . co m*/ final String uri = transformationServiceUrl + "/transform/suggest/" + action + "/params?columnId=" + columnId; final HttpPost getParametersCall = new HttpPost(uri); final InputStreamEntity entity = new InputStreamEntity(getInput()); getParametersCall.setEntity(entity); return getParametersCall; }); on(HttpStatus.OK).then(pipeStream()); }
From source file:niclients.main.regni.java
static boolean createpub() throws UnsupportedEncodingException { post = new HttpPost(fqdn + "/.well-known/netinfproto/publish"); // -l int i = 0;//from w w w .ja v a2 s . c o m StringBody url = new StringBody(niname); // -n reqEntity.addPart("URI", url); StringBody msgid = new StringBody(Integer.toString(randomGenerator.nextInt(100000000))); // generate reqEntity.addPart("msgid", msgid); for (i = 0; i < loc.size(); i++) { try { StringBody l = new StringBody(loc.get(i)); reqEntity.addPart("loc" + i, l); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } post.setEntity(reqEntity); return true; }
From source file:LicenseKeyAPI.java
/** * Registers the application with the server * * @param licenseKey The license key to register with the server. * @param appID The application ID to register with the server. * @param userEmail The users email to register the app with the server. * @return The status code returned from the server. **//* ww w. j a va 2 s. com*/ public int registerApp(String licenseKey, String appID, String userEmail) { String URLpostFixEndpoint = "api/client/register_application"; // Creates HTTP POST request HttpPost httppost = new HttpPost(baseServerURLAddress + URLpostFixEndpoint); httppost.addHeader("Content-Type", "application/json"); httppost.setHeader("Content-Type", "application/json; charset= utf-8"); httppost.setHeader("Accept", "application/json"); JSONObject json = new JSONObject(); json.put("email", userEmail); json.put("licensekey", licenseKey); json.put("appID", appID); StringEntity entity = new StringEntity(json.toString(), "utf-8"); // Adds the POST params to the request httppost.setEntity(entity); return sendPOST(httppost); }
From source file:org.fcrepo.auth.integration.AbstractResourceIT.java
protected static HttpPost postObjMethod(final String pid) { return new HttpPost(serverAddress + pid); }
From source file:LogToFile.java
private static HttpPost Post(String url, HashMap<String, String> params, HashMap<String, ArrayList<String>> arrayParams) { try {//from ww w . j a v a2s. c om if (!url.endsWith("/")) url += "/"; List<NameValuePair> params_list = null; if (params != null) { params_list = new LinkedList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } if (arrayParams != null) { if (params_list == null) params_list = new LinkedList<NameValuePair>(); for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet()) for (String value : entry.getValue()) params_list.add(new BasicNameValuePair(entry.getKey(), value)); } HttpPost request = new HttpPost(url); if (params != null) request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8")); return request; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }
From source file:org.dataconservancy.ui.it.support.SaveMetadataFormatRequest.java
public HttpPost asHttpPost() { final HttpPost form = new HttpPost(urlConfig.getUiConfigUrl().toExternalForm()); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(STRIPES_EVENT, "submit")); UrlEncodedFormEntity entity = null;/* ww w .ja v a 2 s .c o m*/ try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } form.setEntity(entity); return form; }
From source file:com.devbliss.doctest.httpfactory.PostWithoutRedirectImpl.java
public HttpPost createPostRequest(URI uri, Object payload) throws IOException { HttpPost httpPost = new HttpPost(uri); HttpParams params = new BasicHttpParams(); params.setParameter(HANDLE_REDIRECTS, false); httpPost.setParams(params);//from w w w . j a v a2s . co m if (payload != null) { httpPost.setEntity(entityBuilder.buildEntity(payload)); } return httpPost; }
From source file:com.ibm.iot.iotspark.IoTPrediction.java
/** * Makes ReST call to the Predictive Analytics service with the given payload and responds with the predicted score. * //w w w . ja v a 2 s . co m * @param pURL * @param payload * @return * @throws ClientProtocolException * @throws IOException */ public static java.lang.String post(java.lang.String pURL, java.lang.String payload) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(pURL); StringEntity input = new StringEntity(payload); input.setContentType("application/json"); post.setEntity(input); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder out = new StringBuilder(); java.lang.String line; while ((line = rd.readLine()) != null) { // System.out.println(line); out.append(line); } System.out.println(out.toString()); //Prints the string content read from input stream rd.close(); return out.toString(); }
From source file:com.att.voice.TTS.java
public void say(String text, String file) { text = text.replace("\"", ""); try {/*from ww w. j ava 2s . co m*/ HttpPost httpPost = new HttpPost("https://api.att.com/speech/v3/textToSpeech"); httpPost.setHeader("Authorization", "Bearer " + mAuthToken); httpPost.setHeader("Accept", "audio/x-wav"); httpPost.setHeader("Content-Type", "text/plain"); httpPost.setHeader("Tempo", "-16"); HttpEntity entity = new StringEntity(text, "UTF-8"); httpPost.setEntity(entity); HttpResponse response = httpclient.execute(httpPost); //String result = EntityUtils.toString(response.getEntity()); HttpEntity result = response.getEntity(); BufferedInputStream bis = new BufferedInputStream(result.getContent()); String filePath = System.getProperty("user.dir") + tempFile; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath))); int inByte; while ((inByte = bis.read()) != -1) { bos.write(inByte); } bis.close(); bos.close(); executeOnCommandLine("afplay " + System.getProperty("user.dir") + "/" + tempFile); } catch (Exception ex) { System.err.println(ex.getMessage()); } }