Search in sources :

Example 96 with Request

use of org.eclipse.jetty.client.api.Request in project camel by apache.

the class DefaultRestClient method updateSObject.

@Override
public void updateSObject(String sObjectName, String id, InputStream sObject, ResponseCallback callback) {
    final Request patch = getRequest("PATCH", sobjectsUrl(sObjectName + "/" + id));
    // requires authorization token
    setAccessToken(patch);
    // input stream as entity content
    patch.content(new InputStreamContentProvider(sObject));
    patch.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
    doHttpRequest(patch, new DelegatingClientCallback(callback));
}
Also used : Request(org.eclipse.jetty.client.api.Request) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider)

Example 97 with Request

use of org.eclipse.jetty.client.api.Request in project camel by apache.

the class DefaultRestClient method apexCall.

@Override
public void apexCall(String httpMethod, String apexUrl, Map<String, Object> queryParams, InputStream requestDto, ResponseCallback callback) {
    // create APEX call request
    final Request request;
    try {
        request = getRequest(httpMethod, apexCallUrl(apexUrl, queryParams));
        // set request SObject and content type
        if (requestDto != null) {
            request.content(new InputStreamContentProvider(requestDto));
            request.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
        }
        // requires authorization token
        setAccessToken(request);
        doHttpRequest(request, new DelegatingClientCallback(callback));
    } catch (UnsupportedEncodingException e) {
        String msg = "Unexpected error: " + e.getMessage();
        callback.onResponse(null, new SalesforceException(msg, e));
    } catch (URISyntaxException e) {
        String msg = "Unexpected error: " + e.getMessage();
        callback.onResponse(null, new SalesforceException(msg, e));
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Request(org.eclipse.jetty.client.api.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider) URISyntaxException(java.net.URISyntaxException)

Example 98 with Request

use of org.eclipse.jetty.client.api.Request in project camel by apache.

the class DefaultRestClient method getBasicInfo.

@Override
public void getBasicInfo(String sObjectName, ResponseCallback callback) {
    Request get = getRequest(HttpMethod.GET, sobjectsUrl(sObjectName + "/"));
    // requires authorization token
    setAccessToken(get);
    doHttpRequest(get, new DelegatingClientCallback(callback));
}
Also used : Request(org.eclipse.jetty.client.api.Request)

Example 99 with Request

use of org.eclipse.jetty.client.api.Request in project camel by apache.

the class DefaultRestClient method createSObject.

@Override
public void createSObject(String sObjectName, InputStream sObject, ResponseCallback callback) {
    // post the sObject
    final Request post = getRequest(HttpMethod.POST, sobjectsUrl(sObjectName));
    // authorization
    setAccessToken(post);
    // input stream as entity content
    post.content(new InputStreamContentProvider(sObject));
    post.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
    doHttpRequest(post, new DelegatingClientCallback(callback));
}
Also used : Request(org.eclipse.jetty.client.api.Request) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider)

Example 100 with Request

use of org.eclipse.jetty.client.api.Request in project camel by apache.

the class DefaultRestClient method getBlobField.

@Override
public void getBlobField(String sObjectName, String id, String blobFieldName, ResponseCallback callback) {
    final Request get = getRequest(HttpMethod.GET, sobjectsUrl(sObjectName + "/" + id + "/" + blobFieldName));
    // TODO this doesn't seem to be required, the response is always the content binary stream
    //get.header(HttpHeader.ACCEPT_ENCODING, "base64");
    // requires authorization token
    setAccessToken(get);
    doHttpRequest(get, new DelegatingClientCallback(callback));
}
Also used : Request(org.eclipse.jetty.client.api.Request)

Aggregations

Request (org.eclipse.jetty.client.api.Request)221 Test (org.junit.Test)137 HttpServletRequest (javax.servlet.http.HttpServletRequest)120 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)117 HttpServletResponse (javax.servlet.http.HttpServletResponse)63 IOException (java.io.IOException)61 CountDownLatch (java.util.concurrent.CountDownLatch)58 ServletException (javax.servlet.ServletException)53 HttpClient (org.eclipse.jetty.client.HttpClient)48 Result (org.eclipse.jetty.client.api.Result)37 InputStream (java.io.InputStream)36 Response (org.eclipse.jetty.client.api.Response)36 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)35 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)30 FutureResponseListener (org.eclipse.jetty.client.util.FutureResponseListener)28 ByteBuffer (java.nio.ByteBuffer)27 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)26 Connection (org.eclipse.jetty.client.api.Connection)26 URI (java.net.URI)24 HttpDestinationOverHTTP (org.eclipse.jetty.client.http.HttpDestinationOverHTTP)24