java - 从服务器资源调用 ReSTLet 客户端资源导致 HTTP 404 错误

标签 java restlet restlet-2.0

我有一个 ReSTLet 服务器应用程序,它调用客户端资源以访问 google 端点。

当我到达我的代码中的要点时:

ClientResource storeRoot = new ClientResource("http://googleendpoint");
  String jsonString = storeRoot.get().getText();

我收到警告和错误:

Jan 7, 2013 4:33:34 PM org.restlet.engine.component.ClientRouter getNext WARNING: The protocol used by this request is not declared in the list of client connectors. (HTTPS/1.1). In case you are using an instance of the Component class, check its "clients" property. Not Found (404) - The server has not found anything matching the request URI at org.restlet.resource.ClientResource.doError(ClientResource.java:612)

我用谷歌搜索了一下,发现解决方案很可能是像这样将协议(protocol)添加到端点:

component.getClients​().add(Protocol.HTTPS​);

问题是我在 tomcat 中将其作为 war 文件运行。我在哪里访问这个组件对象来添加协议(protocol)?

我还更改了我的 web.xml 以支持这样的协议(protocol):

<?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

         <display-name>Restlet adapters</display-name>

         <servlet>
                 <servlet-name>Restlet1</servlet-name>
                 <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
                 <init-param>
                         <param-name>org.restlet.application</param-name>
                         <param-value>com.MyApplication</param-value>
                 </init-param>
                 <init-param>
                    <param-name>org.restlet.clients</param-name>
                    <param-value>HTTP HTTPS FILE</param-value>
                </init-param>
         </servlet>

         <servlet-mapping>
                 <servlet-name>Restlet1</servlet-name>
                 <url-pattern>/*</url-pattern>
         </servlet-mapping>
 </web-app>

最佳答案

尝试将以下内容添加到您的 web.xml 中,在 <servlet> 中元素。

<!-- Your application class name -->
<init-param>
    <param-name>org.restlet.application</param-name>
    <param-value>test.MyApplication</param-value>
</init-param>

<!-- List of supported client protocols -->
<init-param>
    <param-name>org.restlet.clients</param-name>
    <param-value>HTTP HTTPS FILE</param-value>
</init-param>

参见 http://www.restlet.org/documentation/snapshot/gae/ext/org/restlet/ext/servlet/ServerServlet.html以获得更完整的文档。

关于java - 从服务器资源调用 ReSTLet 客户端资源导致 HTTP 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14206607/

相关文章:

tomcat - Tomcat 中使用 ReSTLet 的路径目录

java - 帮助通过 nat 与套接字通信

c# - Java2C#翻译: public methods in Interfaces in C#

java - 为链表中的数组对象创建 'sort' 方法

java - 如何创建 protected ReSTLet资源?

java - 使用 ReSTLet 设置自定义内容范围 header

java - 查找包含 { } 且不包含特定字符串的行数

java - 如何在 Java 中获取 AJAX 值

java - ReSTLet javax.net.ssl.SSLHandshakeException : null cert chain

java - 尝试在 Google App Engine 上使用 ReSTLets 制作登录认证页面