I need to copy the HttpServletRequest
of client1, as it is, to the HttpServletResponse
object created for client2. According to this HttpRequest
has a ResuestLine, then headers, then body.
I have copied the headers like this :
Enumeration<?> headerNames = client1Req.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
Enumeration<?> headers = client1Req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String headerValue = (String) headers.nextElement();
responseToClient2.addHeader(headerName, headerValue);
responseToClient2.setHeader(headerName, headerValue);
System.out.println("headername : " + headerName + "value : " + headerValue);
}
and body like this:
input = clientReq.getInputStream();
output = responseToRIC.getOutputStream();
if((len=input.available()) > 0){
len = input.read(outputByte);
System.out.println("len : "+len);
output.write(outputByte);
output.flush();
}
else{
System.out.println("no body");
}
However, i need to copy the request line too. If i try to read the input stream instead in the beginning instead of reading headers and body separately, it return -1.
There is no api for reading the entire request line from an HttpServletRequest
. If I read the URL using getRequestURL()
and getQuesrystring()
, where should I place it in the responseToClient2?
In a custom header REQUESTLINE
or should i write it on the outputstream?
Thanks
EDIT : since it is semantically wrong to copy a request
to a response
, i have decided to copy the request
tothe payload or body of the response
. However, since the HttpServletRequest
is not serializable, i am unable to write it on the outputstream
of response
, any suggestions as to how I should achieve this?
Thanks