List of usage examples for org.apache.commons.httpclient.methods PatchMethod PatchMethod
public PatchMethod(String url)
From source file:com.cloudbees.api.BeesClient.java
/** * Sends a request in JSON and expects a JSON response back. * * @param urlTail The end point to hit. Appended to {@link #base}. Shouldn't start with '/' * @param method HTTP method name like GET or POST. * @param headers/* w w w . j av a2 s. co m*/ *@param jsonContent The json request payload, or null if none. @throws IOException If the communication fails. */ public HttpReply jsonRequest(String urlTail, String method, Map<String, String> headers, String jsonContent) throws IOException { HttpMethodBase httpMethod; String urlString = absolutize(urlTail); trace("API call: " + urlString); if (method.equalsIgnoreCase("GET")) { httpMethod = new GetMethod(urlString); } else if ((method.equalsIgnoreCase("POST"))) { httpMethod = new PostMethod(urlString); } else if ((method.equalsIgnoreCase("PUT"))) { httpMethod = new PutMethod(urlString); } else if ((method.equalsIgnoreCase("DELETE"))) { httpMethod = new DeleteMethod(urlString); } else if ((method.equalsIgnoreCase("PATCH"))) { httpMethod = new PatchMethod(urlString); } else if ((method.equalsIgnoreCase("HEAD"))) { httpMethod = new HeadMethod(urlString); } else if ((method.equalsIgnoreCase("TRACE"))) { httpMethod = new TraceMethod(urlString); } else if ((method.equalsIgnoreCase("OPTIONS"))) { httpMethod = new OptionsMethod(urlString); } else throw new IOException("Method not supported: " + method); httpMethod.setRequestHeader("Accept", "application/json"); if (jsonContent != null && httpMethod instanceof EntityEnclosingMethod) { StringRequestEntity requestEntity = new StringRequestEntity(jsonContent, "application/json", "UTF-8"); ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity); trace("Payload: " + jsonContent); } return executeRequest(httpMethod, headers); }
From source file:org.httpobjects.tck.IntegrationTest.java
@Test public void supportsPatch() throws Exception { // given/*from w w w .j av a2s . co m*/ PatchMethod request = new PatchMethod("http://localhost:8080/patchme"); request.setRequestEntity(new StringRequestEntity(" foo bar", "text/plain", "UTF-8")); // then/when assertResource(request, "You told me to patch! foo bar", 200); }