users@jersey.java.net

Re: [Jersey] how to use ApacheHttpClient

From: <reno.rkcrew_at_free.fr>
Date: Tue, 15 Jun 2010 18:00:36 +0200

In fact, we're using the jersey-apache-client classes only in the test classes
to mock an apache HTTPD server ?

S.

>
> On Jun 15, 2010, at 3:52 PM, reno.rkcrew_at_free.fr wrote:
>
> > Paul,
> >
> > My request is: i've got some page on apache httpd server. On a jonas
> > server,
> > i've got my webapp (using jersey & spring). The html pages (with some
> > Javascript) make REST requests to the webapp and the webapp returns
> > JSON.
> > And my goal is to instantiate a cookie when there is no cookie in
> > the HTTPS
> > request.
> >
> > It is clearer ?
> >
>
> I think so.
>
> You do not require the Apache HTTP client as IICU your client is a
> JavaScript client making async requests.
>
> Usually the way cookies are utilized is the server will initiate a
> cookie by returning a response header Set-Cookie. Then for subsequent
> requests the client will respond with a request Cookie that contains a
> value that was included in the Set-Cookie response header value. See:
>
> http://www.ietf.org/rfc/rfc2109.txt
>
> This type of behavior can be supported using Jersey request and
> response filters [1]. But it is also supported if one enables HTTP
> sessions in web containers. It all depends one how you are using
> cookies and what the data needs to be.
>
> Another way to use cookies is for them to be client-driven and not
> consisting of opaque server-side data,
>
> Paul.
>
> [1]
>
https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/package-summary.html
>
>
> > S.
> >>
> >> On Jun 15, 2010, at 1:45 PM, reno.rkcrew_at_free.fr wrote:
> >>
> >>> Thanks Paul,
> >>>
> >>> i found it this info on the web [1] but my problem is where do i put
> >>> this
> >>> configuration ? in each resource or in an "super" resource and the
> >>> others will
> >>> immplement the super class or in a filter class?
> >>> If i use a filter class, do i declare it in the web.xml as the
> >>> following lines:
> >>>
> >>> <init-param>
> >>> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</
> >>> param-name>
> >>> <param-value><mypackage>.MyFilter</param-value>
> >>> </init-param>
> >>>
> >>> there no sample for the apache use so that's why i'm a bit lost :-)
> >>>
> >>
> >> No, client filters are separate entities from server filters.
> >>
> >> I am confused as to exactly what you want to do.
> >>
> >> Are you writing a server-side app that should return cookies to
> >> clients? do you want to use the Apache HTTP client to test your
> >> service?
> >>
> >> Paul.
> >>
> >>
> >>
> >>> S.
> >>>
> >>> [1] :
> >>>
> >>
> >
>
http://jersey.576304.n2.nabble.com/Session-Handling-not-working-with-Jersey-Client-td4519663.html
> >>>
> >>>> Some more info...
> >>>>
> >>>> To enable cooke support:
> >>>>
> >>>> ApacheHttpClientConfig cc = new DefaultApacheHttpClientConfig();
> >>>> cc.setProperty(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES,
> >>>> true);
> >>>> Client c = ApacheHttpClient.create(cc);
> >>>>
> >>>> It add a filter do:
> >>>>
> >>>> MyFilter f = ...
> >>>> c.addFilter(f);
> >>>>
> >>>>
> >>>
> >>
> >
>
https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/filter/Filterable.html
> >>>> #addFilter%28com.sun.jersey.api.client.filter.ClientFilter%29
> >>>>
> >>>> Paul.
> >>>>
> >>>> On Jun 15, 2010, at 1:10 PM, Pavel Bucek wrote:
> >>>>
> >>>>> Hello,
> >>>>>
> >>>>> On 6/15/10 12:28 PM, reno.rkcrew_at_free.fr wrote:
> >>>>>>
> >>>>>> hello all,
> >>>>>>
> >>>>>> I would like to know how to use the ApacheHttpClientXXX
> >>>>>> classes. I
> >>>>>> read the
> >>>>>> package summary [1] but i don't know how to use it with in a
> >>>>>> jersey
> >>>>>> webapp :-(
> >>>>>>
> >>>>> you have to create client instance this way:
> >>>>>
> >>>>> Client c = ApacheHttpClient.create();
> >>>>>
> >>>>> and you need to declare dependency for that:
> >>>>>
> >>>>> <dependency>
> >>>>> <groupId>com.sun.jersey.contribs</groupId>
> >>>>> <artifactId>jersey-apache-client</artifactId>
> >>>>> <version>${project.version}</version>
> >>>>> </dependency>
> >>>>>
> >>>>> Hope it helps,
> >>>>> Pavel
> >>>>>
> >>>>>> In the user guide [2], there is this paragraph:
> >>>>>> "The support for HTTP authentication and cookies is much better
> >>>>>> with the Apache
> >>>>>> HTTP client than with HttpURLConnection. See the Java
> >>>>>> documentation
> >>>>>> for the
> >>>>>> package com.sun.jersey.client.apache, ApacheHttpClientState and
> >>>>>> ApacheHttpClientConfig for more details. "
> >>>>>> it does not help me a lot :-(
> >>>>>>
> >>>>>> My goal is to add a filter for all the requests (that comes
> >>>>>> from an
> >>>>>> apache httpd
> >>>>>> server): if the cookie does not exist, we create it in the
> >>>>>> filter.
> >>>>>>
> >>>>>> Is anybody has ever done it?
> >>>>>>
> >>>>>> Regards
> >>>>>>
> >>>>>> S.
> >>>>>>
> >>>>>> [1] :
> >>>>>>
> >>>>
> >>>
> >>
> >
>
https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-apache-client/com/sun/jersey/client/apache/package-summary.html
> >>>>>> [2] :
> >>>>>> https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html
> >>>>>> #d4e687
> >>>>>>
> >>>>>> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> >>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> >>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >>>>>
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> >>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> >>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> >> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>