private static BayeuxClient createBayeuxClient(Setup builder) {
final Authentication authentication = builder.authentication;
HashMap<String, Object> longPollingOptions = new HashMap<>();
LongPollingTransport longPollingTransport = new LongPollingTransport(longPollingOptions, builder.client.httpClient) {
@Override protected void customize(ContentExchange exchange) {
super.customize(exchange);
HttpRequest request = new Jetty769HttpRequest(exchange);
authentication.setupRequest(request);
logRequest(exchange);
}
@Override protected void debug(String message, Object... args) {
LOG_EVENT_TRANSPORT.debug(message, args);
}
};
// Transports are set the cookieProvider *after* creating the bayeuxClient, because
// BayeuxClient invariably sets its own cookieProvider inside the constructor.
BayeuxClient bayeuxClient;
if (builder.webSocketEnabled) {
WebSocketTransport webSocketTransport = createWebSocketTransport();
bayeuxClient = new BayeuxClient(builder.client.serverUri + "/api/v2/notifications", webSocketTransport, longPollingTransport);
webSocketTransport.setCookieProvider(builder.cookieSession.getCookieProvider());
} else {
bayeuxClient = new BayeuxClient(builder.client.serverUri + "/api/v2/notifications", longPollingTransport);
}
longPollingTransport.setCookieProvider(builder.cookieSession.getCookieProvider());
return bayeuxClient;
}