List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestEntity
public void setRequestEntity(RequestEntity paramRequestEntity)
From source file:com.epam.wilma.service.http.WilmaHttpClient.java
/** * Posting the given stream to the given URL via HTTP POST method and returns * {@code true} if the request was successful. * * @param url the given URL/* w w w. j a va2 s. com*/ * @param resource the given string that will be uploaded as resource * @return {@code true} if the request is successful, otherwise return {@code false} */ public boolean uploadString(String url, String resource) { boolean requestSuccessful = false; PostMethod method = new PostMethod(url); try { method.setRequestEntity(new StringRequestEntity(resource, null, null)); int statusCode = httpclient.executeMethod(method); if (HttpStatus.SC_OK == statusCode) { requestSuccessful = true; } } catch (HttpException e) { LOG.error("Protocol exception occurred when called: " + url, e); } catch (IOException e) { LOG.error("I/O (transport) error occurred when called: " + url, e); } finally { method.releaseConnection(); } return requestSuccessful; }
From source file:net.mojodna.searchable.solr.SolrIndexer.java
@Override protected void delete(final Serializable key) throws IndexingException { final Element delete = new Element("delete").addContent( new Element("query").addContent(IndexSupport.COMPOUND_ID_FIELD_NAME + ":" + key.toString())); // now do something with the delete block try {/*w w w. ja v a 2s .c o m*/ final XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); final String deleteString = out.outputString(delete); final PostMethod post = new PostMethod(solrPath); post.setRequestEntity(new StringRequestEntity(deleteString, "text/xml", "UTF-8")); log.debug("Deleting:\n" + deleteString); getHttpClient().executeMethod(post); if (!isBatchMode()) { commit(); } } catch (final IOException e) { throw new IndexingException(e); } }
From source file:net.mojodna.searchable.solr.SolrIndexer.java
/** * Serialize the Document and hand it to Solr. *//*w ww. ja va 2 s . co m*/ @Override protected void save(final Document doc) throws IndexingException { final Element add = new Element("add"); add.addContent(DocumentConverter.convert(doc)); // now do something with the add block try { final XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); final String addString = out.outputString(add); final PostMethod post = new PostMethod(solrPath); post.setRequestEntity(new StringRequestEntity(addString, "text/xml", "UTF-8")); log.debug("Adding:\n" + addString); getHttpClient().executeMethod(post); if (!isBatchMode()) { commit(); } } catch (final IOException e) { throw new IndexingException(e); } }
From source file:com.owncloud.android.CrashlogSendActivity.java
@Override public void onClick(DialogInterface dialog, final int which) { new Thread(new Runnable() { @Override//from w ww . j a va2s .com public void run() { // TODO Auto-generated method stub File file = new File(mLogFilename); if (which == Dialog.BUTTON_POSITIVE) { try { HttpClient client = new HttpClient(); PostMethod post = new PostMethod(CRASHLOG_SUBMIT_URL); Part[] parts = { new FilePart("crashfile", file) }; post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); client.executeMethod(post); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } } file.delete(); finish(); } }).start(); }
From source file:com.cognifide.calais.OpenCalaisService.java
@SuppressWarnings("deprecation") private String doCalaisRequest(String textBody) throws IOException { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Calais Rest Client"); PostMethod method = createPostMethod(); method.setRequestEntity(new StringRequestEntity(textBody)); try {//w w w. j a va 2 s . c om int returnCode = client.executeMethod(method); if (returnCode == HttpStatus.SC_OK) { return getResponse(method); } else if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) { log("The Post method is not implemented by this URI"); } else { log("Got code: " + returnCode); log("response: " + method.getResponseBodyAsString()); } } finally { method.releaseConnection(); } return null; }
From source file:ch.flatland.cdo.client.internal.http.HTTPSClientConnector.java
private void request(ExtendedIOHandler handler) throws IOException, HttpException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ExtendedDataOutputStream out = new ExtendedDataOutputStream(baos); handler.handleOut(out);//from w w w . ja v a 2s. c o m out.flush(); PostMethod method = createHTTPMethod(url); method.setRequestEntity(new ByteArrayRequestEntity(baos.toByteArray())); try { httpClient.executeMethod(method); InputStream bodyInputStream = method.getResponseBodyAsStream(); ExtendedDataInputStream in = new ExtendedDataInputStream(bodyInputStream); handler.handleIn(in); } finally { method.releaseConnection(); } }
From source file:com.adobe.people.jedelson.aemslack.impl.Notifier.java
private void sendMessage(SlackMessage msg) throws HttpException, IOException { PostMethod pm = new PostMethod(url); pm.setRequestEntity(new StringRequestEntity(msg.toJsonString(), "application/json", "UTF-8")); httpClient.executeMethod(pm);// w w w . j a va2 s .c o m }
From source file:com.assemblade.client.AbstractClient.java
protected <T> T add(String path, T object, TypeReference<T> type) throws ClientException { PostMethod post = new PostMethod(baseUrl + path); try {//from w w w.j a v a 2 s . c o m try { post.setRequestEntity( new StringRequestEntity(mapper.writeValueAsString(object), "application/json", null)); } catch (IOException e) { throw new CallFailedException("Failed to serialize a request object", e); } int statusCode = executeMethod(post); if (statusCode == 200) { try { return mapper.readValue(post.getResponseBodyAsStream(), type); } catch (IOException e) { throw new CallFailedException("Failed to deserialize a response object", e); } } else { throw new InvalidStatusException(200, statusCode); } } finally { post.releaseConnection(); } }
From source file:models.Calais.java
public JSONObject postFile(String content, PostMethod method) throws IOException, ParseException { method.setRequestEntity(new StringRequestEntity(content)); return doRequest(method); }
From source file:com.mobilefirst.fiberlink.Authenticator.java
/** * Description: Create initial post method * @param xml: the xml body payload/*from w ww .j a va 2s .c om*/ * @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); }