Hi,

You likely should get JAXRSClientFactoryBean from spring context and create 
your WebClient on the base on it:

        Object bean = ctx.getBean("myProvider.proxyFactory");
        assertNotNull(bean);
        JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;
        WebClient wc = (WebClient)cfb.create();

See CXF system test JAXRSHttpsBookTest.doTestGetBook123ProxyFromSpring() 
(http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java?view=markup
 ) as a sample.

Btw you can add Interceptors programmatically as well: 
KerberosAuthOutInterceptor kbInterceptor = new KerberosAuthOutInterceptor();
WebClient.getConfig(customerService).getOutInterceptors().add(kbInterceptor);

Regards,
Andrei.

> -----Original Message-----
> From: kalpabas [mailto:[email protected]]
> Sent: Mittwoch, 7. Mai 2014 19:22
> To: [email protected]
> Subject: Use jaxrs-client:client for XML over HTTP Service
> 
> Hello Experts,
> 
> I'm consuming a service which is XML over HTTP. I'm using
> org.apache.cxf.jaxrs.client.WebClient to call this service and everything fine
> with this implementation for years:
> 
>               JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
>               org.apache.cxf.jaxrs.client.WebClient webClient =
> bean.createWebClient();
>               webClient.post(body);
> 
> Now I'm trying to move this client code to spring configuration. I'm using 
> cxf-
> 3.0.0-milestone2. Following is my client configuration:
> 
>       <jaxrs-client:client id="myProvider"
>               address="{serviceAddress}"
> serviceClass="org.apache.cxf.jaxrs.client.WebClient">
>               <jaxrs-client:headers>
>                       <entry key="Accept" value="text/xml" />
>               </jaxrs-client:headers>
>       </jaxrs-client:client>
> 
> My Service address is nothing but an ip address and a port. It does not 
> contain
> any details about the service name or any other thing.
> 
> Here is the code I'm trying to get the client and post request message:
> 
> WebClient webClient = (WebClient) getBean("myProvider");
> 
> And I'm getting this error:
> 
> java.lang.ClassCastException - com.sun.proxy.$Proxy105 cannot be cast to
> org.apache.cxf.jaxrs.client.WebClient - java.lang.ClassCastException:
> com.sun.proxy.$Proxy105 cannot be cast to
> org.apache.cxf.jaxrs.client.WebClient
> 
> The reason I need to move my client code to spring/cxf is to add in/out
> interceptors. All of my regular jaxws clients are working with spring/cxf
> configuration. But only this service is giving me hard time.
> 
> My questions are:
> What am I doing wrong here?
> Can't I use jaxrs-client:client for simple XML over HTTP service?
> 
> Please note that I was using CXF 2.7.X and jaxrs:client configuration. I was
> getting the same error. I switched to CXF 3 after reading about supporting
> WebClient in the new version. But the result is same.
> 
> Thank you,
> Kalpa
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Use-jaxrs-
> client-client-for-XML-over-HTTP-Service-tp5743813.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to