commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tatiana Lloret Iglesias" <tllor...@gmail.com>
Subject Re: HttpClient + Session
Date Mon, 02 Apr 2007 11:45:47 GMT
Hi again,

I only need to pass this validation once from my standalone application to
my server, i.e. i dont need to maintain it among requests ...

Do you have some piece of code to do this? Thanks!
Regards
T



On 3/30/07, Craig McClanahan <craigmcc@apache.org> wrote:
>
> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message