[英]Can't receive an HTTP response from Mule
I am creating a basic service component that takes a URL as input at http inbound endpoint . 我正在创建一个基本服务组件,该组件将URL作为http入站终结点处的输入 。 Code snippet from the mule-config file is as follows:
来自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>
and the function that is called from the Java component class is: 从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;
}
I wish to receive an HTTP response(payload) by hitting the service through CURL as: 我希望通过CURL通过以下方式访问服务来接收HTTP响应(有效负载):
curl -vv "http://localhost:8765/follow/"
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.
组件类中的函数被调用,输出被打印在控制台中。
Are you intentionally using such an old version of mule? 您是否有意使用这种旧版本的m子? There's a much newer 3.2.1 version available.
有一个更新得多的3.2.1版本。 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.
我不记得确切如何将其配置到service元素,但是如果您使用流程的话,则可以在流程的末尾添加一个响应块。
<http:http-response-to-string-transformer />
I hope this helps. 我希望这有帮助。
never mind guys. 没关系的家伙。 i figured out something and it works fine now.
我想出了一点,现在可以正常工作了。 there's an attribute called syncResponse for inbound-endpoint .
入站端点有一个名为syncResponse的属性。 Setting it to true makes it work synchronously.
将其设置为true将使其同步工作。 I think some problem to do with Mule 2.1.2 or maybe some system settings.
我认为与Mule 2.1.2或某些系统设置有关的某些问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.