use of org.apache.http.client.methods.HttpPut in project camel by apache.
the class CxfRsRouterTest method testPutConsumer.
@Test
public void testPutConsumer() throws Exception {
HttpPut put = new HttpPut("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers");
StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
put.setEntity(entity);
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
try {
HttpResponse response = httpclient.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("", EntityUtils.toString(response.getEntity()));
} finally {
httpclient.close();
}
}
use of org.apache.http.client.methods.HttpPut in project openkit-android by OpenKit.
the class AsyncHttpClient method put.
/**
* Perform a HTTP PUT request and track the Android Context which initiated the request.
* And set one-time headers for the request
* @param context the Android Context which initiated the request.
* @param url the URL to send the request to.
* @param headers set one-time headers for this request
* @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml payloads to a server by passing a {@link org.apache.http.entity.StringEntity}.
* @param contentType the content type of the payload you are sending, for example application/json if sending a json payload.
* @param responseHandler the response handler instance that should handle the response.
*/
public void put(Context context, String url, Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPut(url), entity);
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
}
use of org.apache.http.client.methods.HttpPut in project mobile-android by photo.
the class ApiBase method createHttpRequest.
/**
* Create a HttpUriRequest out of a ApiRequest object.
*
* @param request the ApiRequest for which a HttpUriRequest should be
* created
* @param baseUrl the base server url
* @param listener Progress Listener with callback on progress
* @return HttpUriRequest object which will do the request as described in
* ApiRequest
* @throws UnsupportedEncodingException
*/
private HttpUriRequest createHttpRequest(ApiRequest request, String baseUrl, ProgressListener listener) throws UnsupportedEncodingException {
HttpUriRequest httpRequest = null;
switch(request.getMethod()) {
case ApiRequest.GET:
httpRequest = new HttpGet(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
break;
case ApiRequest.POST:
httpRequest = new HttpPost(baseUrl + request.getPath());
HttpPost httpPost = ((HttpPost) httpRequest);
if (request.isMime()) {
// TODO use the multipart when possible (currently server
// handles it wrong)
// HttpEntity entity = createMultipartEntity(request);
// TODO remove this when doing correct multipart
httpRequest = new HttpPost(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
httpPost = ((HttpPost) httpRequest);
HttpEntity entity = createFileOnlyMultipartEntity(request);
if (listener != null) {
httpPost.setEntity(new HttpEntityWithProgress(entity, listener, httpPost));
} else {
httpPost.setEntity(entity);
}
} else {
httpPost.setEntity(new UrlEncodedFormEntity(request.getParameters(), HTTP.UTF_8));
}
break;
case ApiRequest.PUT:
httpRequest = new HttpPut(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
break;
case ApiRequest.DELETE:
httpRequest = new HttpDelete(addParamsToUrl(baseUrl + request.getPath(), request.getParameters()));
break;
}
for (NameValuePair pair : request.getHeaders()) {
request.addHeader(pair.getName(), pair.getValue());
}
return httpRequest;
}
use of org.apache.http.client.methods.HttpPut in project spark by perwendel.
the class SparkTestUtil method getHttpRequest.
private HttpUriRequest getHttpRequest(String requestMethod, String path, String body, boolean secureConnection, String acceptType, Map<String, String> reqHeaders) {
try {
String protocol = secureConnection ? "https" : "http";
String uri = protocol + "://localhost:" + port + path;
if (requestMethod.equals("GET")) {
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("Accept", acceptType);
addHeaders(reqHeaders, httpGet);
return httpGet;
}
if (requestMethod.equals("POST")) {
HttpPost httpPost = new HttpPost(uri);
httpPost.setHeader("Accept", acceptType);
addHeaders(reqHeaders, httpPost);
httpPost.setEntity(new StringEntity(body));
return httpPost;
}
if (requestMethod.equals("PATCH")) {
HttpPatch httpPatch = new HttpPatch(uri);
httpPatch.setHeader("Accept", acceptType);
addHeaders(reqHeaders, httpPatch);
httpPatch.setEntity(new StringEntity(body));
return httpPatch;
}
if (requestMethod.equals("DELETE")) {
HttpDelete httpDelete = new HttpDelete(uri);
addHeaders(reqHeaders, httpDelete);
httpDelete.setHeader("Accept", acceptType);
return httpDelete;
}
if (requestMethod.equals("PUT")) {
HttpPut httpPut = new HttpPut(uri);
httpPut.setHeader("Accept", acceptType);
addHeaders(reqHeaders, httpPut);
httpPut.setEntity(new StringEntity(body));
return httpPut;
}
if (requestMethod.equals("HEAD")) {
HttpHead httpHead = new HttpHead(uri);
addHeaders(reqHeaders, httpHead);
return httpHead;
}
if (requestMethod.equals("TRACE")) {
HttpTrace httpTrace = new HttpTrace(uri);
addHeaders(reqHeaders, httpTrace);
return httpTrace;
}
if (requestMethod.equals("OPTIONS")) {
HttpOptions httpOptions = new HttpOptions(uri);
addHeaders(reqHeaders, httpOptions);
return httpOptions;
}
if (requestMethod.equals("LOCK")) {
HttpLock httpLock = new HttpLock(uri);
addHeaders(reqHeaders, httpLock);
return httpLock;
}
throw new IllegalArgumentException("Unknown method " + requestMethod);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
use of org.apache.http.client.methods.HttpPut in project robolectric by robolectric.
the class FakeHttpLayerTest method matches_shouldMatchPostBody.
@Test
public void matches_shouldMatchPostBody() throws Exception {
final String expectedText = "some post body text";
requestMatcherBuilder.postBody(new FakeHttpLayer.RequestMatcherBuilder.PostBodyMatcher() {
@Override
public boolean matches(HttpEntity actualPostBody) throws IOException {
return EntityUtils.toString(actualPostBody).equals(expectedText);
}
});
HttpPut match = new HttpPut("example.com");
match.setEntity(new StringEntity(expectedText));
HttpPost noMatch = new HttpPost("example.com");
noMatch.setEntity(new StringEntity("some text that does not match"));
assertThat(requestMatcherBuilder.matches(new HttpGet("example.com"))).isFalse();
assertThat(requestMatcherBuilder.matches(noMatch)).isFalse();
assertThat(requestMatcherBuilder.matches(match)).isTrue();
}
Aggregations