use of org.apache.http.client.methods.HttpPut in project LiveSDK-for-Android by liveservices.
the class UploadRequest method execute.
@Override
public JSONObject execute() throws LiveOperationException {
UriBuilder uploadRequestUri;
// we will proxy the upload request, which is a waste of resources.
if (this.pathUri.isRelative()) {
JSONObject response = this.getUploadLocation();
// we need to throw an error.
if (response.has(ERROR_KEY)) {
return response;
} else if (!response.has(UPLOAD_LOCATION_KEY)) {
throw new LiveOperationException(ErrorMessages.MISSING_UPLOAD_LOCATION);
}
// once we have the file object, get the upload location
String uploadLocation;
try {
uploadLocation = response.getString(UPLOAD_LOCATION_KEY);
} catch (JSONException e) {
throw new LiveOperationException(ErrorMessages.SERVER_ERROR, e);
}
uploadRequestUri = UriBuilder.newInstance(Uri.parse(uploadLocation));
// The original path might have query parameters that were sent to the
// the upload location request, and those same query parameters will need
// to be sent to the HttpPut upload request too. Also, the returned upload_location
// *could* have query parameters on it. We want to keep those intact and in front of the
// the client's query parameters.
uploadRequestUri.appendQueryString(this.pathUri.getQuery());
} else {
uploadRequestUri = this.requestUri;
}
if (!this.isFileUpload) {
// if it is not a file upload it is a folder upload and we must
// add the file name to the upload location
// and don't forget to set the overwrite query parameter
uploadRequestUri.appendToPath(this.filename);
this.overwrite.appendQueryParameterOnTo(uploadRequestUri);
}
HttpPut uploadRequest = new HttpPut(uploadRequestUri.toString());
uploadRequest.setEntity(this.entity);
this.currentRequest = uploadRequest;
return super.execute();
}
use of org.apache.http.client.methods.HttpPut in project LiveSDK-for-Android by liveservices.
the class PutRequest method createHttpRequest.
/**
* Factory method override that constructs a HttpPut and adds a body to it.
*
* @return a HttpPut with the properly body added to it.
*/
@Override
protected HttpUriRequest createHttpRequest() throws LiveOperationException {
final HttpPut request = new HttpPut(this.requestUri.toString());
request.setEntity(this.entity);
return request;
}
use of org.apache.http.client.methods.HttpPut in project camel by apache.
the class RestletMultiRoutesEndpointTest method testPutMethod.
@Test
public void testPutMethod() throws Exception {
HttpResponse response = doExecute(new HttpPut("http://localhost:" + portNum + "/users/homer"));
assertHttpResponse(response, 200, "text/plain", "result PUT");
}
use of org.apache.http.client.methods.HttpPut in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testUpdateVipCustomer.
@Test
public void testUpdateVipCustomer() throws Exception {
HttpPut put = new HttpPut("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul2"), sw);
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
HttpResponse response = httpclient.execute(put);
assertEquals(200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.client.methods.HttpPut in project camel by apache.
the class CxfRsConvertBodyToTest method testPutConsumer.
@Test
public void testPutConsumer() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(Customer.class);
HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
put.addHeader("test", "header1;header2");
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();
}
}
Aggregations