HttpUnit redirect problem while login to WS Portal app

"Riju Kansal" <[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
Hi,


The question I have is that -- Is this the best way to get the response in
case of auto-redirects?


I was facing a problem while trying to login in a site, to which I found a
solution but still I have some doubt as follows:

I passed userid & password to a login page and submitted request. As a
result, I should have got an expected home page of the site. But I was
getting redirected back to the login page.

After struggling with this problem (using Fiddler) for a while, I could
finally find the solution. The solution being capturing the SET-COOKIE
header from the first response and setting it as cookie before sending the
request back in a series of auto-redirects.

This site was deployed on a WS portal and I was accessing the Portal login
page.

Following code works fine:

//Start
resp = wc.getResponse( "http://xyz.portal.com/orgaccess" );
String referer = "";
while(resp.getHeaderField("LOCATION") !=null){
referer = resp.getHeaderField("LOCATION");
resp = wc.getResponse( resp.getHeaderField("LOCATION"));
}
WebForm form = resp.getForms()[0];
req = form.getRequest(form.getSubmitButtons()[0]);
req.setParameter(resp.getElementWithID("userID").getName(),"XYZ ABC");
req.setParameter(resp.getElementWithID("password").getName(),"testpwd");
resp = wc.getResponse(req);
String [] headerFieldNames = resp.getHeaderFields("SET-COOKIE");
String cookie = "";
cookie = headerFieldNames[2] + "; " + headerFieldNames[4] + "; " +
headerFieldNames[1];
wc.setHeaderField("Cookie:",cookie);
while(resp.getHeaderField("LOCATION") !=null){
resp = wc.getResponse( resp.getHeaderField("LOCATION"));
}

assertTrue(resp.getTitle().indexOf("Welcome") >= 0);

//End

Please note the string array to hold the SET-COOKIE values in an array and
setting it back in Web Conversation in a particular format to get the
correct response back from portal server. The cookie contains jsessionid,
ltpatoken & login info.

The question I have is that -- Is this the best way to get the response?

Please help me conclude on this problem.

Thanks,
kriju

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.