使用Apache HTTp客户端调用Camlet RESTLET服务器

时间:2013-10-02 00:21:59

标签: rest apache-camel restlet restlet-2.0

这个应该是微不足道的,但不知何故它对我不起作用。我正在尝试调用Camel上托管的RESTLET服务器。我得到它使用Camel客户端,但我试图使用相同的工作与裸Apache HTTP客户端。 Camel是客户端如下:

   CamelContext context = new DefaultCamelContext();
   Map<String, Object> headers = new HashMap<String, Object>();
   context.createProducerTemplate().requestBodyAndHeaders("restlet:http://localhost:8086/Bookmarkee/boolean/V2?restletMethod=post", "Halleluia",headers);

我正在努力工作的HTTP客户端是这样的:

        HttpPost httppost = new HttpPost("http://localhost:8086/Bookmarkee/boolean/V2?restletMethod=post");
        StringEntity e= new StringEntity("Halleluia",ContentType.create("text/plain", "UTF-8"));
        httppost.setEntity(e);
        CloseableHttpResponse response = httpclient.execute(httppost);

但是,在服务器上,servlet引擎不会从流中读取响应。导致我的组件传递输入流而不是字符串。

有任何线索吗?

1 个答案:

答案 0 :(得分:0)

当我的camel路由尝试处理来自服务器的空响应时遇到同样的问题(200 OK,Content-Length:0,Content-Type:application / json) 我发现并修复了我用于使用http组件

请求的URL中的错误后修复