gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:50:22 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com