I have the following scenario of integrating a third party application into my java application. The third party application is running in a different context than my java application. It provides a JSP which needs to be called with certain parameters such as authentication information based on which it generates a cookie value and sets it in the header. I need to call this JSP from my java application and then retrieve the headers from the response with the cookie value and set it to the new cookie that will be created in my application.
I was able to call the JSP using
response.sendRedirect("http://<host>:<port>/<context>/authn.jsp").
The authn.jsp was able to retrieve all values sent authenticate and generate the cookie value. It then does the
response.setHeader(attr,val).
However, I am not sure how to read this response header back in my servlet. Is request.sendRedirect the correct way to do this? Do I need to use the HTTPURLConnection class to achieve this?
You need to use the
HTTPURLConnectionto read the headers. You cannot useresponse.sendRedirect(..). Once you have received the headers, you can setresponse.setHeader(attr,val)in your code.