- This topic has 2 replies, 2 voices, and was last updated 15 years, 2 months ago by Jirawat.
-
AuthorPosts
-
JirawatMemberI’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
Brian FernandesModeratorJirawat,
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.
JirawatMemberBrian,
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,
-
AuthorPosts