List of usage examples for org.apache.commons.httpclient.methods PutMethod setRequestEntity
public void setRequestEntity(RequestEntity paramRequestEntity)
From source file:de.mpg.mpdl.inge.xmltransforming.TestBase.java
/** * Uploads a file to the staging servlet and returns the corresponding URL. * //from w w w . ja v a 2s . co m * @param filename The file to upload * @param mimetype The mimetype of the file * @param userHandle The userHandle to use for upload * @return The URL of the uploaded file. * @throws Exception If anything goes wrong... */ protected URL uploadFile(String filename, String mimetype, final String userHandle) throws Exception { // Prepare the HttpMethod. String fwUrl = PropertyReader.getFrameworkUrl(); PutMethod method = new PutMethod(fwUrl + "/st/staging-file"); method.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(filename))); method.setRequestHeader("Content-Type", mimetype); method.setRequestHeader("Cookie", "escidocCookie=" + userHandle); // Execute the method with HttpClient. HttpClient client = new HttpClient(); ProxyHelper.executeMethod(client, method); String response = method.getResponseBodyAsString(); assertEquals(HttpServletResponse.SC_OK, method.getStatusCode()); return ((XmlTransforming) getService(XmlTransforming.SERVICE_NAME)) .transformUploadResponseToFileURL(response); }
From source file:com.apifest.oauth20.tests.OAuth20BasicTest.java
public String updateClientApp(String clientId, String scope, String description, Integer status, String redirectUri) {//from w w w . java 2 s .c o m PutMethod put = new PutMethod(baseOAuth20Uri + APPLICATION_ENDPOINT + "/" + clientId); String response = null; try { //put.setRequestHeader(HttpHeaders.AUTHORIZATION, createBasicAuthorization(clientId)); JSONObject json = new JSONObject(); json.put("status", status); json.put("description", description); json.put("redirect_uri", redirectUri); String requestBody = json.toString(); RequestEntity requestEntity = new StringRequestEntity(requestBody, "application/json", "UTF-8"); put.setRequestHeader(HttpHeaders.CONTENT_TYPE, "application/json"); put.setRequestEntity(requestEntity); response = readResponse(put); log.info(response); } catch (IOException e) { log.error("cannot update client app", e); } catch (JSONException e) { log.error("cannot update client app", e); } return response; }
From source file:de.mpg.mpdl.inge.xmltransforming.TestBase.java
/** * Creates an item with a file in the framework. * /* w w w. j a v a2s .c o m*/ * @param userHandle The userHandle of a user with the appropriate grants. * @return The XML of the created item with a file, given back by the framework. * @throws Exception Any exception */ protected String createItemWithFile(String userHandle) throws Exception { // Prepare the HttpMethod. PutMethod method = new PutMethod(PropertyReader.getFrameworkUrl() + "/st/staging-file"); method.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(COMPONENT_FILE))); method.setRequestHeader("Content-Type", MIME_TYPE); method.setRequestHeader("Cookie", "escidocCookie=" + userHandle); // Execute the method with HttpClient. HttpClient client = new HttpClient(); ProxyHelper.executeMethod(client, method); logger.debug("Status=" + method.getStatusCode()); // >= HttpServletResponse.SC_MULTIPLE_CHOICE // 300 ??? assertEquals(HttpServletResponse.SC_OK, method.getStatusCode()); String response = method.getResponseBodyAsString(); logger.debug("Response=" + response); // Create a document from the response. DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(method.getResponseBodyAsStream()); document.getDocumentElement().normalize(); // Extract the file information. String href = getValue(document, "/staging-file/@href"); assertNotNull(href); // Create an item with the href in the component. String item = readFile(ITEM_FILE); item = item.replaceFirst("XXX_CONTENT_REF_XXX", PropertyReader.getFrameworkUrl() + href); logger.debug("Item=" + item); item = ServiceLocator.getItemHandler(userHandle).create(item); assertNotNull(item); logger.debug("Item=" + item); return item; }
From source file:com.zimbra.cs.index.elasticsearch.ElasticSearchIndex.java
private void initializeIndex() { if (haveMappingInfo) { return;//www . j a v a 2s.co m } if (!refreshIndexIfNecessary()) { try { ElasticSearchConnector connector = new ElasticSearchConnector(); JSONObject mappingInfo = createMappingInfo(); PutMethod putMethod = new PutMethod(ElasticSearchConnector.actualUrl(indexUrl)); putMethod.setRequestEntity(new StringRequestEntity(mappingInfo.toString(), MimeConstants.CT_APPLICATION_JSON, MimeConstants.P_CHARSET_UTF8)); int statusCode = connector.executeMethod(putMethod); if (statusCode == HttpStatus.SC_OK) { haveMappingInfo = true; refreshIndexIfNecessary(); // Sometimes searches don't seem to honor mapping info. Try to force it } else { ZimbraLog.index.error("Problem Setting mapping information for index with key=%s httpstatus=%d", key, statusCode); } } catch (HttpException e) { ZimbraLog.index.error("Problem Getting mapping information for index with key=" + key, e); } catch (IOException e) { ZimbraLog.index.error("Problem Getting mapping information for index with key=" + key, e); } catch (JSONException e) { ZimbraLog.index.error("Problem Setting mapping information for index with key=" + key, e); } } }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
@Test public void testPutOperation5Xml() throws Exception { String url = URL_RESOURCE1 + "/pathPutOperation5Xml"; PutMethod method = new PutMethod(url); String param = this.getXmlCd(); method.setRequestEntity(new StringRequestEntity(param, "application/xml", null)); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT); byte[] responseBody = method.getResponseBody(); assertNull(responseBody);/* w w w. j av a 2 s . co m*/ }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
@Test public void testPutOperation5Json() throws Exception { String url = URL_RESOURCE1 + "/pathPutOperation5Json"; PutMethod method = new PutMethod(url); String param = this.getJsonCd(); method.setRequestEntity(new StringRequestEntity(param, "application/json", null)); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT); byte[] responseBody = method.getResponseBody(); assertNull(responseBody);/* ww w. j a v a2 s . c om*/ }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
@Test public void testPutOperation7Xml() throws Exception { String url = URL_RESOURCE1 + "/pathPutOperation7Xml"; PutMethod method = new PutMethod(url); String param = this.getXmlCd(); method.setRequestEntity(new StringRequestEntity(param, "application/xml", null)); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_OK); byte[] responseBody = method.getResponseBody(); String xmlResponse = new String(responseBody); assertTrue(xmlResponse.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") > -1); assertTrue(xmlResponse.indexOf("<title>My Track 1</title>") > -1); }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
@Test public void testPutOperation7Json() throws Exception { String url = URL_RESOURCE1 + "/pathPutOperation7Json"; PutMethod method = new PutMethod(url); String param = this.getJsonCd(); method.setRequestEntity(new StringRequestEntity(param, "application/json", null)); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_OK); byte[] responseBody = method.getResponseBody(); String jsonResponse = new String(responseBody); assertTrue(jsonResponse.indexOf("\"title\":\"My Track 1\"") > -1); }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
@Test public void testPutOperation8Xml() throws Exception { String url = URL_RESOURCE1 + "/pathPutOperation8Xml"; PutMethod method = new PutMethod(url); String param = this.getXmlCd(); method.setRequestEntity(new StringRequestEntity(param, "application/xml", null)); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_OK); byte[] responseBody = method.getResponseBody(); String xmlResponse = new String(responseBody); assertTrue(xmlResponse.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") > -1); assertTrue(xmlResponse.indexOf("<title>putOperation8</title>") > -1); }
From source file:muki.tool.JavaCompilationDeploymentTestCase.java
@Test public void testPutOperation8Json() throws Exception { String url = URL_RESOURCE1 + "/pathPutOperation8Json"; PutMethod method = new PutMethod(url); String param = this.getJsonCd(); method.setRequestEntity(new StringRequestEntity(param, "application/json", null)); int statusCode = this.getHttpClient().executeMethod(method); assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_OK); byte[] responseBody = method.getResponseBody(); String jsonResponse = new String(responseBody); assertTrue(jsonResponse.indexOf("\"title\":\"putOperation8\"") > -1); }