cometdrequest-headersbayeux

How to add request header to BayeuxClient


  String url = "some_url";
  HttpClient httpClient = new HttpClient();
  httpClient.start();
  Map<String, Object> options = new HashMap<String, Object>();
  LongPollingTransport transport = new LongPollingTransport(options, httpClient);
  BayeuxClient client = new BayeuxClient(url, transport);
  client.getChannel(Channel.META_HANDSHAKE).addListener(new ClientSessionChannel.MessageListener() {
     public void onMessage(ClientSessionChannel channel, Message message) {
         System.out.println(message);
     }
  });
  client.handshake();

Getting

{"failure":{"exception":"org.cometd.common.TransportException: {httpCode=403}","message":{"supportedConnectionTypes":["long-polling"],"channel":"/meta/handshake","id":"2","version":"1.0"},"httpCode":403,"connectionType":"long-polling"},"channel":"/meta/handshake","id":"2","subscription":null,"successful":false}

So my first guess is to add authorization header. How can I do that? Jetty 9 is used for both the server and the client code libraries.


Solution

  • Please have a look at this test case that shows how to do it.