在Java App服务器中部署的Restlet RIAP协议

Jan*_*avn 2 java restlet restlet-2.0

我已使用ServerServlet机制将我们的Restlet服务部署到Jetty Java Application服务器.一些服务是从GWT前端调用的,但我还需要直接从我们的服务器逻辑中调用它们.

的Restlet RIAP系统似乎为这个完美的,但我不知道如何在这里使用.似乎我需要以某种方式阻止Restlet组件的Context.

我发现一个帖子表明RiapServerHelper对此很有用.但我没有找到关于如何使用它的文档.任何例子都会有所帮助.

Thi*_*ier 6

RiapServerHelper类是服务器连接器的实现.您不必明确使用它.

要使用RIAP,您需要像往常一样实现应用程序的所有实体(服务器资源,应用程序......).将应用程序附加到组件虚拟主机时会出现差异.需要通过RIAP访问的资源也必须连接到内部路由器,如下所示:

Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);

MyApplication app = new MyApplication();
component.getDefaultHost().attachDefault(app);
component.getInternalRouter().attachDefault(app);
Run Code Online (Sandbox Code Playgroud)

请注意,您不必为组件指定RIAP协议.它默认支持.

通过RIAP访问应用程序的资源非常简单,因为您可以像使用其他协议一样使用Restlet客户端支持:

Request request = new Request(Method.GET, "riap://component/ping");
Response response = getContext().getClientDispatcher().handle(request);
Representation repr = response.getEntity();
Run Code Online (Sandbox Code Playgroud)

要么

ClientResource cr = new ClientResource("riap://component/ping");
Representation repr = cr.get();
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请查看页面http://wiki.restlet.org/docs_1.1/13-restlet/27-restlet/48-restlet/86-restlet/45-restlet.html.

希望这能回答你的问题.蒂埃里