0

in my project we are using an JavaEE(CDI,Hibernate)-Backend deployed on a WildFly-Server with an AngularJS-Frontend.

Is there any simple way to push messages from within a war-file to a Javascript-Client?

Thanks.

user3133542
  • 1,695
  • 4
  • 21
  • 42
  • websockets ? do u think under this way ? In other way only client can push – Mikhail May 08 '18 at 14:07
  • Since your client is Javascript, you can set an interval to checkout (pull) the server side. – am.rez May 08 '18 at 14:08
  • Does your java EE app have a servlet? If there is a URL you can go to that produces text of any kind, you can make an HTTP request in angular to call it and get that text. – Mark D May 08 '18 at 14:12
  • Have a look at https://stackoverflow.com/a/11277751/945214 – gargkshitiz May 09 '18 at 06:17

1 Answers1

1

As you've mentioned JavaEE: Websockets are part of EE specification since version 7 - check https://docs.oracle.com/javaee/7/tutorial/websocket.htm.

The Websocket part of the spec is a bit rudimental, for example you have to implement things like topics, broadcasts or reconnect mechanisms by yourself (at least I couldn't find these functions in the specification). In case you need such functionalities it might make sense to take a look at socket.io (https://socket.io/) which can easily be integrated into Angular (https://tutorialedge.net/typescript/angular/angular-socket-io-tutorial/).

If polling (which is also implemented as a fallback in socket.io) is also an option, it's up to you what you prefer (and how complex the content should be). The EE specification is full of technologies with powerful abilities to return content: Servlets, JSF, JSP, JAX-RS, JAX-WS.

Just for clarification: Pushing or polling information with these solutions does only work when the clients have openend your web app in browser (even in background). If you also want to push information when they are not visiting your app you have to check solutions like Web Push Notifications from Google (https://developers.google.com/web/fundamentals/push-notifications/).

Hope this helps.

Jonas
  • 494
  • 4
  • 7
  • Do this way allows also publishing to multiple clients? – user3133542 May 08 '18 at 15:10
  • As mentioned above you have to implement it by yourself when using EE Websockets (JSR356). In case you use socket.io it comes out of the box and there are additional concepts like 'rooms' and 'namespaces' (https://socket.io/docs/emit-cheatsheet/). – Jonas May 09 '18 at 06:04