commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig McClanahan" <craig...@apache.org>
Subject Re: HttpClient + Session
Date Fri, 30 Mar 2007 17:38:38 GMT
On 3/30/07, Tatiana Lloret Iglesias <tlloreti@gmail.com> wrote:
> Hi all,
>
> I'm using jakarta httpclient classes to generate a Request from a stand
> alone application:
>
> HttpClient client = new HttpClient();
> URL filesURL = new URL(myURL");
>
> PostMethod postMethod = new PostMethod(filesURL.toString());
>
> File targetFile = new File(path);
> Part[] parts = {new StringPart("serverFileName",serverFileName),
> new FilePart(targetFile.getName(), targetFile)
> };
>
> postMethod.setRequestEntity(new MultipartRequestEntity(parts,
> postMethod.getParams())
> );
>
>
> int statusCode1 = client.executeMethod(postMethod);
>
> My problem is that in the Server side I check Session object:
>
> private boolean isUserAuthenticated(HttpServletRequest request) {
> boolean isAuthenticated = false;
> HttpSession session = request.getSession(false);
> if(session == null) return false;
> if (session.getAttribute(Constants.USER_LOGGED) != null) {
> isAuthenticated = true;
> }
> return isAuthenticated;
> }
>
> How can I put this Constants.USER_LOGGED variable in httpclient request
> object?

That is not what you actually want to do :-).

What you want to do is simulate the way that a browser maintains
sessions across requests.  Typically, this is done by the server
sending a JSESSIONID cookie along with the first response.  Your
client code will need to pick up that session ID and include it (in a
"Cookie" header) on the subsequent request, so that the server will
know what session the second request belongs to.

Craig


>
> Thanks!
> T
>

---------------------------------------------------------------------
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