I want to identify which response corresponds to which request in Java.
It is easy if each request has its own connection, but if many requests are sent and received through the same socket, it will become hard.
After searching the web, it seems that the solution is to add a custom HTTP header.
Since I do not have access to the server, my question is: Can I add a field to http request and have the server return the same field to me?
EDIT: To be more clear, I am writing a proxy server. So I will receive a http request and relay it to the server and do the same for the response. My question if focused on the requests that are sent through a specific socket.
Related
I'm working with californium library to use Coap protocol in my eclipse project.
I have sent a request to a server Coap.
Now i have set on this server a different end point to give response.
How can i implement an observer that listen and wait to receive this response ?
The response to an observe request must always come from the same endpoint as the request was sent to. A message from a different endpoint on that server (that is, from a different IP address or from a different port) would not be recognized by the client.
I'm pretty unsure, If I understand your question.
how can i implement a listener for response ?
On the server side? To prepare the response?
Then the intention is to override CoapResource.handleGET.
It's very annoying when you are making a simple socket server and you get an http request. Very anoying if your server doesn't support http requests. Is there a way to detect and deny http requests (from webbrowsers) and only accept tcp/socket connections?
no, because you dont know the payload a client intends to send over a socket until youve accepted the connection and read enough of it to understand its talking HTTP.
In my opinion you should think of the frustration clients are experiencing, and do 2 things:
Why are browsers being directed to your (obviously not http) service? can you stop it?
Assuming the answer to #1 above is no, maybe implement some simple detection for http requests and respond with a hardcoded http response that renders as a readable error on the browser who sent it? (yes, even though your service isnt http) - a simple detection would be take your input buffer, decode as a us-ascii string, and if it starts with one of the 9 HTTP request methods send out some hardcoded http error response. i suggest error code 402 - payment required :-)
We have a Java web service with document style and http protocol. Local this service works smoothly and fast (~ 6ms). But calling the service-methods from remote takes over 200ms.
One main reason for this delay is that the
server sends first the response http header,
the client sends in return a ACK and
then again the server sends the response http body.
This second step where the client sends the ACK costs the most time, almost the whole 200ms. I would like to avoid this step and save the time.
So that's why my question: Is it possible to send the whole response in one package? And how and where do I configure that?
Thanks for any advice.
I'm not fully understanding the question.
Why is the server sending the first message? Shouldn't the client be requesting for a web service via HTTP initially?
From what I understand, SOAP requests are wrapped within an http message. HTTP messages assumes a TCP connection and requires a response. This suggests that a client must respond when the server sends an http header.
Basically whatever one end sends to another, the other end must reply. The ACK return from you step 2 will always be present.
EDIT:
I think the reason for the difference in time when requesting via local and remote is simply the routing that happens in the real network versus on your local machine. It's not the number of steps taken in your SOAP request and response.
I have a TCP/IP socket server which send multiple response to client based on client's requirement ( like send update whenever DB has an update). client sends xml and server too respond xml.
I stumbled on Netty yesterday. I want to know whether Netty can support my multiple response server application?
Sure as long as the protocol which is used can handle this kind of message flow.
can an asynchronous web service be achieved with java spring-ws framework like how it's explained in here
basically when a client sends a request to the server for the first time, the web service on the server will callback the the client whenever it has information based on the request. so that means the server may reply more than once based on the first initial request from the client.
Suggested approach as per my experience:
Asynchronous web services are generally implemented in the following model:
CLIENT SUBMIT REQUEST -> SERVER RETURNS 202 ACCEPTED RESPONSE(polling/JOB URL in header) -> CLIENT KEEP POLLING THE JOB URL -> SERVER RETURNS 200 OK for the JOB URL ALONG WITH JOB RESPONSE IN BODY.
You may need to define few response body for job in progress. When client polls the server and server is still processing the request, the body should contain the IN PROGRESS message in a predefined form for the client. If server finished processing, then the desired response should be available in the body.
Hope it helps!