2013-12-20 2 views
2

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을 변경하고 지금은 추상 클래스입니다. HelloServices 클래스의 추상적 인 방법이다, 물론

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를 사용해 보겠습니다.

:.. __ (

답변

1

수출 프로젝트를 .war 파일로하여 서버에 배포해야 그런 다음 경로가 될 것입니다 당신이 매개 변수를 전달하려면 http://localhost:port/Project_Name/myServices. 당신은 router.attach("/myServices/{name}", Services.class);을 추가해야합니다. 그리고 당신은 http://localhost:port/Project_Name/myServices/myName를 작성할 수 있습니다.

this example를 살펴 보자.

+0

Services 클래스에 많은 메소드가 필요합니다. 그래서, router.attach ("/ myServices/otherMethod1")'를 어디에 추가해야합니까? ServicesApplication 클래스에서 true입니까? 당신이 내게'router.attach ("/ myServices", Services.클래스);''hello' 메서드 만 호출합니까? – jjmartinez

+0

응답 해 주셔서 감사합니다. 나는 Restlet이 그 저지 또는 RestEasy를 사용하는 것이 더 복잡하다고 생각한다. ( – jjmartinez

+1

지난 여름 Restlet과 함께 일했고 내가 기억하는 유일한 것은 내가 그것을 싫어한다는 것이다! : p 그리고 예 저지는 더 쉽다. 그리고 마지막 질문은 아마도 [이 링크] (http://stackoverflow.com/questions/7608694/multiple-get-methods-in-single-resource-class-with-restlet) 도움을 줄 수 있습니다. – Sergi

1

이 페이지 here 당신이 시작하는 당신에게 몇 가지 아이디어를 제공

+0

Javadoc이 나에게 명확하지 않습니다. ( – jjmartinez