send different response to ajax using executor service - java

Let's say I am making an ajax call which will get a string as a response. How will I send 3 different response to same ajax call using java's executor service?

You can't send 3 response in only one ajax call.
One request will always return one response.
To solve this problem, you can make 3 request (3 ajax) OR put all your information in your unique ajax response

Related

How can i use get request using httpClient java without get content?

I want to get request a page to set parameters using url(example.com?x=ttt&y=zzz) to reserve those in target server and then should do post request after that final. how can i do these (get request and then post request) in 1 seconds or faster way.
is there any way to do get and post together? but i should get first then post...

Java many threads to many threads relation

I have a service that gets requests from many clients and after some processing sends a response to the clients. I use a ThreadPoolExecutor (threadExecuterClient) to handle client requests and put them in a BlockingQueue (requestQueue). Many clients can send concurrent requests. I have another ThreadPoolExecutor (threadExecuterServer) that processes requests in requestQueue. This processing is basically consists of send that request to a server and get response. After processing, I need to send that response to the client which has made that request. I am having difficulties to track which client has made which request. I basically need to find a way to map the client request to the result of processing. The service will be like a gateway.
Any idea to handle this issue is appreciated.
Thanks
I assume your service accepts requests via HTTP ? Accept the request from your service and send back a HTTP 202 response. This response means that the request was accepted for processing. When you send the response, send the Location header to tell the client which URL to invoke to ascertain the status of your request. The client can poll this URL for status and a result.
The URL should contain a unique ID for each request. Your server can track that and populate a response when it is ready.

http get from jsp and resolve status code

I need to send http request to certain URL via jsp (by clicking on a link / button). Depending on the http response status code I need to generate corresponding output in the jsp (200 - action OK, 404 - unknown action etc, the content of the URL is irrelevant). Is there any way to achieve this behaviour?
I am using Spring.
First send your request to a servlet using AJAX and call the url that you want from the servlet.From that url response you can use int status = response.getStatus(); on the HttpServletResponse object in your servlet and based on the int value that you get you can write your if else statements and use PrintWriter's println method to send response/text to the ajax call on your jsp and use it wherever you want in that jsp page.
you can use jquery and make an ajax call using its ajax method and use it success/error callback methods to get textStatus

How to handle POST response using Servlet

I'm new to Java Servlet programming and have a question about how to handle POST response from other servers (not user's POST request) using Servlet programming.
Suppose my application needs to consult another server in order to process user's request. I need to
send an asynchronous POST request (i.e. specify a redirect_uri in the POST request body) to the other server;
handle the POST response from the other server;
present some result to the user.
I think I need one Servlet to handle user's request and send a POST request to the other server, and I need another Servlet (since the POST request is asynchronous) to handle the POST response from the other server. My specific questions are:
What's the best way to send a POST request in this case? For example, using HttpUrlConnection?
How to handle a POST response in a Servlet? It confused me because a servlet is supposed to handle "request" not "response" but in this case the incoming message is indeed a POST response from the other server. In particular, if you can point me the relevant API/method that would be really helpful. For example, in doPost()? How to get the POST response body? (I assume we can get it from HttpServletRequest object).
Thanks very much!
Yue
I did not understand the term 'POST Response'.However may be you are talking about servlet chaining scenario if I understood your requirement correctly.
Servlet Chaining means the output of one servlet act as a input to
another servlet. Servlet Aliasing allows us to invoke more than one
servlet in sequence when the URL is opened with a common servlet
alias. The output from first Servlet is sent as input to other Servlet
and so on. The Output from the last Servlet is sent back to the
browser. The entire process is called Servlet Chaining.
Example of Servlet Chaining

Response code from GET request to jsp page using SimpleFormController

I am trying to set up a http responder for incoming GET requests using a JSP page with a SimpleFormController.
I am receiving a GET request from a third party company, who are expecting a 200 http response back. However, even though my JSP is basically blank, when a GET request come in, it bypasses my JSP page and is automatically submitted to the onSubmit method in my controller and a http response of 201 is sent back.
How can I send a 200 response back, instead of 201?
Thanks,
Dave
If the onsubmit method is being called, it sounds to me like they are not sending a get request, but doing a post.
Make sure they are sending a get request.

Categories