You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <se...@iona.com> on 2009/09/01 17:22:18 UTC

Re: Trouble creating Proxy on the Client side using JAXRSClientFactory

I've setup a custom Eclipse project and manually imported all the needed
libs, one by one and eventually made it working, here is a list for a
minimal JAXB-based client :

- cglib-nodep-2.1_3.jar (available from my local Maven repo, needed only if
the class to be proxified is not an interface)
- spring.jar (from Spring 2.5.5 distribution, alternatively add spring libs
from the cxf distribution )

from cxf distribution :

- cxf-2.3.0-SNAPSHOT.jar
- jsr311-api-1.0.jar
- jaxb-impl-2.1.12.jar
- jaxb-api-2.1.jar

- geronimo-annotation_1.0_spec-1.1.1.jar
- geronimo-activation_1.1_spec-1.0.2.jar
- geronimo-servlet_2.5_spec-1.2.jar
- commons-logging-1.1.1.jar

- geronimo-stax_api_1.0_spec-1.0.1.jar
- woodstox-core-asl-4.0.3.jar
- stax2-api-3.0.1.jar

- geronimo-jaxws_2.1_spec-1.0.jar
- wsdl4j-1.6.2.jar
- XmlSchema-1.4.5.jar
- neethi-2.0.4.jar

though I believe some users have said they used fewer dependencies....

With CXF 2.2.4-SNAPSHOT you'll need to

- add cxf-2.2.3.jar instead of cxf-2.3.0-SNAPSHOT.jar
- do not add stax2-api-3.0.1.jar (won't be avaiable in distribution)
- add wstx-asl-3.2.8.jar instead of woodstox-core-asl-4.0.3.jar
- add saaj-api-1.3.jar

With 2.2.3 you may need to add FastInfoset.jar (available in the
distribution) as well..

I'm hoping that in CXF 2.3 it won't be necessary to include
geronimo-jaxws_2.1_spec-1.0.jar
& wsdl4j-1.6.2.jar. We will likely need XmlSchema-1.4.5.jar and may be
eventually even neethi.

I'll also see how the Spring dependency can be optionally dropped.

I've also updated 2.2.4-SNAPSHOT to an error message reported...
Will be updating the docs next...

thanks, Sergey


Pranab Verma wrote:
> 
> 
> Hi Kiran/Sergey,
> I am facing the same issue while using JAXRSClientFactory. I have created
> a simple JAVA project. Here is the snippet :
> 
> import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
> import com.my.rest.RestResourceHandler;
> 
> public class ProxyClient {
> 	static public void main(String arg[]) {
> 		String baseAddress = "http://localhost:8443/network/";
> 		RestResourceHandler proxy = JAXRSClientFactory.create(baseAddress,
> RestResourceHandler.class);
> 	}
> }
> The error message is :
> 
> Creating proxy..Exception in thread "main"
> javax.ws.rs.WebApplicationException
> 	at
> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWithValues(JAXRSClientFactoryBean.java:137)
> 	at
> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.create(JAXRSClientFactoryBean.java:113)
> 	at
> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:71)
> 	at
> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:56)
> 	at
> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:46)
> 	at ProxyClient.main(ProxyClient.java:13)
> 
> I have added cglib-nodep-2.1_3.jar library in project properties settings
> but still am getting the same error. 
> 
> Kiran,
> Were you able to resolve the problem?
> 
> Sergey,
> Am I doing the right thing? If not, please tell me what needs to be done?
> 
> Thanks,
> Pranab
> 
> 
> Sergey Beryozkin wrote:
>> 
>> Hi Kiran
>> 
>> The error message is non-existent - I'll have to fix it.
>> I think you need to add a cglib-nodeps dependency given that you're
>> creating a proxy from a concrete class, it will fix it (will document it
>> as well if it's  not documented yet)
>> 
>> cheers, Sergey 
>> 
>> kiran.sidhu wrote:
>>> 
>>> Hi,
>>> 
>>>                 I am getting a WebApplicationException when I try to
>>> create a proxy using JAXRSClientFactory, I tried both create API and
>>> fromClient API.
>>> 
>>> The WebClient API works fine.
>>> 
>>>  
>>> 
>>> Here is my Client code :
>>> 
>>>  
>>> 
>>> WebClient wc =
>>> WebClient.create("http://localhost:8080/cxf-webservices/webservices/cust
>>> omerservice/");
>>> 
>>>  
>>> wc.accept("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0
>>> .8");
>>> 
>>>             wc.encoding("UTF-8");
>>> 
>>>             wc.header("accept-charset",
>>> "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
>>> 
>>>             
>>> 
>>>             
>>> 
>>>             CustomerService proxy = JAXRSClientFactory.create(
>>> "http://localhost:8080/cxf-webservices/webservices/customerservice/",Cus
>>> tomerService.class);
>>> 
>>>             List<Customer> ccoll = proxy.getCustomers();
>>> 
>>>  
>>> 
>>> Right at the create statement, I get the following exception :
>>> 
>>>  
>>> 
>>> javax.ws.rs.WebApplicationException
>>> 
>>>       at
>>> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWithValues(JAXR
>>> SClientFactoryBean.java:149)
>>> 
>>>       at
>>> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.create(JAXRSClientFac
>>> toryBean.java:118)
>>> 
>>>       at
>>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory
>>> .java:71)
>>> 
>>>       at
>>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory
>>> .java:56)
>>> 
>>>       at
>>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory
>>> .java:46)
>>> 
>>>       at com.asipay.ws.client.Client.main(Client.java:82)
>>> 
>>>  
>>> 
>>> Here is my Service class :
>>> 
>>> @Path("/customerservice/")
>>> 
>>> public class CustomerService {
>>> 
>>>  
>>> 
>>>       private Map<Integer, Customer> customerMap = new TreeMap<Integer,
>>> Customer>();
>>> 
>>>       public CustomerService() {
>>> 
>>>             //Hard coded for testing
>>> 
>>>             Customer customer = new Customer();
>>> 
>>>             customer.setId(0);
>>> 
>>>           customer.setName("Jane Doe");
>>> 
>>>           customer.setAddress("123 Howe Ave, Los Angeles, CA");
>>> 
>>>           addCustomer(customer);
>>> 
>>>     } 
>>> 
>>>  
>>> 
>>>         @GET
>>> 
>>>         @Path("/customers")
>>> 
>>>         @Produces("application/xml")
>>> 
>>>         //@Resource MessageContext jaxrsContext; 
>>> 
>>>         public List<Customer> getCustomers() {
>>> 
>>>           //return  new Customers(customerMap.values());
>>> 
>>>               return new ArrayList<Customer>(customerMap.values());
>>> 
>>>         }
>>> 
>>>  
>>> 
>>>         @GET
>>> 
>>>         @Path("/customers/{id}")
>>> 
>>>         @Produces("text/xml")
>>> 
>>>         public Customer getCustomer(@PathParam("id") int cId) {
>>> 
>>>               
>>> 
>>>           return customerMap.get(cId);
>>> 
>>>         }
>>> 
>>>  
>>> 
>>>         @PUT
>>> 
>>>         @Consumes("application/xml")
>>> 
>>>         @Produces("text/plain")
>>> 
>>>         @Path("/customers/update/{id}")   
>>> 
>>>         public String updateCustomer(@PathParam("id") Long id, Customer
>>> customer) {  
>>> 
>>>                   customerMap.put(id.intValue(), customer);
>>> 
>>>               return "Customer " + customer.getName() + " updated.  Id =
>>> " + id;   
>>> 
>>>         }
>>> 
>>>  
>>> 
>>>         @POST
>>> 
>>>         @Path("/customers/add")
>>> 
>>>         @Produces("text/plain")
>>> 
>>>         @Consumes("application/xml")
>>> 
>>>         public String addCustomer(Customer customer) {
>>> 
>>>           int id = customerMap.size();
>>> 
>>>           customer.setId(id);
>>> 
>>>           customerMap.put(id, customer);
>>> 
>>>           return "Customer " + customer.getName() + " added with Id " +
>>> id;
>>> 
>>>         }
>>> 
>>>  
>>> 
>>>         @DELETE
>>> 
>>>         @Path("/customers/delete/{id}")
>>> 
>>>         @Produces("text/plain")
>>> 
>>>         @Consumes("application/xml")
>>> 
>>>         public String deleteCustomer(@PathParam("id") Integer id) {
>>> 
>>>  
>>> 
>>>             Customer customer = customerMap.get(id);
>>> 
>>>           customerMap.remove(id);
>>> 
>>>           return "Customer " + customer.getName() + " removed with Id "
>>> + id;
>>> 
>>>         }
>>> 
>>>  
>>> 
>>> Any idea if I am missing something ?
>>> 
>>>  
>>> 
>>> Thanks
>>> 
>>> Kiran
>>> 
>>> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>>> _ _
>>> 
>>> Notice: This information is intended only for the person(s) or
>>> entity(ies) to which it is addressed. This information may contain
>>> information that is confidential or otherwise protected from disclosure.
>>> If you are not the intended recipient of this message, or if this
>>> message has been addressed to you in error, please immediately alert the
>>> sender by reply e-mail and then delete this message, including any
>>> attachments. Any dissemination, distribution or other use of the
>>> contents of this message by anyone other than the intended recipient is
>>> strictly prohibited.
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trouble-creating-Proxy-on-the-Client-side-using-JAXRSClientFactory-tp24960821p25242323.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Trouble creating Proxy on the Client side using JAXRSClientFactory

Posted by Sergey Beryozkin <se...@iona.com>.
I've confirmed that the spring dependency can be dropped on the client side
too, if the JAXRSBindingFactory is registered with the bus explicitly, here
is the example :

http://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS#JAX-RS-ConfiguringJAXRSclientsprogrammaticallywithoutSpring

it is similar to the way it can be done on the server side

I'll try to enhance the code a bit to let users avoid doing this explicit
registration....

cheers, Sergey


Sergey Beryozkin wrote:
> 
> I've setup a custom Eclipse project and manually imported all the needed
> libs, one by one and eventually made it working, here is a list for a
> minimal JAXB-based client :
> 
> - cglib-nodep-2.1_3.jar (available from my local Maven repo, needed only
> if the class to be proxified is not an interface)
> - spring.jar (from Spring 2.5.5 distribution, alternatively add spring
> libs from the cxf distribution )
> 
> from cxf distribution :
> 
> - cxf-2.3.0-SNAPSHOT.jar
> - jsr311-api-1.0.jar
> - jaxb-impl-2.1.12.jar
> - jaxb-api-2.1.jar
> 
> - geronimo-annotation_1.0_spec-1.1.1.jar
> - geronimo-activation_1.1_spec-1.0.2.jar
> - geronimo-servlet_2.5_spec-1.2.jar
> - commons-logging-1.1.1.jar
> 
> - geronimo-stax_api_1.0_spec-1.0.1.jar
> - woodstox-core-asl-4.0.3.jar
> - stax2-api-3.0.1.jar
> 
> - geronimo-jaxws_2.1_spec-1.0.jar
> - wsdl4j-1.6.2.jar
> - XmlSchema-1.4.5.jar
> - neethi-2.0.4.jar
> 
> though I believe some users have said they used fewer dependencies....
> 
> With CXF 2.2.4-SNAPSHOT you'll need to
> 
> - add cxf-2.2.3.jar instead of cxf-2.3.0-SNAPSHOT.jar
> - do not add stax2-api-3.0.1.jar (won't be avaiable in distribution)
> - add wstx-asl-3.2.8.jar instead of woodstox-core-asl-4.0.3.jar
> - add saaj-api-1.3.jar
> 
> With 2.2.3 you may need to add FastInfoset.jar (available in the
> distribution) as well..
> 
> I'm hoping that in CXF 2.3 it won't be necessary to include
> geronimo-jaxws_2.1_spec-1.0.jar
> & wsdl4j-1.6.2.jar. We will likely need XmlSchema-1.4.5.jar and may be
> eventually even neethi.
> 
> I'll also see how the Spring dependency can be optionally dropped.
> 
> I've also updated 2.2.4-SNAPSHOT to an error message reported...
> Will be updating the docs next...
> 
> thanks, Sergey
> 
> 
> Pranab Verma wrote:
>> 
>> 
>> Hi Kiran/Sergey,
>> I am facing the same issue while using JAXRSClientFactory. I have created
>> a simple JAVA project. Here is the snippet :
>> 
>> import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
>> import com.my.rest.RestResourceHandler;
>> 
>> public class ProxyClient {
>> 	static public void main(String arg[]) {
>> 		String baseAddress = "http://localhost:8443/network/";
>> 		RestResourceHandler proxy = JAXRSClientFactory.create(baseAddress,
>> RestResourceHandler.class);
>> 	}
>> }
>> The error message is :
>> 
>> Creating proxy..Exception in thread "main"
>> javax.ws.rs.WebApplicationException
>> 	at
>> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWithValues(JAXRSClientFactoryBean.java:137)
>> 	at
>> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.create(JAXRSClientFactoryBean.java:113)
>> 	at
>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:71)
>> 	at
>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:56)
>> 	at
>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:46)
>> 	at ProxyClient.main(ProxyClient.java:13)
>> 
>> I have added cglib-nodep-2.1_3.jar library in project properties settings
>> but still am getting the same error. 
>> 
>> Kiran,
>> Were you able to resolve the problem?
>> 
>> Sergey,
>> Am I doing the right thing? If not, please tell me what needs to be done?
>> 
>> Thanks,
>> Pranab
>> 
>> 
>> Sergey Beryozkin wrote:
>>> 
>>> Hi Kiran
>>> 
>>> The error message is non-existent - I'll have to fix it.
>>> I think you need to add a cglib-nodeps dependency given that you're
>>> creating a proxy from a concrete class, it will fix it (will document it
>>> as well if it's  not documented yet)
>>> 
>>> cheers, Sergey 
>>> 
>>> kiran.sidhu wrote:
>>>> 
>>>> Hi,
>>>> 
>>>>                 I am getting a WebApplicationException when I try to
>>>> create a proxy using JAXRSClientFactory, I tried both create API and
>>>> fromClient API.
>>>> 
>>>> The WebClient API works fine.
>>>> 
>>>>  
>>>> 
>>>> Here is my Client code :
>>>> 
>>>>  
>>>> 
>>>> WebClient wc =
>>>> WebClient.create("http://localhost:8080/cxf-webservices/webservices/cust
>>>> omerservice/");
>>>> 
>>>>  
>>>> wc.accept("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0
>>>> .8");
>>>> 
>>>>             wc.encoding("UTF-8");
>>>> 
>>>>             wc.header("accept-charset",
>>>> "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
>>>> 
>>>>             
>>>> 
>>>>             
>>>> 
>>>>             CustomerService proxy = JAXRSClientFactory.create(
>>>> "http://localhost:8080/cxf-webservices/webservices/customerservice/",Cus
>>>> tomerService.class);
>>>> 
>>>>             List<Customer> ccoll = proxy.getCustomers();
>>>> 
>>>>  
>>>> 
>>>> Right at the create statement, I get the following exception :
>>>> 
>>>>  
>>>> 
>>>> javax.ws.rs.WebApplicationException
>>>> 
>>>>       at
>>>> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWithValues(JAXR
>>>> SClientFactoryBean.java:149)
>>>> 
>>>>       at
>>>> org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.create(JAXRSClientFac
>>>> toryBean.java:118)
>>>> 
>>>>       at
>>>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory
>>>> .java:71)
>>>> 
>>>>       at
>>>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory
>>>> .java:56)
>>>> 
>>>>       at
>>>> org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory
>>>> .java:46)
>>>> 
>>>>       at com.asipay.ws.client.Client.main(Client.java:82)
>>>> 
>>>>  
>>>> 
>>>> Here is my Service class :
>>>> 
>>>> @Path("/customerservice/")
>>>> 
>>>> public class CustomerService {
>>>> 
>>>>  
>>>> 
>>>>       private Map<Integer, Customer> customerMap = new TreeMap<Integer,
>>>> Customer>();
>>>> 
>>>>       public CustomerService() {
>>>> 
>>>>             //Hard coded for testing
>>>> 
>>>>             Customer customer = new Customer();
>>>> 
>>>>             customer.setId(0);
>>>> 
>>>>           customer.setName("Jane Doe");
>>>> 
>>>>           customer.setAddress("123 Howe Ave, Los Angeles, CA");
>>>> 
>>>>           addCustomer(customer);
>>>> 
>>>>     } 
>>>> 
>>>>  
>>>> 
>>>>         @GET
>>>> 
>>>>         @Path("/customers")
>>>> 
>>>>         @Produces("application/xml")
>>>> 
>>>>         //@Resource MessageContext jaxrsContext; 
>>>> 
>>>>         public List<Customer> getCustomers() {
>>>> 
>>>>           //return  new Customers(customerMap.values());
>>>> 
>>>>               return new ArrayList<Customer>(customerMap.values());
>>>> 
>>>>         }
>>>> 
>>>>  
>>>> 
>>>>         @GET
>>>> 
>>>>         @Path("/customers/{id}")
>>>> 
>>>>         @Produces("text/xml")
>>>> 
>>>>         public Customer getCustomer(@PathParam("id") int cId) {
>>>> 
>>>>               
>>>> 
>>>>           return customerMap.get(cId);
>>>> 
>>>>         }
>>>> 
>>>>  
>>>> 
>>>>         @PUT
>>>> 
>>>>         @Consumes("application/xml")
>>>> 
>>>>         @Produces("text/plain")
>>>> 
>>>>         @Path("/customers/update/{id}")   
>>>> 
>>>>         public String updateCustomer(@PathParam("id") Long id, Customer
>>>> customer) {  
>>>> 
>>>>                   customerMap.put(id.intValue(), customer);
>>>> 
>>>>               return "Customer " + customer.getName() + " updated.  Id
>>>> =
>>>> " + id;   
>>>> 
>>>>         }
>>>> 
>>>>  
>>>> 
>>>>         @POST
>>>> 
>>>>         @Path("/customers/add")
>>>> 
>>>>         @Produces("text/plain")
>>>> 
>>>>         @Consumes("application/xml")
>>>> 
>>>>         public String addCustomer(Customer customer) {
>>>> 
>>>>           int id = customerMap.size();
>>>> 
>>>>           customer.setId(id);
>>>> 
>>>>           customerMap.put(id, customer);
>>>> 
>>>>           return "Customer " + customer.getName() + " added with Id " +
>>>> id;
>>>> 
>>>>         }
>>>> 
>>>>  
>>>> 
>>>>         @DELETE
>>>> 
>>>>         @Path("/customers/delete/{id}")
>>>> 
>>>>         @Produces("text/plain")
>>>> 
>>>>         @Consumes("application/xml")
>>>> 
>>>>         public String deleteCustomer(@PathParam("id") Integer id) {
>>>> 
>>>>  
>>>> 
>>>>             Customer customer = customerMap.get(id);
>>>> 
>>>>           customerMap.remove(id);
>>>> 
>>>>           return "Customer " + customer.getName() + " removed with Id "
>>>> + id;
>>>> 
>>>>         }
>>>> 
>>>>  
>>>> 
>>>> Any idea if I am missing something ?
>>>> 
>>>>  
>>>> 
>>>> Thanks
>>>> 
>>>> Kiran
>>>> 
>>>> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>>>> _ _
>>>> 
>>>> Notice: This information is intended only for the person(s) or
>>>> entity(ies) to which it is addressed. This information may contain
>>>> information that is confidential or otherwise protected from
>>>> disclosure. If you are not the intended recipient of this message, or
>>>> if this message has been addressed to you in error, please immediately
>>>> alert the sender by reply e-mail and then delete this message,
>>>> including any attachments. Any dissemination, distribution or other use
>>>> of the contents of this message by anyone other than the intended
>>>> recipient is strictly prohibited.
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trouble-creating-Proxy-on-the-Client-side-using-JAXRSClientFactory-tp24960821p25243687.html
Sent from the cxf-user mailing list archive at Nabble.com.