Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
Getting multiple 401 errors in console when connecting to websocket using sockjs in spring boot application

We have websocket microservice running in dev server behind gateway. Here is the code piece that am using to connect to it using sockjs.

function connect() {
            var socket = new SockJS('https://dev.my.net/api/v1/websocket/app');
            stompClient = Stomp.over(socket);
            stompClient.connect({}, function(frame) {
                setConnected(true);
                console.log('Connected: ' + frame);
                stompClient.subscribe('/topic', function(messageOutput) {
                    showMessageOutput(JSON.parse(messageOutput.body));
                });
            });

Here is the spring boot configuration for websocket :

@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig implements WebSocketMessageBrokerConfigurer {


final WebSocketHandshakeAuthInterceptor webSocketHandshakeAuthInterceptor;

@Autowired
public WebsocketConfig(WebSocketHandshakeAuthInterceptor webSocketHandshakeAuthInterceptor) {
    this.webSocketHandshakeAuthInterceptor = webSocketHandshakeAuthInterceptor;
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/app")
            .addInterceptors(webSocketHandshakeAuthInterceptor)
            .setAllowedOriginPatterns("*");
    registry.addEndpoint("/app")
            .addInterceptors(webSocketHandshakeAuthInterceptor)
            .setAllowedOriginPatterns("*").withSockJS()
            .setSupressCors(true);
}

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableSimpleBroker("/topic");
}

}

The error am getting in console :

   WebSocket connection to 'wss://dev.my.net/api/v1/websocket/app/646/x5eauxus/websocket?Authorisation=Bearer asdfghjkl' failed: 
   
  https://dev.my.net/api/v1/websocket/app/646/vmlurtte/xhr_streaming?Authorisation=Bearer asdfghjkl 401

   https://dev.my.net/api/v1/websocket/app/646/uhfyhy05/eventsource?Authorisation=Bearer asdfghjkl 401

   chromewebdata/:1 Failed to load resource: the server responded with a status of 401 ()
   chromewebdata/:1 Failed to load resource: the server responded with a status of 401 ()
   chromewebdata/:1 Refused to display 'https://dev.my.net/' in a frame because it set 
     'X-Frame-Options' to 'deny'.
   chromewebdata/:1 Refused to display 'https://dev.my.net/' in a frame because it set 
      'X-Frame-Options' to 'deny'.

Can someone tell me why am getting 401 errors ? I know its trying to use all fallback options possible to connect using sockjs .

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda