How to create a websocket server using spring boot? - spring

I am trying to create a websocket server using spring boot and I find it very tricky. I have followed multiple tutorials but I keep failing.
For instance, I followed this tutorial https://spring.io/guides/gs/messaging-stomp-websocket/
I did everything exactly like it was described there. However, when I start the server and access the generated UI and try to connect to the server, I get
WebSocket connection to 'ws://localhost:8080/user' failed: Error during WebSocket handshake: Unexpected response code: 404
It's very unclear to me why it would try to connect to /user if I haven't even defined such endpoint.
When I try connecting through Postman to the address "ws://localhost:8080/gs-guide-websocket", I get the 400 code. No logs in the spring console.
Any hints/advices on how to make a simple websocket server using spring boot? Literally, every tutorial that I follow on the internet, doesn't work.

Related

Not able to Intercept websocket client request using #Webfilter in quarkus

I am migrating an application from thorntail to Quarkus , so I faced an issue of intercepting the websocket client request but same works fine in thorntail.
I am trying to intercept the websocket client request with #WebFilter but seems like it is not picking up the websocket client request , but it works fine with rest client .
Any Suggestion around this would be helpful.

Calling a POSTMAN Mock Server from IIB

I have been trying to call a mock server I made on POSTMAN from IIB flow that I deployed on local. But I am getting java.net.UnknownHostException: 77735a12-4076-4e16-af64-79f0f9b70b61.mock.pstmn.io I have tested the mock server after creating it, it works fine. But this time I am trying to hit it from outside POASTMAN. Do I have to include CORS headers here?

Application on Cloud Foundry

I am using Cloud Foundry and I deployed my Spring boot application on Cloud. I have bound the Mongodb Service with my application. When my application is trying to read the data from mongodb I am seeing below error.
Query failed with error code 13 and error message 'not authorized for query on cfe5cb4d-2ca8-40f3-9f83-0cc8321e8c19.ACCOUNT_DETAILS' on server IP:Port
At the same time when I am connecting to this db with application deployed on my local systems its working fine.
Please help me if I need to modify anything here in Configuration to make the application on Cloud work ?
I think you should check your VCAP_SERVICES, probably locally you are using the connection parameters directly but on Bluemix you have to use VCAP_SERVICES parsing.
Please if possible, copy and paste the code section used to connect to MongoDB.

no mapping found for /info Spring 4 websockets

In spring controllers if I use #MessageMapping it is working, but if I changed to #Requestmapping(value=="",method=RequestMethod.POST) and try to use SimpMessagingTemplate to send the messages to client then it is unable to connect, it is showing error in
connecting to websockets /info request mapping not found
I recognize /info from SockJS. Are you using it on the backend?
In my configuration, I have a STOMP endpoint at /stomp and use SockJS on the client side to do the WebSocket connection. SockJS makes a request to /stomp/info first to figure out what kind of connection to make.

401 Authorization Required on REST client

I am trying to write a very simple REST client using RestTemplate and Jackson JSON.
Tried such sample from spring.io Getting error 401 Authorization Required even on localhost or even if I include it into the same Tomcat6 Eclipse project where that REST WebService is running.
We don't require any authorization on that Web Service while in Dev or local environment,
and anyway I am an authorized user.
Is that something enforced by Spring RestTemplate?
Running client as Java application on Java 1.6.
I am new to REST and JSON.
No there is no enforced Authorization required by Spring's RestTemplate. You should be able to build or launch an example simple REST webservice and send requests to it with RestTemplate without receiving this response, so either the server you are sending the requests to or something inbetween is returning this response code. Can you share any more details of the service you are communicating with? Is it something internal or a public API which may require Authorization?

Resources