two way webservice communication REST - java

G'day folks, So I have an application in mind with a client-server architecture where multiple clients are connected to a web service. The webservice needs to be able to call or send messages to all or some of the clients. I have previously done the same using SOAP based services in WCF but now I am working with java and wish to avoid SOAP. I have been experimenting with Server Sent Events in reactive framework in Spring framework but have been mostly unlucky.
Is there a way to implement two way communication without explicitly exposing a webservice or such on the client? thanks a bunch :)

Try WebSockets for two-way communication and simple Restful for request-response communication.
Here is a simple guide: http://www.baeldung.com/java-websockets

Related

Business logic in java websocket endpoint/JAX-RS?

What's the best practices for implementing business logic in a web-application that uses a Websocket connection? specifically, how to use a Java websocket endpoint effectively to implement services and functionalities of the system?
Does the websocket endpoint replace Java web-services (JAX-RS) functionality entirely?
WebSocket is not a replacement for JAX-RS.
Both technologies have their usecases; if I were you, I would do my research before asking questions like this one.
The first question is about the business logic - and that always depends. You can adapt in some way MVC patter when dealing with JAX-RS, since there is a tight connection between Http Request and Response and you can even use some templating engine to process your output (Jersey - JAX-RS RI - contains pre-built support for this scenario). WebSocket is very different in terms of data processing, there is one "persistent" TCP connection which you can use to transmit messages from/to either side, which usually requires different programming model and typical usecase would include sending/receiving short status update messages to some interactive front-end (javascript) application.

Rest vs SOAP with regards to WSDL

I'm not completely clear on one thing and am hoping some one here will probably answer this.
I worked on an enterprise application where we had a Java app consuming services with a WSDL interface in between and a .NET application on the other side producing the services.
I have been reading RESTful webservices where jersey API is used to route a request through a jersey servlet to an URI that eventually talks to a Java class to send the data back.
I'm not able to understand the point where diverse applications like .NET and Java can talk through a REST interface and how for this particular scenario Rest is useful.How does Rest work in this case?. for SOAP there is WSDL, what about for REST assuming a Java app is consuming from a .NET through a Restful service. Please explain how it works.
Thanks in advance!
Both REST and SOAP use HTTP for communication. Requests are sent over the wire using the HTTP protocol from client to server. The server replies using the same protocol. As long as the client and the server both send information using HTTP, it doesn't matter what language the client or server are written in.
RESTful APIs may use some combination of WADL, HATEOAS, and documentation to reveal their API to clients.

Consuming Java RESTFul web service with PHP client

I am having some problems developing a PHP client that will consume Java RESTful services, created in NetBeans 7.1.1.
For those who don't know: When you create a Java RESTful web-service based on MySQL database (entities), NetBeans will create, automatically, the entities class, and each entity "facade", that can be known as a service provider.
I developed a web application using Java RESTful web-service server and the Java RESTful client that consumes the web-services through Jersey & Servlets.
Now on to a planned PHP client: I already googled a lot, and what I see is: no interoperability (or i'm "the" noob), which is one of the purposes of web-services. I know how to create a RESTful web-service in PHP, and communicate with a PHP client, and the same with Java, but what I want is create the Java RESTful web-services server, and a php client.
Sorry if I said something wrong on the subject, and feel free to correct me.
If anyone could help me, giving me some ideas, code examples, explaining the "know-how", I would appreciate a lot.
This is rather an easy problem to solve. For an enterprise application, I have modeled this same solution. The Java layer has CXF restful web services mapping to a mixture of SOAP endpoints (external systems) as well as entity objects (mapped via Hibernate/IBatis). Consuming the CXF rest layer is rather simple. In PHP, I would definitely recommend using the Guzzle client.
/** USE REST SERVICES **/
$client = new Client("http://example.com/);
$locationRequest = $client->get('/someservice/rest/location/findstatebyzip.json?zip=12345');
$locationResponse = $locationRequest->send();
$locationResults = json_decode($locationResponse->getBody());
The great thing about Guzzle Client is that you aren't required to have CURL enabled/installed, it can use other transport mechanisms.

WCF web service and java web service

Can web service developed in Java can be consumed by WCF web service and vice versa.??
Yes, Web Services are basically request/response calls through a network. The message is XML. This protocol is known as SOAP (Simple Object Access Protocol). So, you're passing XML data across the wire. WCF wouldn't care less which originating language it comes from as it only sees XML.
Alternatively, you can use HTTP request/response using REST.
Yes they can, if you run into trouble and are using SOAP it will most likely be due to versions in the security headers. If so you WCF can be configured to use custom binding (Sure the same applies for java side). Rest is simpler.
Checkout http://www.soapui.org/. It is written in java and can communicate using both Rest and Soap.

Web Services vs Messaging

What kind of arguments one should use when choosing between integration using web service vs JMS? I'm familiar with basics of both approaches however in some cases it is unclear as to which one would be the best for a given situation. I guess I'm looking for a high overview comparison with use cases.
thanks
JMS is a messaging service. It is asynchronous and 2 directional, i.e. you can write application that both sends and receives messages. But this must be application implemented typically in java. I mean it cannot be thin client. And standard protocol of JMS is TCP based, so it may be blocked by firewall.
Web service is designed as a transport over HTTP, so it typically passes firewalls. But it is one directional: client calls server; server cannot call client. It just can response client's calls. Client of web service (especially RestFull web service) is very simple, so it can be easily implemented as a thin client (e.g. AJAX client).
Good question.
I will use Web Service when:
1. Dealing with cross domains, typically services environment when I am not sure about the client technology.
2. Need Synchronous response.
And pickup Messaging when (Hope you mean Messaging not just Java version):
1. Need Asynchronous request/response.
2. High Availability.
3. Confirmed Delivery.

Categories