Websocket Postman
I just wanted to check if someone notice anything wrong in my code.
Basically, what I want to do is that when a new user registers, I want the admins to be notified with "New user has been registered", but I want to do it in real-time using WebSocket.
I'm testing my WebSocket URL ws://localhost:8080/ws, and I successfully connect to it. I also subscribe to the destination:
which works fine. But when I register a new user, I don't receive the message in the destination, even though I see it in the terminal 😅 hahaha.
It's weird, but I just wanted to check if someone notice anything off.
WebsocketConfig
NotificationService
AuthService
121 Replies
⌛
This post has been reserved for your question.
Hey @Itsurran! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Anyone please 🙂
wazaaaaaaaaaaaaaaaaap
How you doing
great
show the code where u
register to endpoint
’’’java
@PostMapping("/register")
’’’
This message has been formatted automatically. You can disable this using
/preferences
.Ugg I’m on my phone
no no
oh
you use postman
wait let me ask
yea for my endpoints
hmmmmm
r u sure ur listening to the correct destination on postman
As you can se on this picture
You can se the terminal that the user registartion has been registered but im not getting back any message
th
so
in my app
on the frontend
to listen to the
channel
i had to do
and to listen to the port
yes, that is the connection but since i want to land on a destination for example in my case notifciations where admins can see that there has been a new user registered then i should do this
that should be ur example
url
try that
cant connect
yea but you need to use your
actual destination
if ur using some other
ip
wym
oh
nvm
we need danial in here is a pro :JoyStroke:
yea call his sudoness here
say 'your sudoness we have been awaiting you'
:GnuTrolling:
@dan1st :/ sry for pining you
but you gotta be involved
test
ok Discord seems to somewhat work again
seems like they have an issue with Google Cloud
at east accessing Discord results in a Google Cloud error
upstream connect error or disconnect/reset before headers. reset reason: overflow
me 2 couldnt load servers
yes ik it's a Discord issue
Postman Docs
Create a WebSocket Request | Postman Docs
Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.
for Websocket requests
specifically that thing
yh i have
Can you expand these things?
oh i was just testing with different SUBSCRIBE but this is the right one
oh i meant here
looks fine so far
right
but someone is not sending me the message to that destiantion
maybe postman api is just bad
for websockets
anywhere else to try?
use a proper client
like the actual client that is supposed to connect
You mean a frontend?
for it
for example - I assume you already have one?
Not yet, doing backend first
ah ok
apis, logics etc
then starting with client
Well, what is supposed to happen?
lemme se if there is plugin in intellij for websocket
So when a new user registeres i want the admins to be notified in real time that theres a new user registered
so you have the websocket connection where the admin is supposed to be notified? Just try to register a user and see what happens?
Also use a debugger to see what's executed on the Java side
Is there any way an admin authenticates themselves on the websocket?
i mean im prolly gonna use websocket for alot of things but its nice to have every detail
(before being allowed to receive events)
No not yet, can it be that?
so you are automatically sending the events to all connected clients?
Do you have a listener or similar for incoming websocket connections?
Yes but they are gonna be specifc to admins only to connect
Nope
What stops a non-admin from connecting?
then maybe create one and see whether it's called
Alright 1 sec
Are you using STOMP?
yes
ok that's not normal websockets - that's something built on top of websockets
so just connecting via postman doesn't make you get the events
I think
actually nvm I think that should work if the URL is correct
like this is the only code i have right now thats connect for websocket
and
little bit here at authservice
is the
logger.info("Sending WebSocket message to /topic/admins: {}", message);
printed?
yeah I think you need to do something like thatthis happens when i start the project without connecting
What happens when sending the SUBSCRIBE message in postman?
weird right?
Where does that come from?
from my authservice
just to log
you see the arrow/caret on the right? What happens when clicking it?
it folds the message
ah so it happens when the user is registered
yes
that message only comes when the user is registered
Are you using Spring Security?
yes
Can you show the config?
absolutly
I assume the
.requestMatchers("/**").permitAll()
is just for debugging?yep
but gonna strict all of these later
with @HasAuthorize etc
I personally prefer restricting them in the security config but your choice how to do it
yh i will se that later just wanted to get webscoket up because ive had problem with it alot
Can you try something like this? https://stackoverflow.com/q/49980319/10871900
Stack Overflow
Send message to client on connect via Spring Websocket
Okay, I have practically read every single stackoveflow post on spring websocket.
I want to send a message to a particular client once it connects to the server, simple!
I have been able to connect
and also log something there
For example
What about this
you can also try that if you want to
or both
so adding
might do something as well
I'd just try both and see what happens
so add them, try subscribing from postman and check for a response - and also check the logs from Spring
Same results
as the picture i sent
this is weird
wanna try urself? i can send u the zip and just add a new db in application.properties
mby its my postman
😂
so no logs in Spring?
Then I guess your subscription message is incorrect
like i only get this
User registered: John Doe
2025-02-04T23:04:49.951+01:00 INFO 33732 --- [nio-8080-exec-3] NEMportal.service.NotificationService : Sending WebSocket message to /topic/admins: New user registered: John Doe
2025-02-04T23:04:49.954+01:00 INFO 33732 --- [nio-8080-exec-3] NEMportal.service.NotificationService : WebSocket message sent successfully!
WebSocket message sent for user registration!
when i register a user
You could try creating a new HTML page with very little JS that just uses stompjs to subscribe
Are there any logs when subscribing?
no logs
I am not talking about the user creation but the subscribing thing
nope
And you added both pieces of code to your project?
Can you show the directory structure of your backend?
i.e. the folders and files, specifically Java files
ok
yeah try it with Stompjs or similar
cant even connect
and thats a frontend problem :/
ugh
why this gotta be complicated
Can you check the network tab?
Does anything appear in the network tab when attempting to connect?
yes
Can you show the messages tabs of the individual requests there?
Did you press the button multiple times?
yes
ah ok
can you show the messages tab?
in the devtools
If postman doesn't work, you can use the HTML page instead of postman xd
nothing
Does the "Response headers" show anything there?
nope
nothing
Can you show the JS?
I feel like you might have done something weird with the URL
it's simple connection
hahahah like what?
I'm telling you, i can send you the zip of the code and you just run it and see. Maybe its my shit thats not working 😂
So what we thinking, the next move 😦
Should I create another destination and something else just to try?
idk about setting it up like that - if I were, I'd create a new project and add all the necessary stuff myself
I guess
stompClient = Stomp.client("ws://localhost:8080/ws");
instead of the thing with WebSocket
and Stomp.over
results in the same error?
or stompClient = Stomp.overWS("ws://localhost:8080/ws");
lemme try
1 sec
got it working
@dan1st
What was the issue?
The backend or frontend/Postman side?
first i tried ur way then it say origin not allowed and i added the origin and some stuff on corsfilter and it worked
then I guess the backend works perfectly fine and it was just postman
because CORS restrictions are specifically for web browsers
yep got it
alright guess backend works perfectly
maybe you made a typo in postman or whatever
btw I wouldn't even have made that much stuff in the HTML page - I would have just logged the things I needed to the console and always change in the page what I currently need to test lol
or just write automated tests in Java
Never done that 😮
in school we only learned postman and html tests l0l
something similar to https://rafaelhz.github.io/testing-websockets/ I guess
I also never properly worked with websockets lol
hate it
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.