Hi Pete,
The Jersey client by default uses HttpURLConnection that does not
support cookie management (and thus sessions).
You need to switch to using the Apache HTTP client support.
https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-apache-client/com/sun/jersey/client/apache/package-summary.html
Then set the following property to true:
https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-apache-client/com/sun/jersey/client/apache/config/ApacheHttpClientConfig.html
#PROPERTY_HANDLE_COOKIES
DefaultApacheHttpClientConfig config = new
DefaultApacheHttpClientConfig();
config
.setProperty("com.sun.jersey.impl.client.httpclient.handleCookies",
true);
ApacheHttpClient c = ApacheHttpClient.create(config);
Plus you can also use authorization with the Apache HTTP client
integration.
DefaultApacheHttpClientConfig config = new
DefaultApacheHttpClientConfig();
config.getState().setCredentials(null, null, -1, "foo", "bar");
ApacheHttpClient c = ApacheHttpClient.create(config);
WebResource r = c.resource("
http://host/base");
String s = r.get(String.class);
s = r.post(String.class, s);
Paul.
On Feb 5, 2010, at 1:38 PM, Peter.Neu_at_gmx.net wrote:
> Hi,
>
> I have trouble with the session handling with the jersey client.
> Each call I make to the jersey server produces a new session id.
> Thus I'm not able to store anything in the session.
>
> My calls look like this:
>
> WebResource resource = restClient.resource(url + "fileupload");
> Builder builder = resource.type("application/x-www-form-urlencoded");
> builder = builder.header("Authorization", "...))));
> builder = builder.accept("application/json");
> builder = builder.header("Accept-Charset", "UTF-8");
> final MultivaluedMap<String, String> formParams = new
> MultivaluedMapImpl();
> formParams.add("..", "...");
> formParams.add("..", "...");
>
> In my rest method on the server I have:
>
> @POST
> @Path("/createreport")
> @Produces(MediaType.APPLICATION_JSON)
> @Consumes("application/x-www-form-urlencoded")
> public String createReport(...,_at_Context HttpServletRequest req) {
>
> logger.info(" SessionID is :" + req.getSession().getId());
> }
>
> Any ideas what's wrong?
>
> Normal JSP Session Handling works fine.
>
> I use tomcat 6.0.20, jdk 1.6.0.11 and jersey 1.0.3
>
> Cheers,
> Pete
> --
> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla
> Firefox 3.5 -
> sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>