java - Websocket in Spring Boot app - Getting 403 Forbidden -
websocket in spring boot app - getting 403 forbidden
i can connect websocket client using sockjs/stompjs when run in eclipse (no spring boot).
but when create spring boot jar(gradlew build) websocket code , run java -jar websocket-code.jar 403 error connecting websocket.
i have no authentication websockets. have cors filters , think have headers right in request/response.
below build.gradle
apply plugin: 'java' apply plugin: 'spring-boot' apply plugin: 'war' sourcecompatibility = 1.7 version = '1.0' repositories { mavencentral() } buildscript { repositories { mavencentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.release") } } configurations { compile.exclude module: "spring-boot-starter-tomcat" } dependencies { compile "org.springframework:spring-web:$spring_version" compile "org.springframework:spring-webmvc:$spring_version" compile "org.springframework:spring-websocket:$spring_version" compile "org.springframework:spring-messaging:$spring_version" compile "org.springframework.boot:spring-boot-starter-websocket" compile "org.springframework.boot:spring-boot-starter-web" compile "com.fasterxml.jackson.core:jackson-databind:2.6.2" compile "com.fasterxml.jackson.core:jackson-core:2.6.2" compile "com.fasterxml.jackson.core:jackson-annotations:2.6.2" compile "org.springframework.amqp:spring-rabbit:1.3.5.release" compile("org.springframework:spring-tx") compile("org.springframework.boot:spring-boot-starter-web:1.2.6.release") compile("org.springframework.boot:spring-boot-starter-jetty:1.2.6.release") testcompile group: 'junit', name: 'junit', version: '4.11' testcompile "org.springframework:spring-test:$spring_version" } task wrapper(type: wrapper) { gradleversion = '2.5' } update:
added cors filter response.setheader("access-control-allow-origin", "http://localhost:8089");
in firebug on client side
request headers origin http://localhost:8089 response headers access-control-allow-origin http://localhost:8089 server logs 2015-10-02 16:57:31.372 debug 1848 --- [qtp374030679-14] o.s.w.s.s.t.h.defaultsockjsservice : request rejected, origin header value http://localhost:8089 not allowed origin requesting in allow-origin list. still getting request rejected message in logs.
i had similar issue , fixed in websocketconfig setting allowed origins "*".
@configuration @enablewebsocketmessagebroker public class websocketconfig extends abstractwebsocketmessagebrokerconfigurer { @override public void registerstompendpoints(stompendpointregistry registry) { // endpoint websocket connections registry.addendpoint("/stomp").setallowedorigins("*").withsockjs(); } // remaining config not shown not relevant }
Comments
Post a Comment