OSGi 中的 Restlet HTTP 问题
我是 Restlet 框架(2.08 版)的着迷用户。这就是为什么我目前正在尝试在 OSGi 环境中使用 Restlet 来完成我论文的实践部分。最后,我创建了一个服务器包(它由我的 Felix OSGi 环境中的 Activator 启动)并显示一条消息作为对 http://localhost:8888/
等简单调用的响应。
但我没有成功从我的 Restlet 接收其他资源。想象一下,我需要来自 http://localhost:808 0/tripleStore/triple s/5
的数据来计算 http://localhost:8888/test< 的结果/代码>。 (代码片段如下...)
public void startServer() throws Exception {
component = new Component();
Server server = new Server ( Protocol.HTTP, 8888);
component.getServers().add(server);
Client client = new Client (Protocol.HTTP);
component.getClients().add(client);
Restlet restlet = new Restlet() {
@Override
public void handle(Request request, Response response) {
response.setEntity("Container Resource is active!", MediaType.TEXT_PLAIN);
}
};
Restlet restletTest = new Restlet() {
@Override
public void handle(Request request, Response response) {
RdfClientResource cli = new RdfClientResource("http://localhost:8080/tripleStore/triples/5");
cli.setFollowingRedirects(false);
Representation repri = cli.get();
response.setEntity(repri);
}
};
component.getDefaultHost().attach("/container",new Sink());
component.getDefaultHost().attach("/test",restletTest);
component.getDefaultHost().attach(restlet);
component.getClients().add(Protocol.HTTP);
component.start();
}
目前,我在致电时收到“错误请求”错误 http://localhost:808 0/tripleStore/triple s/5
在我的 Restlet 中,当我调用 http://127.0.0.1:808 0/tripleStore 时出现“禁止”错误/triple s/5
来自我的 Restlet。
进一步的研究表明,造成这个错误的原因非常简单。 Restlet 尝试直接从网络代理获取结果,该代理不知道任何 localhost
并且禁止调用 127.0.0.1
。
另一个关键点是,除了一次尝试之外,错误总是可复制的。在这种情况下,一切正常。这就是为什么我假设与 OSGi 启动顺序有关。 (这不是修复,取决于 Sonatype Aether 框架。)
您是否已经意识到这样的错误?您能否建议我修复任何错误,避免手动尝试所有 OSGi 启动命令?当我尝试在 OSGi 之外做这些事情时,一切都工作得很好。
提前致谢! 马库斯
I'm a fascinated user of the Restlet framework (version 2.08). This is why I'm currently trying to use Restlet in an OSGi environment for the practical part of my thesis. Finally, I arrived to create a server bundle (which is started by the Activator in my Felix OSGi environment) and to show a message as a response to a simple call like http://localhost:8888/
.
But I don't succeed to receive another resource from my Restlet. Imagine the case that I need data from http://localhost:8080/tripleStore/triples/5
in order to calculate the result of http://localhost:8888/test
. (code snippet follows...)
public void startServer() throws Exception {
component = new Component();
Server server = new Server ( Protocol.HTTP, 8888);
component.getServers().add(server);
Client client = new Client (Protocol.HTTP);
component.getClients().add(client);
Restlet restlet = new Restlet() {
@Override
public void handle(Request request, Response response) {
response.setEntity("Container Resource is active!", MediaType.TEXT_PLAIN);
}
};
Restlet restletTest = new Restlet() {
@Override
public void handle(Request request, Response response) {
RdfClientResource cli = new RdfClientResource("http://localhost:8080/tripleStore/triples/5");
cli.setFollowingRedirects(false);
Representation repri = cli.get();
response.setEntity(repri);
}
};
component.getDefaultHost().attach("/container",new Sink());
component.getDefaultHost().attach("/test",restletTest);
component.getDefaultHost().attach(restlet);
component.getClients().add(Protocol.HTTP);
component.start();
}
Currently I'm getting a "bad request"-error when I callhttp://localhost:8080/tripleStore/triples/5
in my restlet and a "forbidden"-error when I call http://127.0.0.1:8080/tripleStore/triples/5
from my Restlet.
Further research has shown that the cause for this errors is quite simple. The restlet tries to get it's results directly from the network proxy, which doesn't know any localhost
and forbids the call to 127.0.0.1
.
Another critical point is, that the error was always replicable, except during one try. In this case, everything worked fine. This is why I assume a relation to the OSGi startup order. (Which isn't fix and depends on the Sonatype Aether-framework.)
Are you already aware of an error like this? And can you suggest me any bugfix avoiding to try all OSGi startup orders by hand? When I try to do these things outside of OSGi, everything works quite fine.
Thanks in advance!
Marcus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题让我想起了我遇到的一个问题。您必须记住的是,客户端连接器会自动注册到 Restlet 引擎。这里的问题是包加载的顺序。
我的问题与 HTTPS 连接器有关。尝试添加客户端连接器时,您必须确保提供连接器的捆绑包已加载。否则,我会在跟踪中看到类似的内容:
也许在添加客户端连接器之前,您可以检查加载的捆绑包以及在执行 REST 请求之前,注册的客户端连接器吗?
以下是查看已注册客户端连接器的代码:
您可以使用 OSGi 捆绑包侦听器来查看是否加载了必要的捆绑包。以下是代码示例:
registerClientConnector 方法仅执行类似以下操作:component.getClients().add(Protocol.HTTPS);。
希望对您有帮助。请随时向我发送一个最小的项目来重现问题,以便我可以更准确地提供帮助。
蒂埃里
Your problem remind me a problem I had. What you must have in mind is that client connectors are automatically registered against the Restlet engine. The problem here is the order in the bundle loading.
My problem was about the HTTPS connector. You must be sure that the bundle providing the connector is already loaded when trying to add the client connector. Otherwise I'll see something like that in the trace:
Perhaps before adding your client connector can you check the loaded bundles and before executing your REST request, the registered client connector?
Here is the code to see registered client connectors:
You can use OSGi bundle listeners to see if necessary bundles are loaded. Here is a sample of code:
The registerClientConnector method simply does something like that: component.getClients().add(Protocol.HTTPS);.
Hope it helps you. Don't hesitate to send me a minimal project to reproduce the problem so I can help more precisely.
Thierry