#Spring boot websocket integration issues

70 messages · Page 1 of 1 (latest)

mellow kindleBOT
#

This post has been reserved for your question.

Hey @ancient escarp! Please use /close or the Close Post button 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.

humble ridge
#

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

ancient escarp
#
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
humble ridge
#

that doesn't look like rejected

ancient escarp
#

It's like didn't even connected

humble ridge
#

I think the issue is that Spring uses the Stomp protocol and postman uses raw websockets

ancient escarp
humble ridge
#

Can you try using stompjs as mentioned in the tutorial?

#

Also is the tutorial using the same Spring version?

ancient escarp
humble ridge
#

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?

ancient escarp
humble ridge
#

Can you show the directory structure of your project?

ancient escarp
humble ridge
#

and ideally also show the logs

#

ideally with logging.level.org.springframework.web.socket=TRACE

ancient escarp
ancient escarp
humble ridge
#

yes

ancient escarp
humble ridge
#

Can you show the whole thing as text using a code block?

ancient escarp
#

text is too big for discord

humble ridge
ancient escarp
#

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

humble ridge
#

Can you connect to the HTTP endpoints via localhost?

ancient escarp
#

likes get and post?

#

yes

humble ridge
#

and that works with that port?

ancient escarp
#

yes

humble ridge
#

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

humble ridge
ancient escarp
#

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
    }
}
humble ridge
#

that's what I wanted to check

#

can you comment out that controller?

ancient escarp
#

so problem in it?

#

ye

humble ridge
#
  1. You cannot use forward: in @RestControllers
  2. it looks like it matches the websocket URL and overwrites it
#

so just comment it out and try again

ancient escarp
#

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

humble ridge
# ancient escarp its working

Should I vote to close your SO question as typo/nonreproducable/resolved in a way unlikely to help future readers?

ancient escarp
#

and now its working

humble ridge
#

except you are deleting it ig

ancient escarp
#

i think i can delete it if you think this no info that can help to ppl

humble ridge
#

yeah just delete it

ancient escarp
#

thanks again

humble ridge
#

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

ancient escarp
#

like logs and etc?

humble ridge
#

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

ancient escarp
#

oh, ye thx, i'll remember it

humble ridge
#

and you should also very clearly specify what your expected and actual result is as well as how they are different

ancient escarp
#

got it

humble ridge