Jersey를 사용하고 this example을 따르는 RESTFul 웹 서비스를 배우려고합니다.Jersey를 사용하는 클라이언트에서 RESTFul Web Service 호출 문제
http://localhost:8080/de.vogella.jersey.first/rest/hello.
나는이 서비스를 호출하는 클라이언트를 만든하지만이 클라이언트를 실행하면 다음과 같이 내가 예외를 얻을 :
GET http://localhost:8080/de.vogella.jersey.first/rest/hello
returned a response status of 404 Not Found Exception in thread "main"
com.sun.jersey.api.client.UniformInterfaceException:
GET http://localhost:8080/de.vogella.jersey.first/rest/hello
returned a response status of 404 Not Found
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
at de.vogella.jersey.first.client.Test.main(Test.java:23)
서비스 클래스가되어 나는에 액세스 할 수있는 샘플 서비스를 만들었습니다
public class Hello {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
클라이언트 코드 :
public class Test {
public static void main(String[] args) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());
System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_XML).get(String.class));
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8080/de.vogella.jersey.first").build();
}
}
01 23,516,
이상한 부분은 내가 브라우저에서
http://localhost:8080/de.vogella.jersey.first/rest/hello
에 충돌하면 올바른 결과를 얻을 수있다. 이 문제를 해결할 수있는 도움을 주시면 감사하겠습니다. 감사합니다
무엇이 문제입니까? 무슨 일 이니? – KatieK
문제는 클라이언트가 브라우저에서 정상적으로 작동하는 URL에 액세스 할 수 없다는 것입니다. 나는 오늘 그것을 실제로 작동시킬 필요가있다. 도와주세요. – Preeti
클라이언트에서 보내는 HTTP 헤더는 무엇입니까? – Yaniv