facebook

Cannot invoke Rest Web service

  1. MyEclipse Archived
  2.  > 
  3. Web Services
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #301978 Reply

    Jirawat
    Member

    I’ve tried to follow Customers quick strat: http://www.myeclipseide.com/documentation/quickstarts/webservices_rest/.

    But I cannot connect to my webservice:
    Code:
    Client rclient = Client.create();
    WebResource resource = rclient.resource(“http://localhost:8080/restdemo/services/customers/0”);
    resource.accept(“application/xml”);
    Customer cus = resource.get(Customer.class);

    Exception:
    Exception in thread “main” com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java type, class com.myeclipseide.ws.Customer, and MIME media type, application/xml, was not found
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:526)
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:491)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:561)
    at com.sun.jersey.api.client.WebResource.get(WebResource.java:179)
    at com.test.rest.RClient.main(RClient.java:16)

    Any help is appreciated.
    Thank you

    #301986 Reply

    Brian Fernandes
    Moderator

    Jirawat,

    Did you add the @XmlRootElement annotation to your Customer class? For an explanation, please see the table in section 4.1 in the REST tutorial you referenced.

    Note that you could also use the REST explorer to test your service before writing a client application.

    Hope this helps.

    #302022 Reply

    Jirawat
    Member

    Brian,
    I’ve added @XmlRootElement to Customer class.

    @XmlRootElement
    public class Customer {…

    My REST webservice is work properly in REST explorer.
    Below is my client code:
    Client rclient = Client.create();
    WebResource resource = rclient.resource(“http://localhost:8080/Osellus/services/customers/0”);
    Builder builder = resource.type(“application/xml”);
    Customer str = builder.get(Customer.class);

    But after, I’ve tried to change return type of getCustomer to String, see below:
    @GET
    @Path(“{id}”)
    @Produces(“text/plain”)
    public String getCustomer(@PathParam(“id”) int cId) {
    return customerMap.get(cId).getName();
    }

    I can retrieve customer name by following code:
    String str = builder.get(String.class);

    I think the exception is thrown after retrived data from webservice and tried to cast it to Customer.

    Thank you,

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Cannot invoke Rest Web service

You must be logged in to post in the forum log in