title: Howto add request header to Tyrus annotation based client
body: <p>I'm trying to access a websocket server endpoint using a tyrus standalone client (tyrus-standalone-client-1.9) with an annotation based client endpoint. I was mainly following <a href="https://blog.openshift.com/how-to-build-java-websocket-applications-using-the-jsr-356-api/" rel="noreferrer">this example</a>.</p>
  
  <p>That is, my client endpoint currently looks like </p>
  
  <pre class="lang-java prettyprint-override"><code>@ClientEndpoint
  public class MyClientEndpoint {
  
      private static CountDownLatch latch;
  
      private Logger logger = Logger.getLogger(this.getClass().getName());
  
      @OnOpen
      public void onOpen(Session session) throws Exception {
          session.getBasicRemote().sendText("initialRequest")
      }
  
      @OnMessage
      public void onMessage(String message, Session session) throws Exception {
          // do something
      }
  
      @OnClose
      public void onClose(Session session, CloseReason closeReason) {
          logger.info(String.format("Session %s close because of %s", session.getId(), closeReason));
          latch.countDown();
      }
  
      public static void main(String[] args) {
          latch = new CountDownLatch(1);
  
          ClientManager client = ClientManager.createClient();
          try {
              URI serverEndpointUri = new URI("ws://localhost/websockets/server/endpoint");
              client.connectToServer(MyClientEndpoint.class, serverEndpointUri);
              latch.await();
  
          } catch (DeploymentException | URISyntaxException | InterruptedException e) {
              throw new RuntimeException(e);
          }
      }
  }
  </code></pre>
  
  <p>However I need to pass some session ID along with the request and I need to modify the origin header of the request to get my connection accepted by the server endpoint.</p>
  
  <p>In a programmatic client endpoint I could do something like</p>
  
  <pre class="lang-java prettyprint-override"><code>final Builder configBuilder = ClientEndpointConfig.Builder.create();
  configBuilder.configurator(new Configurator() {
      @Override
      public void beforeRequest(final Map&lt;String, List&lt;String&gt;&gt; headers) {
          headers.put("Cookie", Arrays.asList("X-Session=0f822c8c-bf63-4ae7-9d2f-af263f86baad"));
          headers.put("Origin", Arrays.asList("http://localhost"));
      }
  });
  ClientEndpointConfig clientConfig = configBuilder.build();
  ClientManager client = ClientManager.createClient();
  URI serverEndpointUri = new URI("ws://localhost/websockets/server/endpoint");
  client.connectToServer(new MyClientEndpoint(), clientConfig, serverEndpointUri);
  </code></pre>
  
  <p>But there doesn't seem to be any option to pass the configuration to an annotation based client.</p>
  
  <p>Is there some other way to add/modify the request headers that I'm currently missing? I'd really like to stay with the annotation based approach as it seems to be much cleaner to me...</p>