【问题标题】:Calling Restlet client resource from server resource causes HTTP 404 error从服务器资源调用 Restlet 客户端资源导致 HTTP 404 错误
【发布时间】:2013-01-08 00:45:55
【问题描述】:

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

当我在我的代码中达到目的时:

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

我收到警告和错误:

2013 年 1 月 7 日下午 4:33:34 org.restlet.engine.component.ClientRouter getNext 警告:此请求使用的协议未在 客户端连接器列表。 (HTTPS/1.1)。如果您使用的是 Component 类的实例,检查它的“clients”属性。不是 Found (404) - 服务器没有找到任何匹配请求的东西 URI 在 org.restlet.resource.ClientResource.doError(ClientResource.java:612)

我搜索了一下,发现解决方案可能会像这样将协议添加到端点:

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

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

我还更改了我的 web.xml 以支持此协议,如下所示:

<?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 来解决它: [code] org.restlet.clients CLAP HTTP HTTPS [code]

标签: java restlet restlet-2.0


【解决方案1】:

尝试将以下内容添加到您的 web.xml 中的 &lt;servlet&gt; 元素内。

<!-- 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

【讨论】:

  • 我已将此添加到 web.xml,但我没有看到上述错误有任何变化。还有什么我可以尝试的吗?
  • 您的 com.MyApplication 需要是从 org.restlet.Application 派生的类的完整包范围名称(我是假设它不是真正的“com.MyApplication”,是吗?)。
【解决方案2】:

经过一番心痛后,我确定解决方案是在上面安迪所说的 web.xml 中添加参数,并添加以下 jars:

org.restlet.ext.net org.restlet.ext.httpclient org.restlet.ext.ssl

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    相关资源
    最近更新 更多