1

This is my first post.I have seen some some answer for this question - Jetty 8.1.1 Websocket client handshake But using similar kind of solution didn't help me. The Client connects to the server and sends the message, but on the server side, the server is not authenticating client (invalid token) even tough I am sending the right token. I am not able to understand what I am missing. Same thing in Javascript is working but I have to implement it in Java.

Here is my sample client code. Any help will be greatly appreciated.Thanks!

public class JettyWebSocketClient {

  public static void main(String[] args) throws Exception {
    JettyWebSocketClient app = new JettyWebSocketClient();
    app.test();
}

  public void test() throws Exception {
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    request.setHeader("Authorization", "xyz==");
    WebSocketClient client = new WebSocketClient(new SslContextFactory());
    MyWebSocket socket = new MyWebSocket();
    client.start();
    URI destUri = new URI("wss://xyz.com:4443/ws");
    System.out.println("Connecting to " + destUri);
    client.connect(socket, destUri, request);
    socket.awaitClose(20, TimeUnit.SECONDS);
    client.stop();
  }
}

1 Answer 1

1

If you server expects Basic Authentication, the value of Authorization header must start with "Basic ".

Try to change

request.setHeader("Authorization", "xyz==");

to

request.setHeader("Authorization", "Basic xyz==");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but it didn't help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.