We have a web application that is using client service model. We are using SOAP Client and Soap Service.
Technology and architecture of current application -
We have a WEBEAR it is the client.Request comes to WEBEAR.
2. We have ServiceEAR, it is service side Request goes from client to this service.
This is developed using SOAP webservice (JAX-WS).
Now at the time of login I am taking location value from the user and save it to the session, since session is available only in client side and I passing location in every service request. I want I pass location in service side at once at the time of login when session starts and it remains throughout the session I don't need to pass the location again and again with every service request.
Please suggest some solution/framework/architecture.
Related
I have rest client API accessing data through /read endpoint from my server. However, I have an internal batch service that calls my server's /write endpoint which updates the data. So from time to time the data from the server gets updated. How will I tell the client that the data is updated and ask it to call the /read endpoint again to get the latest data?
Below is a highlevel diagram on the scenario.
Try learning webhooks? Basically, the client will "subscribe" to your webhook, or to make it easier, the client will provide an endpoint to the server. Whenever there's an update, your server just sends a request to the client. The client should simply call a service that, whenever it receives a request from the webhook, fetches read.
It basically goes like this
Client subscribes to server
The client gives the server an endpoint /updateAvailable
When there's an update, the server sends a request to client's endpoint /updateAvailable
'/updateAvailable' invokes a service that calls on '/read'
The '/updateAvailable' endpoint could invoke a service that updates content. Let's say the request sent has a parameter
{
"updateFound":true
}
So whenever the client's '/updateAvailable' is called and receives a request, you do something like this (pseudo code)
if (updateBody.updateFound.message=true)
then call read()
Edit
By creating an endpoint for client, you can also do automatic updates. So client has an /updateAvailable endpoint. The server sends the update to the /updateAvailable endpoint, which from the client side invokes whatever service is used for /read
There are two solutions for your question:
Using timer on restful client to request to restful server in every N seconds/minutes... However, it's really bad idea because it has to request to server many times even though there's no updated data.
Using third party publish-subscribe-based messaging protocol solutions to implement push notification feature whenever there is new data updated. These solutions are: Google FCM,MQTT,AMQP
I have a RESTful web Service that provide function of returning some data whenever a client send GET requests to ask for it:
#GET
#Path("/{deviceId}")
#Produces(MediaType.TEXT_PLAIN)
public String getDataResource(#PathParam("deviceId") long id){
return dataService.getData(id);
}
And the flow for this case would be the client sends request -> the web service returns value. But I want to ask that is it possible that the web service will automatically send response to the client when ever it has new data change inside of it? That means it not need to wait for the client to send request to ask for it. Because I would like to establish a communication between a client and some services running on an Application Server so that the client can always receives the newest data from the Application Server, so I think RESTful web Service can be a solution for it. And in oder to be ensure that the newest data will be transfered to the client side, so the server has to send to the client, not wait for the client to ask for it. Is RESTful web service provides any function like this?
Thank you all!
Is RESTful web service provides any function like this?
No. Not in the context you're asking for.
As answered before, the client could periodically poll for updates on the server. This is usually common option.
Another option - the original server posting updated on the "client". The client then becomes server itself. Viable, if you can expose services on the "client" side.
Maybe what are you looking for are web sockets. It is a long-lasting connection from client, where the server could keep returning data as they come.
There are some books around but you could search the net for more resources depending on the framework you use
You can implement notification system(observer pattern), so that client will poll the server in certain interval and any state change, it can get the result.
You may use the Schedulers to push the data to the client in a certain intervals.
I am currently trying Java Jersey 2.23.2 for my restful service
When both of the web client and tomcat web service runs on the same device, The session was handled perfectly.
However, when the an external client (another website) that runs on a different machine, there will always be new session introduced after an API call instead of sticking to just one session.
Is there anyway I could let the external client to call the webservice just like the local client does?
I can assume that your remote client does not care about JSESSIONID cookie. When session created, server sends HTTP header Set-Cookie with it.
Client must take it and then send it back with each subsequent requests.
All browsers do it automatically.
But as long as your client is another service it needs to care about it.
Node server is applied by our front-end to deal with request from user's browser, and then get data from API served by jetty. It has been validated that all works well when client call API directly. However, we need node server to precess some front end logic. But APIs depended on session will failed when all requests are from node server.
To be clear, the request tracing would be:
client(browser) <==> node server <==> API (jetty web server)
For example, one of our APIs captcha service (based on Kaptcha) needs to set generated image into HttpSession in HttpServletRequest. and all requests would be considered from the same point with the same sessionId caused by the forwarding of node server.
The business logic is, when captcha is required, javascript in browser will call node server and then call API server to get captcha.
Jetty would think all requests from the same client(node server) and the sessionId will be always same, service would keep the last captcha associated with sessionId, however the original requests are from different users. When more than one users access our website, some of them will fail.
Thanks a lot for your time reading this, so is there any way to distinguish the different source from my API without removing the node server?
Thanks again.
I have 2 web services - created with Java Servlets. The client app sends an XML to Web Service A. That service takes the xml and sends it to Web Service B. The Web Service B should respond with a body to my Web Service A, but how can I send that response to the client?
If this is a quick synchronous transaction (round trip), The client's call when it sends file-A.xml to the WSA can be held until WSA receives a response from WSB, and send it as part of it's response.
In an asynchronous case, WSA would need to communicate with the Client if it is able to call it, or perhaps store the response, and wait for the Client to retrieve it at a later time. This may involve the Client polling WSA in case the WSB response is not available yet.