【问题标题】:Can't receive an HTTP response from Mule无法接收来自 Mule 的 HTTP 响应
【发布时间】:2012-01-18 15:53:09
【问题描述】:

我正在创建一个基本服务组件,它在 http 入站端点 将 URL 作为输入。 mule-config文件中的sn-p代码如下:

    <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

我错过了什么吗?正在调用组件类中的函数,并在控制台中打印输出。

【问题讨论】:

  • 你到底想达到什么目的?
  • 您在控制台中得到了什么? “到达这里:”之后是什么?

标签: java http mule


【解决方案1】:

你是故意用这么旧的mule吗?有一个更新的 3.2.1 版本可用。我建议您转向流式消息传递而不是服务。

但是要回答您的问题,如果您想打印出响应负载,那么您应该在配置中添加一个字符串转换器。我不记得具体如何将它配置到服务元素,但如果你使用流,那么你可以在流的末尾添加一个响应块。

&lt;http:http-response-to-string-transformer /&gt;

我希望这会有所帮助。

【讨论】:

    【解决方案2】:

    别介意伙计们。我想出了一些东西,它现在工作正常。 inbound-endpoint 有一个名为 syncResponse 的属性。将其设置为 true 使其同步工作。我认为某些问题与 Mule 2.1.2 或某些系统设置有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多