List of usage examples for org.apache.commons.httpclient.methods PutMethod setRequestBody
public void setRequestBody(InputStream paramInputStream)
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param is The input stream./*from www .j a va 2 s . com*/ * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, InputStream is) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestContentLength(PutMethod.CONTENT_LENGTH_CHUNKED); method.setRequestBody(is); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param data String to send.//from w ww . jav a 2 s.c o m * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, String data) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestBody(data); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the given file * @param file the filename to get on local. * @return true if the method is succeeded. * @exception HttpException/*from w w w. j av a2 s . c o m*/ * @exception IOException */ public boolean putMethod(String path, File file) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); long fileLength = file.length(); method.setRequestContentLength( fileLength <= Integer.MAX_VALUE ? (int) fileLength : PutMethod.CONTENT_LENGTH_CHUNKED); method.setRequestBody(new FileInputStream(file)); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute the PUT method for the given path from the given url. * * @param path the server relative path to put the data * @param url The URL to get a resource. * @return true if the method is succeeded. * @exception HttpException//from w w w . j a va 2s .c o m * @exception IOException */ public boolean putMethod(String path, URL url) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestBody(url.openStream()); generateTransactionHeader(method); generateAdditionalHeaders(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
From source file:org.atomserver.core.dbstore.RawClientDBSTest.java
@SuppressWarnings("deprecation") public void testMissingEntryContent() throws Exception { String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml"; HttpClient client = new HttpClient(); PutMethod put = new PutMethod(urlToCall); put.setRequestHeader("Content-type", "text/xml; charset=UTF-8"); URL url = this.getClass().getResource("/missingEntryContent.xml"); File file = new File(url.toURI()); FileInputStream fis = new FileInputStream(file); put.setRequestBody(fis); // Execute the method. int statusCode = client.executeMethod(put); // 422 -- unprocessable Entity log.debug("STATUS CODE= " + statusCode); assertTrue(statusCode == 422);/*from w ww . j a v a2s. c o m*/ }
From source file:org.atomserver.core.dbstore.RawClientDBSTest.java
@SuppressWarnings("deprecation") public void testMissingEntryContent2() throws Exception { String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml"; HttpClient client = new HttpClient(); PutMethod put = new PutMethod(urlToCall); put.setRequestHeader("Content-type", "text/xml; charset=UTF-8"); URL url = this.getClass().getResource("/missingEntryContent2.xml"); File file = new File(url.toURI()); FileInputStream fis = new FileInputStream(file); put.setRequestBody(fis); // Execute the method. int statusCode = client.executeMethod(put); // 422 -- unprocessable Entity log.debug("STATUS CODE= " + statusCode); assertTrue(statusCode == 422);/*from ww w . ja v a2 s .c om*/ }
From source file:org.atomserver.core.dbstore.RawClientDBSTest.java
@SuppressWarnings("deprecation") public void testEmptyRequest() throws Exception { String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml"; HttpClient client = new HttpClient(); PutMethod put = new PutMethod(urlToCall); put.setRequestHeader("Content-type", "text/xml; charset=UTF-8"); URL url = this.getClass().getResource("/empty.xml"); File file = new File(url.toURI()); FileInputStream fis = new FileInputStream(file); put.setRequestBody(fis); // Execute the method. int statusCode = client.executeMethod(put); // 422 -- unprocessable Entity log.debug("STATUS CODE= " + statusCode); assertEquals(422, statusCode);//from w w w .java2s .co m }
From source file:org.atomserver.core.dbstore.RawClientDBSTest.java
@SuppressWarnings("deprecation") public void testNoNamespace() throws Exception { String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml"; HttpClient client = new HttpClient(); PutMethod put = new PutMethod(urlToCall); put.setRequestHeader("Content-type", "text/xml; charset=UTF-8"); URL url = this.getClass().getResource("/noNamespaceEntry.xml"); File file = new File(url.toURI()); FileInputStream fis = new FileInputStream(file); put.setRequestBody(fis); // Execute the method. int statusCode = client.executeMethod(put); // 422 -- unprocessable Entity log.debug("STATUS CODE= " + statusCode); assertTrue(statusCode == 422);/*from w w w . j av a 2 s .co m*/ }
From source file:org.bonitasoft.connectors.xwiki.common.XWikiRestClient.java
/** * Update an XWiki MetaData using REST/* w w w.j a v a 2s.c o m*/ * @throws IOException * @throws HttpException */ @SuppressWarnings("deprecation") public boolean updateMetadata(String wikiName, String spaceName, String pageName, String className, String propertyName, String propertyValue, XWikiConnector conn) throws HttpException, IOException { try { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("updateMetadata wikiName=" + wikiName + " spaceName=" + spaceName + " pageName=" + pageName + " className=" + className + " propertyName=" + propertyName + " value=" + propertyValue); } String uri = server + "/xwiki/rest/wikis/" + wikiName + "/spaces/" + spaceName + "/pages/" + pageName + "/objects/" + className + "/0/properties/" + propertyName; if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("PUT " + uri); } HttpClient httpClient = new HttpClient(); JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb"); Unmarshaller unmarshaller = context.createUnmarshaller(); httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(username, password); httpClient.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds); PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Accept", "application/xml"); putMethod.setRequestHeader("Content-Type", "text/plain"); putMethod.setRequestBody(propertyValue); httpClient.executeMethod(putMethod); Object result = ""; String returnString = putMethod.getResponseBodyAsString(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("HTTP Result: " + returnString); } conn.setResponse(returnString); try { Property prop = (Property) unmarshaller.unmarshal(new StreamSource(new StringReader(returnString))); result = prop.getValue(); boolean status = result.equals(propertyValue); conn.setStatus(status); return status; } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error reading xwiki rest call result", e); conn.setStatus(false); return false; } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error in xwiki connector", e); conn.setStatus(false); conn.setResponse("updateMetadata failed with exception: " + e.getMessage()); return false; } }
From source file:org.demo.workflow.integration.Helper.java
@SuppressWarnings("deprecation") public String putTaskProperties(String task_instance_id, String body) throws HttpException, IOException { String connectionUrl = replaceTokensInURL(ALF_URL_SERV_WORK_ASSIGN[1], "host", host); connectionUrl = replaceTokensInURL(connectionUrl, "task_instance_id", task_instance_id); PutMethod method = new PutMethod(connectionUrl); method.setDoAuthentication(true);//from w ww .j ava 2 s . co m method.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); method.setRequestBody(body); client.executeMethod(method); String rt = method.getResponseBodyAsString(); return rt; }