Restlet으로 REST 서비스를 개발하고 싶습니다. org.restlet.Application 클래스를 확장하는 클래스 하나와 org.restlet.resource.ServerResource 클래스를 확장하는 클래스가 있습니다.개발 및 배치 a Restlet 서비스
일등 한 방법 갖는다:
public class ServicesApplication extends Application {
public Restlet createInboundRoot() {
// Create a router Restlet that routes each call to a
// new instance of HelloWorldResource.
Router router = new Router(getContext());
// Defines only one route
router.attach("/myServices", Services.class);
return router;
}
}
및 두번째 클래스는 예를 들어,을 HelloWorld 서비스의 여러 가지 방법을 갖는다 :
public class Services extends ServerResource{
@Get ("hello")
public void Hello(String name){
System.out.println("Hello "+name);
}
}
문제 I가 없다는 것이다 Tomcat에서 서비스를 배포하려면 어떻게해야합니까? Tomcat의 webapps 폴더에 .war 파일을 생성하고 저장해야합니까? 그리고 ServerResource를 구현하는 클래스에서 Application 클래스에 구현되는 클래스를 호출해야하는지 여부는 알 수 없습니다. 마지막으로 "Hello"를 호출하는 URL이 정확히 무엇인지 알 수 없습니다. http://myDomain:myPort/myServices/hello?name=MyName
???? 사전
UPDATE
에서
이감사합니다 나는 내 응용 프로그램을 업데이트 : 나는 ServicesApplication을 변경하고 지금은 추상 클래스입니다. Hello
는 Services
클래스의 추상적 인 방법이다, 물론
public class HelloWorldService extends Services {
public String Hello(String name){
System.out.println("Hello "+name);
return("Hello"+name);
}
}
: 또한 나는 ServicesApplication 클래스에 확장 다른 클래스를 추가 할 수 있습니다.
router.attach("/helloWorld/{name}", HelloWorldService.class);
내 네비게이터에서이 방법으로 호출하고 있습니다 :
또한 나는 ServicesApplication
이 줄을 추가
http://localhost:8080/myServices/service/helloWorld/Jesus
를이는 반응이다 :
Hello null
메소드를 어떻게 호출해야합니까 ???
나는 단지 Hello +name
을하고 싶습니다. 이 기사에서는 JSON String을 매개 변수로 사용하여 GET 및 POST 메서드를 개발하려고합니다. 그러나 간단한 HelloWorld를 Reslet으로 개발하는 것이 매우 어려운 경우 RestEasy를 사용해 보겠습니다.
:.. __ (
Services 클래스에 많은 메소드가 필요합니다. 그래서, router.attach ("/ myServices/otherMethod1")'를 어디에 추가해야합니까? ServicesApplication 클래스에서 true입니까? 당신이 내게'router.attach ("/ myServices", Services.클래스);''hello' 메서드 만 호출합니까? – jjmartinez
응답 해 주셔서 감사합니다. 나는 Restlet이 그 저지 또는 RestEasy를 사용하는 것이 더 복잡하다고 생각한다. ( – jjmartinez
지난 여름 Restlet과 함께 일했고 내가 기억하는 유일한 것은 내가 그것을 싫어한다는 것이다! : p 그리고 예 저지는 더 쉽다. 그리고 마지막 질문은 아마도 [이 링크] (http://stackoverflow.com/questions/7608694/multiple-get-methods-in-single-resource-class-with-restlet) 도움을 줄 수 있습니다. – Sergi