use of org.cometd.client.BayeuxClient 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;
}
Aggregations