You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by ki...@asipay.com on 2009/07/29 20:06:22 UTC

Running into problems with using WebClient

Hi,

                 I have a simple RESTful Web Service that I got from one
of the samples on the web.  I am able to invoke it from browser and it
shows the output on the browser, but when I try and call it from my
client code using WebClient, it's throwing the following exception, Am I
missing something ?

 

WARNING: .No operation matching request path /customers is found,
ContentType : */*, Accept :
text/html,application/xhtml+xml,application/xml,.

Jul 29, 2009 10:38:23 AM
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse

WARNING: WebApplicationException has been caught : no cause is available

Jul 29, 2009 10:38:23 AM
org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose

 

Here is the Client code :

 

WebClient wc =
WebClient.create("http://localhost:8080/cxf-webservices/webservices/cust
omerservice");

wc.accept("text/html,application/xhtml+xml,application/xml");     

Response getresponse = wc.path("/customers").get();

 

 

Here is the Web Service :

    <jaxrs:server id="customerService" address="/">   

      <jaxrs:serviceBeans>  

          <ref bean="customerservice"/>

        </jaxrs:serviceBeans>

      </jaxrs:server>  

      <bean id="customerservice" class="test.CustomerService" />

 

 

@Path("/customerservice/")   

@Produces("text/xml")

public class CustomerService {

 

      private TreeMap<Integer, Customer> customerMap = new
TreeMap<Integer, Customer>();

      public CustomerService() {

            //Hard coded for testing

            Customer customer = new Customer();

            customer.setId(0);

          customer.setName("Harold Abernathy");

          customer.setAddress("Sheffield, UK");

          addCustomer(customer);

    } 

 

        @GET

        @Path("/customers")

        public CustomerCollection getCustomers() {

          return new CustomerCollection( customerMap.values());

        }

 

        @GET

        @Path("/customers/{id}")

        public Customer getCustomer(@PathParam("id") int cId) {

              

          return customerMap.get(cId);

        }

 

        @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;

        }

 

Any help will be appreciated.

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.

RE: Running into problems with using WebClient

Posted by ki...@asipay.com.
Hi Sergey,
            Thanks for your help. I was able to get past this problem by
changing the WebClient.accept call to the following :

wc.accept("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0
.8");

Now I get the response back, but when I try to get the Customer object
from the response, it throws a JAXBException (Premature end of file) 

---------------------------
ID: 6
Address:
http://localhost:8080/cxf-webservices/webservices/customerservice/custom
ers/0
Encoding: 
Content-Type: */*
Headers:
{Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
], Accept-Encoding=[gzip,deflate], Content-Encoding=[UTF-8],
accept-charset=[ISO-8859-1,utf-8;q=0.7,*;q=0.7], Content-Type=[*/*]}
Payload: 
--------------------------------------
Jul 29, 2009 12:37:09 PM org.apache.cxf.interceptor.LoggingInInterceptor
logging
INFO: Inbound Message
----------------------------
ID: 6
Encoding: UTF-8
Content-Type: text/xml
Headers: {content-type=[text/xml], Date=[Wed, 29 Jul 2009 19:37:09 GMT],
Content-Length=[147], Server=[Apache-Coyote/1.1]}
Payload: <?xml version="1.0" encoding="UTF-8"
standalone="yes"?><customer><address>Sheffield,
UK</address><id>0</id><name>Harold Abernathy</name></customer>
--------------------------------------
Jul 29, 2009 12:37:10 PM
org.apache.cxf.jaxrs.provider.AbstractJAXBProvider handleJAXBException
WARNING: JAXBException occurred : Premature end of file.
javax.ws.rs.WebApplicationException: javax.ws.rs.WebApplicationException
	at
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:500)
	at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java
:486)
	at
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:463)
	at
org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:264)
	at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:292)
	at com.asipay.ws.client.Client.main(Client.java:83)
Caused by: javax.ws.rs.WebApplicationException
	at
org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:
393)
	at
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:494)
	... 5 more

-----Original Message-----
From: users-return-16498-kiran.sidhu=asipay.com@cxf.apache.org
[mailto:users-return-16498-kiran.sidhu=asipay.com@cxf.apache.org] 
Sent: Wednesday, July 29, 2009 12:27 PM
To: users@cxf.apache.org
Subject: Re: Running into problems with using WebClient


Hi

I think the reason no match is found is that CustomerService uses a
global
@Produces("text/xml")
values which applies to all resource methods unless specifically
overridden,
while WebClient says it can accept 

text/html,application/xhtml+xml,application/xml

so you might want to update either a WebClient accept call or @Produces
to
also include text/xml 

I'll update the server code which reports the problem to make sure a
more
specific message is reported. You should also get a 406 response code in
this case (per the spec). Give it a try please.

cheers, Sergey


kiran.sidhu wrote:
> 
> Hi,
> 
>                  I have a simple RESTful Web Service that I got from
one
> of the samples on the web.  I am able to invoke it from browser and it
> shows the output on the browser, but when I try and call it from my
> client code using WebClient, it's throwing the following exception, Am
I
> missing something ?
> 
> Hi
> 
> 
> 
> WARNING: .No operation matching request path /customers is found,
> ContentType : */*, Accept :
> text/html,application/xhtml+xml,application/xml,.
> 
> Jul 29, 2009 10:38:23 AM
> org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
> 
> WARNING: WebApplicationException has been caught : no cause is
available
> 
> Jul 29, 2009 10:38:23 AM
> org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback
onClose
> 
>  
> 
> Here is the Client code :
> 
>  
> 
> WebClient wc =
>
WebClient.create("http://localhost:8080/cxf-webservices/webservices/cust
> omerservice");
> 
> wc.accept("text/html,application/xhtml+xml,application/xml");     
> 
> Response getresponse = wc.path("/customers").get();
> 
>  
> 
>  
> 
> Here is the Web Service :
> 
>     <jaxrs:server id="customerService" address="/">   
> 
>       <jaxrs:serviceBeans>  
> 
>           <ref bean="customerservice"/>
> 
>         </jaxrs:serviceBeans>
> 
>       </jaxrs:server>  
> 
>       <bean id="customerservice" class="test.CustomerService" />
> 
>  
> 
>  
> 
> @Path("/customerservice/")   
> 
> @Produces("text/xml")
> 
> public class CustomerService {
> 
>  
> 
>       private TreeMap<Integer, Customer> customerMap = new
> TreeMap<Integer, Customer>();
> 
>       public CustomerService() {
> 
>             //Hard coded for testing
> 
>             Customer customer = new Customer();
> 
>             customer.setId(0);
> 
>           customer.setName("Harold Abernathy");
> 
>           customer.setAddress("Sheffield, UK");
> 
>           addCustomer(customer);
> 
>     } 
> 
>  
> 
>         @GET
> 
>         @Path("/customers")
> 
>         public CustomerCollection getCustomers() {
> 
>           return new CustomerCollection( customerMap.values());
> 
>         }
> 
>  
> 
>         @GET
> 
>         @Path("/customers/{id}")
> 
>         public Customer getCustomer(@PathParam("id") int cId) {
> 
>               
> 
>           return customerMap.get(cId);
> 
>         }
> 
>  
> 
>         @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;
> 
>         }
> 
>  
> 
> Any help will be appreciated.
> 
> 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/Running-into-problems-with-using-WebClient-tp24724
574p24725928.html
Sent from the cxf-user mailing list archive at Nabble.com.


_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

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.


Re: Running into problems with using WebClient

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

I think the reason no match is found is that CustomerService uses a global
@Produces("text/xml")
values which applies to all resource methods unless specifically overridden,
while WebClient says it can accept 

text/html,application/xhtml+xml,application/xml

so you might want to update either a WebClient accept call or @Produces to
also include text/xml 

I'll update the server code which reports the problem to make sure a more
specific message is reported. You should also get a 406 response code in
this case (per the spec). Give it a try please.

cheers, Sergey


kiran.sidhu wrote:
> 
> Hi,
> 
>                  I have a simple RESTful Web Service that I got from one
> of the samples on the web.  I am able to invoke it from browser and it
> shows the output on the browser, but when I try and call it from my
> client code using WebClient, it's throwing the following exception, Am I
> missing something ?
> 
> Hi
> 
> 
> 
> WARNING: .No operation matching request path /customers is found,
> ContentType : */*, Accept :
> text/html,application/xhtml+xml,application/xml,.
> 
> Jul 29, 2009 10:38:23 AM
> org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
> 
> WARNING: WebApplicationException has been caught : no cause is available
> 
> Jul 29, 2009 10:38:23 AM
> org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
> 
>  
> 
> Here is the Client code :
> 
>  
> 
> WebClient wc =
> WebClient.create("http://localhost:8080/cxf-webservices/webservices/cust
> omerservice");
> 
> wc.accept("text/html,application/xhtml+xml,application/xml");     
> 
> Response getresponse = wc.path("/customers").get();
> 
>  
> 
>  
> 
> Here is the Web Service :
> 
>     <jaxrs:server id="customerService" address="/">   
> 
>       <jaxrs:serviceBeans>  
> 
>           <ref bean="customerservice"/>
> 
>         </jaxrs:serviceBeans>
> 
>       </jaxrs:server>  
> 
>       <bean id="customerservice" class="test.CustomerService" />
> 
>  
> 
>  
> 
> @Path("/customerservice/")   
> 
> @Produces("text/xml")
> 
> public class CustomerService {
> 
>  
> 
>       private TreeMap<Integer, Customer> customerMap = new
> TreeMap<Integer, Customer>();
> 
>       public CustomerService() {
> 
>             //Hard coded for testing
> 
>             Customer customer = new Customer();
> 
>             customer.setId(0);
> 
>           customer.setName("Harold Abernathy");
> 
>           customer.setAddress("Sheffield, UK");
> 
>           addCustomer(customer);
> 
>     } 
> 
>  
> 
>         @GET
> 
>         @Path("/customers")
> 
>         public CustomerCollection getCustomers() {
> 
>           return new CustomerCollection( customerMap.values());
> 
>         }
> 
>  
> 
>         @GET
> 
>         @Path("/customers/{id}")
> 
>         public Customer getCustomer(@PathParam("id") int cId) {
> 
>               
> 
>           return customerMap.get(cId);
> 
>         }
> 
>  
> 
>         @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;
> 
>         }
> 
>  
> 
> Any help will be appreciated.
> 
> 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/Running-into-problems-with-using-WebClient-tp24724574p24725928.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Running into problems with using WebClient

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

It's an issue with CXF JAXRS 2.2.2, the logging interceptor replaces the
HTTP in stream with another InputStream but WebClient fails to check it and
reads the HTTP stream again. Fixed in 2.2.3, for now please remove a logging
interceptor once you've confirmed the message is coming back
thanks, Sergey

 

kiran.sidhu wrote:
> 
> Hi,
> 
>                  I have a simple RESTful Web Service that I got from one
> of the samples on the web.  I am able to invoke it from browser and it
> shows the output on the browser, but when I try and call it from my
> client code using WebClient, it's throwing the following exception, Am I
> missing something ?
> 
>  
> 
> WARNING: .No operation matching request path /customers is found,
> ContentType : */*, Accept :
> text/html,application/xhtml+xml,application/xml,.
> 
> Jul 29, 2009 10:38:23 AM
> org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
> 
> WARNING: WebApplicationException has been caught : no cause is available
> 
> Jul 29, 2009 10:38:23 AM
> org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
> 
>  
> 
> Here is the Client code :
> 
>  
> 
> WebClient wc =
> WebClient.create("http://localhost:8080/cxf-webservices/webservices/cust
> omerservice");
> 
> wc.accept("text/html,application/xhtml+xml,application/xml");     
> 
> Response getresponse = wc.path("/customers").get();
> 
>  
> 
>  
> 
> Here is the Web Service :
> 
>     <jaxrs:server id="customerService" address="/">   
> 
>       <jaxrs:serviceBeans>  
> 
>           <ref bean="customerservice"/>
> 
>         </jaxrs:serviceBeans>
> 
>       </jaxrs:server>  
> 
>       <bean id="customerservice" class="test.CustomerService" />
> 
>  
> 
>  
> 
> @Path("/customerservice/")   
> 
> @Produces("text/xml")
> 
> public class CustomerService {
> 
>  
> 
>       private TreeMap<Integer, Customer> customerMap = new
> TreeMap<Integer, Customer>();
> 
>       public CustomerService() {
> 
>             //Hard coded for testing
> 
>             Customer customer = new Customer();
> 
>             customer.setId(0);
> 
>           customer.setName("Harold Abernathy");
> 
>           customer.setAddress("Sheffield, UK");
> 
>           addCustomer(customer);
> 
>     } 
> 
>  
> 
>         @GET
> 
>         @Path("/customers")
> 
>         public CustomerCollection getCustomers() {
> 
>           return new CustomerCollection( customerMap.values());
> 
>         }
> 
>  
> 
>         @GET
> 
>         @Path("/customers/{id}")
> 
>         public Customer getCustomer(@PathParam("id") int cId) {
> 
>               
> 
>           return customerMap.get(cId);
> 
>         }
> 
>  
> 
>         @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;
> 
>         }
> 
>  
> 
> Any help will be appreciated.
> 
> 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/Running-into-problems-with-using-WebClient-tp24724574p24727454.html
Sent from the cxf-user mailing list archive at Nabble.com.