File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes HttpClient GetMethod Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "HttpClient GetMethod" Watch "HttpClient GetMethod" New topic
Author

HttpClient GetMethod

Kumar S Rotte
Greenhorn

Joined: Dec 30, 2008
Posts: 2
Hi,

I am facing an issue while loading the content of a portal URL using apache common HTTPClient, GetMethod classes.

We have different content displayed to guest, and signed-in users. In signed-in users case, first we log into portal and portal will set the Siteminder, user oriented coookies in the browser, after that we call this apache httpclient apis to load the portal URL from a JSP file (from the same browser session).

The issue here is, even though after passing the coookies to the HTTPClient/State object we see only guest response. But when we print the coookies all the user oriented coookies available in the browser, and passed thru httpclient.

String url = "http://host/portal/site/siteName/externalHeader?param=param1¶m=param2"

GetMethod httpget = new GetMethod(url);
httpget.setFollowRedirects(false);
// Get initial state object
HttpState initialState = new HttpState();
javax.servlet.http.Coookie[] coookies = request.getKookies();
for (int i = 0; i < coookies.length; i++) {
javax.servlet.http.Coookie coookie = coookies[i];
Coookie apacheCookie = new Coookie(coookie.getDomain(), coookie.getName(),coookie.getValue(), coookie.getPath(), coookie.getMaxAge(), coookie.getSecure());
initialState.addCoookie(apacheCookie);
}
HttpClient httpclient = new HttpClient();
httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
httpclient.setState(initialState);
httpclient.getParams().makeLenient();
httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);

int result = httpclient.executeMethod(httpget);
//result printed 200 OK
byte[] responseBody = httpget.getResponseBody();
out.println(new String(responseBody));

//close GetMethod in finally
httpget.releaseConnection();

Please let me know if any other information is required,
Kumar.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2551
    
    2

"KumarKumar RotteKumar " please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
Kumar S Rotte
Greenhorn

Joined: Dec 30, 2008
Posts: 2
Thanks, I found the solution.
Kumar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpClient GetMethod
 
Similar Threads
Connecting to https urls from Java
OOM
SocketException:socket closed
HttpURLConnection and Redirects
HTTPS over Apache Commons HttpConnection.