Search in sources :

Example 91 with HttpPut

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();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 92 with HttpPut

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;
}
Also used : HttpPut(org.apache.http.client.methods.HttpPut)

Example 93 with HttpPut

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");
}
Also used : HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 94 with HttpPut

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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 95 with HttpPut

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();
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

HttpPut (org.apache.http.client.methods.HttpPut)153 StringEntity (org.apache.http.entity.StringEntity)89 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)50 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)40 HttpResponse (org.apache.http.HttpResponse)29 Test (org.junit.Test)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)27 Deployment (org.activiti.engine.test.Deployment)27 HttpPost (org.apache.http.client.methods.HttpPost)19 HttpGet (org.apache.http.client.methods.HttpGet)17 IOException (java.io.IOException)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 HttpEntity (org.apache.http.HttpEntity)13 URI (java.net.URI)12 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)12 HttpHead (org.apache.http.client.methods.HttpHead)11 Execution (org.activiti.engine.runtime.Execution)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)9