List of usage examples for org.apache.commons.httpclient.methods PutMethod PutMethod
public PutMethod(String paramString)
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public void resourceNotification(String modelSetId, String modelId, String artifactId, String resourceId, ResourceType type, NotificationActionType action, String userId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/resourcenotification/%s", DefaultRestResource.REST_URI, modelSetId); PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Accept", "application/xml"); NameValuePair[] queryString = new NameValuePair[6]; queryString[0] = new NameValuePair("modelid", modelId); queryString[1] = new NameValuePair("artifactid", artifactId); queryString[2] = new NameValuePair("resourceid", resourceId); queryString[3] = new NameValuePair("resourcetype", type.toString()); queryString[4] = new NameValuePair("action", action.toString()); queryString[5] = new NameValuePair("userid", userId); putMethod.setQueryString(queryString); try {/*w w w. ja va2 s.c o m*/ httpClient.executeMethod(putMethod); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:eu.eco2clouds.scheduler.bonfire.BFClientSchedulerImpl.java
private String putMethod(String url, String payload, Boolean exception) { // Create an instance of HttpClient. HttpClient client = getHttpClient(); logger.debug("Connecting to: " + url); // Create a method instance. PutMethod method = new PutMethod(url); setHeaders(method);//w w w.j av a2s . c om // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); String response = ""; try { RequestEntity entity = new StringRequestEntity(payload, SchedulerDictionary.CONTENT_TYPE_BONFIRE_XML, "UTF-8"); method.setRequestEntity(entity); // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_ACCEPTED) { //TODO test for this case... logger.warn( "get managed experiments information... : " + url + " failed: " + method.getStatusLine()); } else { // Read the response body. byte[] responseBody = method.getResponseBody(); response = new String(responseBody); } } catch (HttpException e) { logger.warn("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); exception = true; } catch (IOException e) { logger.warn("Fatal transport error: " + e.getMessage()); e.printStackTrace(); exception = true; } finally { // Release the connection. method.releaseConnection(); } return response; }
From source file:com.assemblade.client.AbstractClient.java
protected <T> T update(String path, T object, TypeReference<T> type) throws ClientException { PutMethod put = new PutMethod(baseUrl + path); try {//from www .j a v a 2 s . c o m try { put.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(put); if (statusCode == 200) { try { return mapper.readValue(put.getResponseBodyAsStream(), type); } catch (IOException e) { throw new CallFailedException("Failed to deserialize a response object", e); } } else { throw new InvalidStatusException(200, statusCode); } } finally { put.releaseConnection(); } }
From source file:com.arjuna.qa.junit.HttpUtils.java
public static HttpMethodBase createMethod(URL url, int type) { HttpMethodBase request = null;/*from w w w . j a v a 2 s .c o m*/ switch (type) { case GET: request = new GetMethod(url.toString()); break; case POST: request = new PostMethod(url.toString()); break; case HEAD: request = new HeadMethod(url.toString()); break; case OPTIONS: request = new OptionsMethod(url.toString()); break; case PUT: request = new PutMethod(url.toString()); break; case DELETE: request = new DeleteMethod(url.toString()); break; case TRACE: request = new TraceMethod(url.toString()); break; } return request; }
From source file:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java
@Override public void modelVerified(String modelSetId, String result) throws LpRestExceptionXWikiImpl { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/bridge/modelverified/%s", DefaultRestResource.REST_URI, modelSetId);/*from www.j ava 2 s . co m*/ PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Accept", "application/xml"); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("result", result); putMethod.setQueryString(queryString); try { httpClient.executeMethod(putMethod); } catch (IOException e) { e.printStackTrace(); throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:com.intuit.tank.httpclient3.TankHttpClient3.java
@Override public void doPut(BaseRequest request) { try {//from w w w. ja v a 2 s . c o m PutMethod httpput = new PutMethod(request.getRequestUrl()); // Multiple calls can be expensive, so get it once String requestBody = request.getBody(); StringRequestEntity entity = new StringRequestEntity(requestBody, request.getContentType(), request.getContentTypeCharSet()); httpput.setRequestEntity(entity); sendRequest(request, httpput, requestBody); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java
protected HttpMethod createMethod(final String type, final String uri, final int port) throws BigSwitchBcfApiException { String url;/*www. j a va2 s . c o m*/ try { url = new URL(S_PROTOCOL, host, port, uri).toString(); } catch (MalformedURLException e) { S_LOGGER.error("Unable to build Big Switch API URL", e); throw new BigSwitchBcfApiException("Unable to build Big Switch API URL", e); } if ("post".equalsIgnoreCase(type)) { return new PostMethod(url); } else if ("get".equalsIgnoreCase(type)) { return new GetMethod(url); } else if ("delete".equalsIgnoreCase(type)) { return new DeleteMethod(url); } else if ("put".equalsIgnoreCase(type)) { return new PutMethod(url); } else { throw new BigSwitchBcfApiException("Requesting unknown method type"); } }
From source file:jails.http.client.CommonsClientHttpRequestFactory.java
/** * Create a Commons HttpMethodBase object for the given HTTP method * and URI specification.//from w w w . ja v a 2 s.c om * @param httpMethod the HTTP method * @param uri the URI * @return the Commons HttpMethodBase object */ protected HttpMethodBase createCommonsHttpMethod(HttpMethod httpMethod, String uri) { switch (httpMethod) { case GET: return new GetMethod(uri); case DELETE: return new DeleteMethod(uri); case HEAD: return new HeadMethod(uri); case OPTIONS: return new OptionsMethod(uri); case POST: return new PostMethod(uri); case PUT: return new PutMethod(uri); case TRACE: return new TraceMethod(uri); default: throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod); } }
From source file:edu.ucsb.eucalyptus.cloud.ws.tests.CreateSnapshotTest.java
public void testSendDummy() throws Exception { HttpClient httpClient = new HttpClient(); String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/meh/ttt.wsl?gg=vol&hh=snap"; HttpMethodBase method = new PutMethod(addr); method.setRequestHeader("Authorization", "Euca"); method.setRequestHeader("Date", (new Date()).toString()); method.setRequestHeader("Expect", "100-continue"); httpClient.executeMethod(method);/*from ww w. j a v a 2 s. co m*/ String responseString = method.getResponseBodyAsString(); System.out.println(responseString); method.releaseConnection(); }
From source file:gov.va.vinci.leo.tools.JamService.java
/** * Given a queue name, determine if it already exists. * * @param queueName the ServiceQueue.queueName to check for * @param brokerUrl the broker url this service is using. * @return returns TRUE if the service queue name exists, or false if it does not. * @throws IOException if any communication exception occurs. *//*ww w . j a v a 2s . co m*/ public boolean doesServiceQueueExist(final String queueName, final String brokerUrl) throws IOException { PutMethod method = new PutMethod(jamServerBaseUrl + "webservice/doesServiceQueueExist"); method.setRequestBody(getServiceQueueExistRequestBody(queueName, brokerUrl)); String result = doHttpCall(method); return "TRUE".equals(result); }