My client is running on a Tomcat server and I do not have access to the client code. So I have to build this server to process requests from the client. For this I am reading on a port as a bytestream as follows:
ServerSocket ss = new ServerSocket(8999);
Socket s = ss.accept();
InputStreamReader in = new InputStreamReader(s.getInputStream());
cbuf = new char[buf_length];
int char_read = in.read(cbuf,0,10000);
inputLine = new String(cbuf);
I am supposed to get SOAP POST requests from the client and these I am able to handle but in between these client requests, I am getting a GET request which looks as follows:
GET / HTTP/1.1
User-Agent: Java/1.6.0_21
Host: localhost:8999
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
So the user agent is not the client(its probably Tomcat) and it accepts everything. So my server code is unable to handle this. So I tried closing the socket, reopening and trying to read but it reads the same GET request again.
Do I need to send a particular response for this request to continue my program so that the client then is able to send me the next request?
Thanks
If you really mean that the problem is that you can’t respond with any of the types listed in the
Acceptheader, then the correct HTTP response code is 406. You construct an HTTP response with this status code, send it, and close.But, what do you mean you can’t handle it? Because the request says it will accept anything!
As to what the client will do in response to a 406, well, it’s up to the client. It will retry if it wants to retry, though it shouldn’t in response to a 406 with the same
Acceptheader.You’re not even clear on what is making requests to you (it’s not Tomcat) — surely that’s most of your problem here, right? Figure that out. Then you can figure out what you are supposed to be doing.