List of usage examples for org.apache.commons.httpclient.methods PutMethod setRequestBody
public void setRequestBody(InputStream paramInputStream)
From source file:org.eclipse.winery.highlevelrestapi.HighLevelRestApi.java
/** * This method implements the HTTP Put Method * // www . j ava 2s. c om * @param uri Resource URI * @param requestPayload Content which has to be put into the Resource * @return ResponseCode of HTTP Interaction */ @SuppressWarnings("deprecation") public static HttpResponseMessage Put(String uri, String requestPayload, String acceptHeaderValue) { PutMethod method = new PutMethod(uri); // requestPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + // requestPayload; HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); method.setRequestBody(requestPayload); HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); // kill <?xml... in front of response HighLevelRestApi.cleanResponseBody(responseMessage); return responseMessage; }
From source file:org.iavante.sling.commons.services.DistributionServerTestIT.java
private void uploadContent() throws FileNotFoundException { PutMethod put_create_ok = new PutMethod(SLING_URL + APPS_URL); put_create_ok.setDoAuthentication(true); put_create_ok.setRequestBody(new FileInputStream("./src/test/resources/GET.jsp")); put_create_ok.setDoAuthentication(true); try {// w w w . ja v a 2 s.c om client.executeMethod(put_create_ok); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created System.out.println("Created ok: " + put_create_ok.getStatusCode()); assertEquals(201, put_create_ok.getStatusCode()); put_create_ok.releaseConnection(); }
From source file:org.iavante.sling.s3backend.S3BackendTestIT.java
private void uploadContent() throws FileNotFoundException { PutMethod put_create_ok = new PutMethod(SLING_URL + APPS_URL); put_create_ok.setDoAuthentication(true); put_create_ok.setRequestBody(new FileInputStream("./src/test/resources/GET.jsp")); put_create_ok.setDoAuthentication(true); try {/* w w w . j a v a2 s. c om*/ client.executeMethod(put_create_ok); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Content created log.info("Created ok: " + put_create_ok.getStatusCode()); // assertEquals(201, put_create_ok.getStatusCode()); put_create_ok.releaseConnection(); }
From source file:org.lgf.jahia.esni.service.ElasticSearchService.java
/** * //from ww w. ja v a 2 s . c om * Index un noeud <code>node</code> de type <code>type</code> (type elasticsearch) * l'index <code>indexName</code> * * @param node * @param indexName * @param type * @throws RepositoryException */ public void indexNode(JCRNodeWrapper node, String indexName, String type) throws RepositoryException { String baseUrl = "http://" + hostname + ":" + port + "/" + indexName + "/" + type + "/"; HttpClient client = new HttpClient(); String url = baseUrl + node.getIdentifier(); logger.info("PUT " + url); try { PutMethod put = new PutMethod(url); put.setRequestBody(serializeNodeToJSON(node, 0).toString()); client.executeMethod(put); } catch (IOException e) { logger.error("Error on PUT " + url, e); } catch (JSONException e) { logger.error("Error when serialize node to json", e); } }
From source file:org.openo.nfvo.monitor.dac.util.APIHttpClient.java
public static String doPut(String uri, String jsonObj, String token) { String resStr = null;/* ww w.j a va2s .c om*/ HttpClient htpClient = new HttpClient(); PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Content-Type", "application/json"); putMethod.addRequestHeader("X-Auth-Token", token); putMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8"); putMethod.setRequestBody(jsonObj); try { int statusCode = htpClient.executeMethod(putMethod); if (statusCode != HttpStatus.SC_OK) { return null; } byte[] responseBody = putMethod.getResponseBody(); resStr = new String(responseBody, "utf-8"); } catch (Exception e) { e.printStackTrace(); } finally { putMethod.releaseConnection(); } return resStr; }
From source file:org.openo.nfvo.monitor.umc.util.APIHttpClient.java
public static String doPut(String uri, JSONObject jsonObj, String token) { String resStr = null;/*from w w w. j a v a 2 s . c o m*/ String requestBody = jsonObj.toString(); HttpClient htpClient = new HttpClient(); PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Content-Type", "application/json"); putMethod.addRequestHeader("X-Auth-Token", token); putMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8"); putMethod.setRequestBody(requestBody); try { int statusCode = htpClient.executeMethod(putMethod); if (statusCode != HttpStatus.SC_OK) { return null; } byte[] responseBody = putMethod.getResponseBody(); resStr = new String(responseBody, "utf-8"); } catch (Exception e) { e.printStackTrace(); } finally { putMethod.releaseConnection(); } return resStr; }
From source file:org.pengyou.client.lib.DavResource.java
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param is The input stream./* w ww . j a va 2s . c o m*/ * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ protected boolean putMethod() throws HttpException, IOException { log.debug("putMethod"); InputStream is = new ByteArrayInputStream(this.contentBody); HttpClient client = getSessionInstance(); PutMethod method = new PutMethod(context.getBaseUrl() + path); generateIfHeader(method); if (getContentType() != null && !getContentType().equals("")) method.setRequestHeader("Content-Type", getContentType()); method.setRequestContentLength(PutMethod.CONTENT_LENGTH_CHUNKED); method.setRequestBody(is); generateTransactionHeader(method); int statusCode = client.executeMethod(method); this.statusCode = statusCode; return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:webdav.ManageWebDAVContacts.java
@SuppressWarnings("deprecation") private void uploadVCardsToWebDAV(String strUriFile, String strContent) { try {// ww w. j a v a2 s.c o m PutMethod httpMethod = new PutMethod(strUriFile); httpMethod.setRequestBody(strContent); this.client.executeMethod(httpMethod); httpMethod.releaseConnection(); } catch (IOException e) { e.printStackTrace(); } }