Search in sources :

Example 1 with LongPollingTransport

use of org.cometd.client.transport.LongPollingTransport in project camel by apache.

the class SubscriptionHelper method createClient.

static BayeuxClient createClient(final SalesforceComponent component) throws SalesforceException {
    // use default Jetty client from SalesforceComponent, its shared by all consumers
    final SalesforceHttpClient httpClient = component.getConfig().getHttpClient();
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(ClientTransport.MAX_NETWORK_DELAY_OPTION, httpClient.getTimeout());
    final SalesforceSession session = component.getSession();
    // check login access token
    if (session.getAccessToken() == null) {
        // lazy login here!
        session.login(null);
    }
    LongPollingTransport transport = new LongPollingTransport(options, httpClient) {

        @Override
        protected void customize(Request request) {
            super.customize(request);
            // add current security token obtained from session
            // replace old token
            request.getHeaders().put(HttpHeader.AUTHORIZATION, "OAuth " + session.getAccessToken());
        }
    };
    BayeuxClient client = new BayeuxClient(getEndpointUrl(component), transport);
    // added eagerly to check for support during handshake
    client.addExtension(REPLAY_EXTENSION);
    return client;
}
Also used : LongPollingTransport(org.cometd.client.transport.LongPollingTransport) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SalesforceSession(org.apache.camel.component.salesforce.internal.SalesforceSession) Request(org.eclipse.jetty.client.api.Request) SalesforceHttpClient(org.apache.camel.component.salesforce.SalesforceHttpClient) BayeuxClient(org.cometd.client.BayeuxClient)

Aggregations

HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SalesforceHttpClient (org.apache.camel.component.salesforce.SalesforceHttpClient)1 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)1 BayeuxClient (org.cometd.client.BayeuxClient)1 LongPollingTransport (org.cometd.client.transport.LongPollingTransport)1 Request (org.eclipse.jetty.client.api.Request)1