title: Spring websocket (WSS) with angular sockjs (HTTPS) over secure web socket server (tomcat)
body: <p>I'm working on sending messages from the server side to angular client application using Spring web socket + stomp + SockJsClient at server side and SockJS at the angular side.</p>
  
  <p>My Socket server is a spring boot application and running on 8080 port.</p>
  
  <p>Its working fine over ws/http protocol. but now I have enabled SSL on socket server.</p>
  
  <p><strong>Socket Server configuration.</strong></p>
  
  <pre><code>@Configuration
  @EnableWebSocketMessageBroker
  public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
  
  @Override
  public void configureMessageBroker(MessageBrokerRegistry config) {
      config.enableSimpleBroker("/topic");
      config.setApplicationDestinationPrefixes("/topic");
  }
  
  @Override
  public void registerStompEndpoints(StompEndpointRegistry registry) {
      registry.addEndpoint("/sync").setAllowedOrigins("*").withSockJS();
  }}
  </code></pre>
  
  <p><strong>Working code of Java Client over WS</strong></p>
  
  <pre><code>List&lt;Transport&gt; transports = new ArrayList&lt;Transport&gt;(1);
  transports.add(new RestTemplateXhrTransport());
  SockJsClient sockJsClient = new SockJsClient(transports);
  sockJsClient.setMessageCodec(new Jackson2SockJsMessageCodec());
  
  WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
  stompClient.setMessageConverter(new StringMessageConverter());
  String url = "ws://my-socket.server.com/sync";
  StompSessionHandler sessionHandler = new MyStompSessionHandler(senderId, syncUrl, content);
  stompClient.connect(url, sessionHandler);
  </code></pre>
  
  <p><strong>Working code of angular client over HTTP</strong></p>
  
  <pre><code>const Stomp = StompJs.Stomp;
  const socket = new SockJS('http://my-socket.server.com/sync');
  this.stompClient = Stomp.over(socket);
  this.stompClient.connect({}, (res, err) =&gt; {}
  </code></pre>
  
  <p>Now I have implement SSL over my web socket server which is running on separate spring boot server. And update Protocol at server and client side like. <strong>ws to wss and http to https.</strong></p>
  
  <p>And also try following things to add SSL Context</p>
  
  <pre><code>StandardWebSocketClient simpleWebSocketClient = new StandardWebSocketClient();
  List&lt;Transport&gt; transports = new ArrayList&lt;Transport&gt;(1);
  Map&lt;String, Object&gt; userProperties = new HashMap&lt;String, Object&gt;();
  userProperties.put("org.apache.tomcat.websocket.SSL_CONTEXT", SSLContext.getDefault());
  simpleWebSocketClient.setUserProperties(userProperties);
  transports.add(new WebSocketTransport(simpleWebSocketClient));
  </code></pre>
  
  <p>I have take reference from following stack link but no luck :(</p>
  
  <p><a href="https://stackoverflow.com/questions/47430122/wss-my-domain-com-sockjs-362-4q059yw7-websocket">Secure websocket with HTTPS (SSL)</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32177803/how-to-use-spring-websocketclient-with-ssl">How to use Spring WebSocketClient with SSL?</a></p>
  
  <p>Please help me to get out of it.</p>
  
  <p>Thank you :)</p>