Link to home
Start Free TrialLog in
Avatar of aturetsky
aturetsky

asked on

passing info in the header to different app

I have a servlet and would like to pass some info in the header to a different app (it's actually a perl application).

I can't use something like this, since this I have a fully qualified url for where I want to send it to - it's not prefixed by "/" since it's not in the same app:

RequestDispatcher rd=request.getRequestDispatcher("/JSPLogin.jsp");
                  rd.forward(request,response);      

What should I do?
Avatar of koppcha
koppcha
Flag of United States of America image

you mean you want to call a perl application from the servlet ?
use getRunTime();
Avatar of aturetsky
aturetsky

ASKER

No... I don't want to run a perl application I would like to completely transfer from a java servlet to a perl cgi app.  But I need to pass some info to the PERL app.  Cookies and Gets are not an option.  I would like to add header info or set header info but then when I call sendRedirect("http://someDomain/somePerl.cgi"); the header info does not seem to be there that I added or set.

thanks.
Avatar of bloodredsun
If it's a totally different webapp then the best thing would be to pass information in the request, using request parameters

e.g.
String perlURL = "http://www.myhost.com/cgi-bin/test.pl?param1=hello¶m2=example" ;
response.sendRedirect( perlURL );

RequestDispatcher is used for forwarding requests inside your own webapp, as soon as you go outside of the app, you can't use it (because it's an internal server call).

You could use request headers, but they are a lot more convoluted to call than a simple redirect with request parameters.
To use headers you would have to create an HttpUrlConnection inside your servlet and I wouldn't recommend that.
As of right now, adding params in plain view in the url is not an option.

Thanks.
do you want to keep them in your own webapp? Then creating an internal HttpUrlConnection is probably your best best. I can show you how if you like.

I'm wondering about your design/architecture if you have to go outside of your owb webapp. How come?
Yes, I am going outside my own WebApp.  This is just a temporary solution until we can completely convert to Java.  I have some legacy forms in PERL.  Once in PERL they will never need to come back to that java servlet.   BTW, will I need to create a HttpsUrlConnection, assuming I am connecting to a https://?

Thanks.  
ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All,
    Thanks for all your help.  As it turns out the headers were getting to my browser.  However the sendRedirect was then sends a 302 "temp moved" and forwards to another website WITHOUT my request headers sent on.  So back to the drawing board.

Yes, a response.sendRedirect makes the browser make a new request, which is why you have to use an internal https call to get the response from the external webapp from inside a servlet doGet/doPost method
By the way, you know that you can call HttpsURLConnection.setFollowRedirects(true) ; which should enable the instance to follow redirects. It should work for all 3XX responses.