You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by mike <mi...@3-egg.ch> on 2010/12/18 11:53:12 UTC

How to read Cookies in CXF Client

Does anybody know, how to read the JSESSIONID cookie? I'm sure, that the
cookie is set by the server.

I try this:

this.service = JAXRSClientFactory.create("http://localhost",
RegistrationService.class);
		
this.client =
WebClient.client(this.service).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML);

this.service.login(loginCredentials); // server call
		
ClientConfiguration config = WebClient.getConfig(this.service);
HTTPConduit conduit1 = config.getHttpConduit();
Map cookies = conduit1.getCookies(); //<- is empty
		
String str =
WebClient.getConfig(this.service).getHttpConduit().getClient().getCookie();
//<-is null

What am i doing wrong?
Any hints?
Thanks!!
-- 
View this message in context: http://cxf.547215.n5.nabble.com/How-to-read-Cookies-in-CXF-Client-tp3310363p3310363.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to read Cookies in CXF Client

Posted by mike <mi...@3-egg.ch>.
Hi Sergey

Yes, this helps. Thank you!

Here is the code to extract the JSESSIONID value:

// get all cookies
List cookies = this.client.getResponse().getMetadata().get("Set-Cookie");
		
if (cookies != null && !cookies.isEmpty()) {
			
  String cookie;
  for (Object object : cookies) {
    cookie = (String) object;
    if (cookie.contains("JSESSIONID")) {
      // cookie looks like that: JSESSIONID=m4i8fbdufhiy12tlnpd1hfp3f;Path=/
      cookie = cookie.substring(cookie.indexOf("=") + 1,
cookie.indexOf(";"));
    }
  }
}

Cheers!
Mike
-- 
View this message in context: http://cxf.547215.n5.nabble.com/How-to-read-Cookies-in-CXF-Client-tp3310363p3313165.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to read Cookies in CXF Client

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

You can do it similarly to the way you customize Content-Type & Accept (note
- you only need to do it if you'd like to override the information the proxy
has already got after introspecting the interface/resource object).

So you can do

proxy.login();

Response r = WebClient.client(proxy).getResponse();
List<Object> cookies = r.getMetadata().get("JSESSIONID");

hope it helps
Sergey

On Sat, Dec 18, 2010 at 10:53 AM, mike <mi...@3-egg.ch> wrote:

>
> Does anybody know, how to read the JSESSIONID cookie? I'm sure, that the
> cookie is set by the server.
>
> I try this:
>
> this.service = JAXRSClientFactory.create("http://localhost",
> RegistrationService.class);
>
> this.client =
>
> WebClient.client(this.service).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML);
>
> this.service.login(loginCredentials); // server call
>
> ClientConfiguration config = WebClient.getConfig(this.service);
> HTTPConduit conduit1 = config.getHttpConduit();
> Map cookies = conduit1.getCookies(); //<- is empty
>
> String str =
> WebClient.getConfig(this.service).getHttpConduit().getClient().getCookie();
> //<-is null
>
> What am i doing wrong?
> Any hints?
> Thanks!!
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-read-Cookies-in-CXF-Client-tp3310363p3310363.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: How to read Cookies in CXF Client

Posted by Benson Margulies <bi...@gmail.com>.
Ron, he's a client, not as server. The server has nothing to do with
his question, which is how to get a cookie response out of the JAX-RS
client wrappers CXF provides.

On Sat, Dec 18, 2010 at 8:56 AM, Ron Wheeler
<rw...@artifact-software.com> wrote:
> Does this have anything to do with CXF?
> Would this not be a question for the forum supporting your client
> application's server?
> You have not even mentioned the server technology that you client runs on.
>
> Ron
>
> On 18/12/2010 5:53 AM, mike wrote:
>>
>> Does anybody know, how to read the JSESSIONID cookie? I'm sure, that the
>> cookie is set by the server.
>>
>> I try this:
>>
>> this.service = JAXRSClientFactory.create("http://localhost",
>> RegistrationService.class);
>>
>> this.client =
>>
>> WebClient.client(this.service).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML);
>>
>> this.service.login(loginCredentials); // server call
>>
>> ClientConfiguration config = WebClient.getConfig(this.service);
>> HTTPConduit conduit1 = config.getHttpConduit();
>> Map cookies = conduit1.getCookies(); //<- is empty
>>
>> String str =
>>
>> WebClient.getConfig(this.service).getHttpConduit().getClient().getCookie();
>> //<-is null
>>
>> What am i doing wrong?
>> Any hints?
>> Thanks!!
>
>

Re: How to read Cookies in CXF Client

Posted by Ron Wheeler <rw...@artifact-software.com>.
Does this have anything to do with CXF?
Would this not be a question for the forum supporting your client 
application's server?
You have not even mentioned the server technology that you client runs on.

Ron

On 18/12/2010 5:53 AM, mike wrote:
> Does anybody know, how to read the JSESSIONID cookie? I'm sure, that the
> cookie is set by the server.
>
> I try this:
>
> this.service = JAXRSClientFactory.create("http://localhost",
> RegistrationService.class);
> 		
> this.client =
> WebClient.client(this.service).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML);
>
> this.service.login(loginCredentials); // server call
> 		
> ClientConfiguration config = WebClient.getConfig(this.service);
> HTTPConduit conduit1 = config.getHttpConduit();
> Map cookies = conduit1.getCookies(); //<- is empty
> 		
> String str =
> WebClient.getConfig(this.service).getHttpConduit().getClient().getCookie();
> //<-is null
>
> What am i doing wrong?
> Any hints?
> Thanks!!