无法接收来自 Mule 的 HTTP 响应
我正在创建一个基本服务组件,该组件将 URL 作为 http 入站端点的输入。 mule-config 文件中的代码片段如下:
<service name="follow">
<inbound>
<http:inbound-endpoint address="http://localhost:8765/follow/" synchronous="true"/>
</inbound>
<component class="org.mule.application.mytwitter.Follow" />
</service>
从 Java 组件类调用的函数是:
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage msg = eventContext.getMessage();
String str = msg.getStringProperty("http.request", null);
msg.setPayload(str);
msg.setStringProperty("http.status","200");
msg.setStringProperty("Content-Type","text/html");
System.out.println("Reached here:" + str);
return msg;
}
我希望通过 CURL 访问服务来接收 HTTP 响应(有效负载),如下所示:
curl -vv“http://localhost:8765/follow/”
但我没有收到任何有效负载:
> * About to connect() to localhost port 8765 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 8765 (#0)
> GET /follow/ HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: localhost:8765
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Date: Tue, 27 Dec 2011 03:14:00 IST
< Server: Mule Core/2.1.2
< Expires: Tue, 27 Dec 2011 03:14:00 IST
< Content-Length: 0
< Connection: close
<
* Closing connection #0
我错过了什么吗?正在调用组件类中的函数,并在控制台中打印输出。
I am creating a basic service component that takes a URL as input at http inbound endpoint. Code snippet from the mule-config file is as follows:
<service name="follow">
<inbound>
<http:inbound-endpoint address="http://localhost:8765/follow/" synchronous="true"/>
</inbound>
<component class="org.mule.application.mytwitter.Follow" />
</service>
and the function that is called from the Java component class is:
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage msg = eventContext.getMessage();
String str = msg.getStringProperty("http.request", null);
msg.setPayload(str);
msg.setStringProperty("http.status","200");
msg.setStringProperty("Content-Type","text/html");
System.out.println("Reached here:" + str);
return msg;
}
I wish to receive an HTTP response(payload) by hitting the service through CURL as:
curl -vv "http://localhost:8765/follow/"
but I'm not receiving any payload:
> * About to connect() to localhost port 8765 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 8765 (#0)
> GET /follow/ HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: localhost:8765
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Date: Tue, 27 Dec 2011 03:14:00 IST
< Server: Mule Core/2.1.2
< Expires: Tue, 27 Dec 2011 03:14:00 IST
< Content-Length: 0
< Connection: close
<
* Closing connection #0
Am I missing something? The function in component class is being called and output is printed in console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是故意用这么老版本的mule吗?有更新的 3.2.1 版本可用。我建议您转向流式消息传递而不是服务。
但要回答您的问题,如果您希望打印出响应有效负载,那么您应该在配置中添加一个字符串转换器。我不记得如何将其配置到服务元素,但是如果您使用流,那么您可以在流的末尾添加一个响应块。
我希望这会有所帮助。
Are you intentionally using such an old version of mule? There's a much newer 3.2.1 version available. And I suggest you to move to flow-style messaging instead of services.
But to answer your problem, if you want to have the response payload to print out, then you should add a string transformer to you configuration. I don't remember exactly how to configure this to the service element, but if you use flow's then you can add a response block to the end of the flow.
<http:http-response-to-string-transformer />
I hope this helps.
别介意伙计们。我想出了一些办法,现在效果很好。 inbound-endpoint 有一个名为 syncResponse 的属性。将其设置为true使其同步工作。我认为 Mule 2.1.2 或某些系统设置有问题。
never mind guys. i figured out something and it works fine now. there's an attribute called syncResponse for inbound-endpoint. Setting it to true makes it work synchronously. I think some problem to do with Mule 2.1.2 or maybe some system settings.