Not able to send cookie in websocket client in java when connecting to server

Viewed 125

I want to send cookie to server using java websocket client

ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() {
    public void beforeRequest(Map<String,List<String>> headers) {
        List<String> list=new ArrayList<>();
        list.add("cookie value");
        headers.put("Cookie", list);
    }
};
ClientEndpointConfig clientConfig = ClientEndpointConfig.Builder.create()
        .configurator(configurator)
        .build();

WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.connectToServer(clientConfig,endpointURI);

this is my code and I am getting below error :

javax.websocket.DeploymentException: Cannot use POJO class [javax.websocket.DefaultClientEndpointConfig] as it is not annotated with @ClientEndpoint

0 Answers
Related