Spring Web Socket Java Client - java

How to Write a Java based Spring Web Socket (STOMP) Client. As in Spring we have only javascript based client is provided using stompJS but if we need a java client how should we need to achive it?

Spring 4.1 introduces a SockJs Java Client which is quite useful for server to server communication and performance testing. It doesn't come with a Stomp client (this is certainly in the roadmap) but you can check out the tests in the sample app which has already an implementation. Seems this is what you are looking for.
Update 8 Sep 2015:
Spring 4.2 has a STOMP Java client which can be used along with the SockJS Java client. More: https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/htmlsingle/#websocket-stomp-client

I would look for websocket clients in Java and build off of those. It seems that Jetty has a websocket client api as does too tall nate.

Related

XMPP - Spring Integration: Does the spring application run an embedded XMPP server

I'm trying to integrate instant messaging in my application that is based on the usual Spring-Maven stack. Two possibilities that I've come across are to either use raw Smack (igniterealtime.org) or go for the spring-integration support for XMPP (which is also based on Smack). My question is; "Is it required to run an XMPP server like openfire alongside or is there a possibility of the XMPP server running embedded within my application running on tomcat?". What would be an efficient scheme for the scenario? Thanks
The Smack (and therefore Spring Integration XMPP) is just an API (Client) for that protocol and what you need to know and configure is XmppConnection and particular host/port to connect.
To right an application based on those component you don't need to run an XMPP server.
For example we tested Spring Integration against regular Google Chat.
So, yes: Spring Integration doesn't run Embedded Server and even doesn't require an external to be run for you locally.

Connect with iOS and Android clients to SockJS Backend

I'm developing WebSocket messaging backend using Spring WebSockets, which uses SockJS + STOMP protocol. The reason why not to use plain WebSockets is because I will need to leverage security integration that SockJS provides in Spring WebSockets and also other neat features from SockJS, such as rooms, subscriptions, etc. I was wondering if this is a good option to use so that mobile (iOS and Android) and Web client apps can easily connect to the backend server and perform messaging. If yes, then what libraries I can use for iOS and Android.
On SockJS GitHub page they are also listing available client libraries, but no iOS nor Android. So, I'm wondering if SockJS is even worth to use just because of that.
I found that for iOS client Primus-Objc (GitHub page) library claiming that they can connect to native WebSockets, Socket.IO, SockJS or perhaps engine.io. is that a true statement? And event if that's true, what about the quality of that library?
And event if it is ok to use SockJS on the back, then would it be also possible to show an example code for iOS and Android so that I can perform a proof of concept on mobile devices?
If SockJS is not a good option for me, then would it be better than to build my messaging app with Socket.io + Node.js (using JavaScript). Socket.io seems to me have all needed client libraries for iOS (official library by Socket.IO guys) and Android (official library by Socket.IO guys).
Another option can be to use Netty-Socket.io library and build each endpoint manually without any help from Spring Framework (which I'm considering to use) but there is small challenge that I'll have to tackle, that is security. Somebody actually already tried to do it (the same author asking question on the official Netty-Socket.IO Github page) but looks like he didn't have a luck in solving it yet.
Maybe it's more than a year since the question was asked. But, because it's getting in the first results when Googling for SockJS+Android. So, I am posting my answer.
From my experience with a recent project I worked on, we were able to use a STOMP client - like the one here- to connect to Spring Websocket backend from native Android app.
And from the browser, you can still use SockJS client to gain across browsers compatibility to websockets with fallback.
A note to mention that when using only STOMP client to connect to native websocket the URL will be something like ws://mydomain/SockJSEndpoint/websocket,
and when using SockJS client from the browser the URL will be like http://mydomain/SockJSEndpoint.
Please find below useful references related to your requirement for both iOS and Android
http://www.elabs.se/blog/66-using-websockets-in-native-ios-and-android-apps
https://www.cometchat.com/blog/ios-android-chat-mobile-sdk/
https://github.com/elabs/mobile-websocket-example
We have tested them, both Android-client (link) was given by #Amr K. Ismail and
this iOS-client (link) are suitable with Spring-SockJS-Server which has STOMP.
SockJS may be interesting because it provides non-ws transports. Just using WebSockets may not be possible in all situations.
There is one cross-platform SockJs client of the OpenFL project:
https://github.com/jeremyfa/openfl-sockjs
Not tested how well it works, but at least for Android it's using JavaScript from inside WebView, so should be no different than JavaScript one. Again, it is not clear how tightly it is coupled with OpenFL, but the approach of using WebView and stock SockJS client could probably be re-used.

Spring STOMP Java client and server pub/sub topic

I am looking for an example or code snippets on using Spring's STOMP topic pub/sub messaging, with both the client and server in the same tomcat7 instance. NOT OVER THE WEBSOCKET.
We want to handle some operations asynchronously in our server side and so want to use STOMP as our messaging protocol in our tomcat7 instance. Everywhere I look I find samples for STOMP over websocket or integrating with other MOM's!!
Anyone know about a java sample for simple spring stomp pub/sub? Appreciate any pointers...Thanks.
Have a look at the Spring Websocket Portfolio application. Yes, I know you said not over websocket, but the application has some tests that use a STOMP client/server that might just be what you are looking for.

jetty WebSocket custom events

I am new to WebSockets with jetty, before I have used node.js together with socket.io to create a WebSocket Server. But due to different requirements I will have to use a java WebSocketServlet/WebSocket and was doing well so far using maven, jetty and the jetty-websocket plugin. My problem is, that I donĀ“t found anything what was comparable to socket.io's socket.on(event, fn) implementation for the java solution. I would like to have the same possibility to react on different events fired from the client like "new", "addthis", "jointhat", ... send with some data as json or as POST param in the body. Is there any possibility or WebSocket Implementation which could do the same as socket.io?
Doing this "channel" stuff where I can implement the eventhandling on server side?
There is no custom event in WebSocket spec, and socket.io just follows their own protocol supporting custom event - https://github.com/LearnBoost/socket.io-spec
As far as I know, there is no Java implementation supporting custom event listening.
However, with Atmosphere, you can use socket.io client with Java web server, but I have not tested. https://github.com/Atmosphere/atmosphere/wiki/Getting-Started-with-Socket.IO
You might want to use other library in the client side like the jQuery Socket, if you want to control Jetty's WebSocketServlet directly. - https://github.com/flowersinthesand/jquery-socket/tree/master/samples/jetty-ws
Jetty's websocket implementation is only concerned with handling the basics of websocket.
Binary Messages (with fragmenting)
Text Messages (with fragmenting)
Ping / Pong
Close
There's been some brief discussion on supporting various new websocket subprotocols (odd name), such as WAMP (websocket application messaging protocol). But those would just be built on top of the basic websocket layer.
Another choice is to use something with a full channel api like CometD and just configure it to use websocket and not fallback into older communication formats.

Jetty And Netty integration

I want to build a nio based java web server. Jetty is light weighted java server and Netty is an asynchronous event-driven network application nio framework. can any one help me to integrate this two?
You could build up your own webserver by using only netty.
See the examples for this:
http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/http/
Finagle, you can easily, and within minutes, spin up a Netty based web server using Finagle. Finagle is an open source project by Twitter.

Categories

Resources