Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jersey Rest Client  RSS feed

 
kri shan
Ranch Hand
Posts: 1488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jersey Rest client not returns city name.


Rest Service
########


@Path("services/result");
public class Service {

@GET
@Produces("application/json")
@Path("city")
public City getCityName() {
return "New York";

}



Rest Client
#######


public class RestClient {

public static void main(String[] args) {

ClientConfig clientConfig = new DefaultClientConfig();

clientConfig.getFeatures().put(JSONConfiguration.FEATUTRE_POJO_MAPPING, Boolean.TRUE);

Client client = Client.create(clientConfig);

WebResource webRes = client.resource("http://localhost:8080/rest/services/result/city");

ClientResponse response = webRes.accept("application/json").get(City.class);

String output = response.getEntity(City.class);

}
}

 
Vishal Bhadur Verma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it throwing any error ? If yes. Please post it

I think you have use @Path("/city").
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Vishal said, "/" should be there in the @Path string. It has to be @Path("/city"), otherwise the url you are referring would be considered as http://localhost:8080/rest/services/resultcity and in this url pattern no service has declared. Just change it and let us know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!