commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@bluewin.ch>
Subject RE: [HttpClient] How to use HttpClient with Form-based Authentication?
Date Tue, 07 Sep 2004 17:39:12 GMT
The problem is not the redirect as such. The real issue appears to be
that for whatever reason the upload servlet does not recognize or accept
the session cookie which causes the redirect back to the logon page

Please post the complete debug/wire log of the HTTP session that
exhibits the problem. For details on logging with HttpClient refer to
the HttpClient logging guide:

http://jakarta.apache.org/commons/httpclient/logging.html

I'll see if I can get more information out of the wire log. 

You may want to have security sensitive information such as logon
credentials obfuscated prior to posting the log to the list

Oleg


On Tue, 2004-09-07 at 15:50, rportan@saguaro.ro wrote:
> Thank for help, sadly is not enogh.
> I want to upload several files using MultipartPostMethod, the problem is 
> I'm redirected from the upload servlet back to the login form page.
> Basicaly I want my client to authorize itself and than go the 
> UploadServlet to send the file to it.
> 
> 
> Here is my addition(BOLDED) to the FormLoginDemo.java file. 
> 
> 
>             ...
> 
>  
>         if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
>             (statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
>             (statuscode == HttpStatus.SC_SEE_OTHER) ||
>             (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
>             Header header = authpost.getResponseHeader("location");
>             if (header != null) {
>                 String newuri = header.getValue();
>                 if ((newuri == null) || (newuri.equals(""))) {
>                     newuri = "/";
>                 }
>                 System.out.println("Redirect target: " + newuri); 
>                 GetMethod redirect = new GetMethod(newuri);
> 
>                 client.executeMethod(redirect);
>                 System.out.println("Redirect: " + 
> redirect.getStatusLine().toString()); 
>                 // release any connection resources used by the method
>                 redirect.releaseConnection();
>  
> 
> 
>                 File file=new File("c:\\Books\\<my file>");
>                     MultipartPostMethod mPost = new MultipartPostMethod(
> "http://localhost/MyApp/UploadServlet");
>                     mPost.addParameter(file.getName(),file); 
>                     mPost.setFollowRedirects(true);
> 
>                     client.executeMethod(mPost);
>                     System.out.println("Post status: " + 
> mPost.getStatusLine().toString()); 
>                     mPost.releaseConnection();
> 
> 
>  
>             } else {
>                 System.out.println("Invalid redirect");
>                 System.exit(1);
>             }
>         }
>            ......... 
> 
> 
> 
> And here are the logs for multipart request part:
> 
> 
> 
> 2004/09/07 16:46:14:922 EEST [INFO] HttpMethodDirector - Redirect 
> requested but followRedirects is disabledLogin form post: HTTP/1.1 302 
> Found
> 
> Logon cookies:
> - JSESSIONID=0000SdkoAaLYJd1wXxn-19q17Fe:-1
> Redirect target: http://localhost:9080/InfoprintJobTicketer/login.html
> 2004/09/07 16:46:14:922 EEST [DEBUG] HttpMethodBase - Resorting to 
> protocol version default close connection policy
> 2004/09/07 16:46:14:922 EEST [DEBUG] HttpMethodBase - Should NOT close 
> connection, using HTTP/1.1
> 2004/09/07 16:46:14:922 EEST [DEBUG] HttpConnection - Releasing connection 
> back to connection manager.
> Redirect: HTTP/1.1 200 OK
> 2004/09/07 16:46:14:922 EEST [DEBUG] HttpMethodBase - Adding Host request 
> header
> 2004/09/07 16:46:14:938 EEST [DEBUG] HttpMethodBase - Resorting to 
> protocol version default close connection policy
> 2004/09/07 16:46:14:938 EEST [DEBUG] HttpMethodBase - Should NOT close 
> connection, using HTTP/1.1
> 2004/09/07 16:46:14:938 EEST [DEBUG] HttpConnection - Releasing connection 
> back to connection manager.
> 2004/09/07 16:46:14:953 EEST [DEBUG] HttpMethodBase - Adding Host request 
> header
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Redirect 
> required
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Redirect 
> requested to location 
> 'http://localhost:9080/InfoprintJobTicketer/login.html'
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Redirecting from 
> 'http://localhost/MyApp/UploadServlet' to 'http://localhost/MyApp/
> login.html
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodDirector - Execute redirect 
> 1 of 100
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodBase - Resorting to 
> protocol version default close connection policy
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpMethodBase - Should NOT close 
> connection, using HTTP/1.1
> 2004/09/07 16:46:16:250 EEST [DEBUG] HttpConnection - Connection is 
> locked.  Call to releaseConnection() ignored.
> 2004/09/07 16:46:16:266 EEST [DEBUG] HttpMethodBase - Adding Host request 
> header
> 2004/09/07 16:46:17:109 EEST [DEBUG] HttpMethodBase - Resorting to 
> protocol version default close connection policy
> 2004/09/07 16:46:17:109 EEST [DEBUG] HttpMethodBase - Should NOT close 
> connection, using HTTP/1.1
> 2004/09/07 16:46:17:109 EEST [DEBUG] HttpConnection - Releasing connection 
> back to connection manager.
> Post status: HTTP/1.1 200 OK
> 
> 
> 
> 
> 
> olegk@bluewin.ch 
> 09/07/2004 03:57 PM
> Please respond to
> "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
> 
> 
> To
> "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
> cc
> 
> Subject
> RE: [HttpClient] How to use HttpClient with Form-based Authentication?
> 
> 
> 
> 
> 
> 
> Hope this one will do
> 
> http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/FormLoginDemo.java?view=markup
> 
> 
> Oleg
> 
> >-- Original Message --
> >Reply-To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
> >To: commons-user@jakarta.apache.org
> >Subject: [HttpClient] How to use HttpClient with Form-based 
> Authentication?
> >From: rportan@saguaro.ro
> >Date: Tue, 7 Sep 2004 15:50:02 +0300
> >
> >
> >Hi,
> >
> >Can HttpClient be used with  Form-based Authentication?
> >If yes can I have a code example?
> >Thank you
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message