#Spring boot websocket integration issues
70 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @ancient escarp! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
What exactly happens when connecting via websockets? Is the connection rejected? Any error anywhere? Where are you connecting to and how? Does it not like the path?
Please also show the how you do it in postmap
And it's probably also a good idea to edit your question and add it there
literally just use ws://[ip]:[port]/[that url from tutorial]
And it's just rejected, but when I'm doing the same but with launched final tutorial project everything is fine and it's connecting
Error: Unexpected server response: 200
Handshake Details
Request Method: GET
Status Code: 200
Request Headers
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: Xogi5djhhRgL605D7e63Lg==
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Host: 26.254.32.113:8090
Response Headers
Vary
0: Origin
1: Access-Control-Request-Method
2: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: text/plain;charset=UTF-8
Content-Length: 19
Date: Sat, 11 Jan 2025 20:49:16 GMT
that doesn't look like rejected
It's like didn't even connected
I think the issue is that Spring uses the Stomp protocol and postman uses raw websockets
But postman is connecting when I'm using project from tutorial
that output literally tells you that the server responded with something wanting to use websockets
Can you try using stompjs as mentioned in the tutorial?
Also is the tutorial using the same Spring version?
Tutorial 3.3.0 mine is 3.3.3
I did try but js is printing "cant connect to websocket" in console
ok so it seems like the server gives you an HTTP response
Can you show the exact thing how you are doing it in postmap?
Did you do the JS part using stompjs?
Ye, wait a minute
Can you show the directory structure of your project?
Yes, exactly stompjs
and ideally also show the logs
ideally with logging.level.org.springframework.web.socket=TRACE
Is it from application.proporties?
yes
Can you show the whole thing as text using a code block?
Is that your local IP?
well actually it's my radmin vpn ip, but i also tried to change to localhost but it didnt work and project is working perfectly fine w vpn ip
expect websockets
Can you connect to the HTTP endpoints via localhost?
and that works with that port?
yes
Are there any logs printed when making the websocket request?
Can you try making a GET request to the websocket URL?
just to see what happens
ok there's definuitely something configured incorrectly here
its bc of homecontroller
@RestController
public class HomeController {
@RequestMapping("/{path:[^\\.]*}") // Match all paths without a dot (e.g., /something but not /api/something)
public String redirectToReact() {
return "forward:/index.html"; // Forward to React's entry point
}
}
- You cannot use
forward:in@RestControllers - it looks like it matches the websocket URL and overwrites it
so just comment it out and try again
gosh
its working
first i tried it get me this
2025-01-12T01:02:53.486+03:00 TRACE 10356 --- [RpMap] [113-8090-exec-3] o.s.w.s.s.s.WebSocketHandlerMapping : Mapped to HandlerExecutionChain with [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@7674f9d4] and 1 interceptors
2025-01-12T01:02:53.486+03:00 DEBUG 10356 --- [RpMap] [113-8090-exec-3] o.s.w.s.s.t.h.DefaultSockJsService : Processing transport request: GET http://26.254.32.113:8090/gs-guide-websocket
and i desabled sockJs
Should I vote to close your SO question as typo/nonreproducable/resolved in a way unlikely to help future readers?
and now its working
except you are deleting it ig
i think i can delete it if you think this no info that can help to ppl
yeah just delete it
thanks again
btw when asking questions like that on SO in the future: You have to provide a minimal reproducer
like everything necessary to reproduce the issue
for reasons like that
like logs and etc?
the main important thing is that you provide everything necessary to reproduce it on a new project
So before asking a question on SO (or before clicking on the post/submit button), you should create a new project, paste all the files from your question there and check whether you can really reproduce the issue with only the information in your question
oh, ye thx, i'll remember it
and you should also very clearly specify what your expected and actual result is as well as how they are different
got it
My template for it is
Please [edit] your question to include a [mre] so that readers can run your code to answer your question. This should include everything necessary to reproduce the issue you are having on a new project but not more (if something isn't necessary for reproducing the issue, please don't include it).