2011-12-27 86 views
1

我正在創建一個基本服務組件,該URL以http入站端點爲輸入。從騾配置文件的代碼段如下所示:無法接收來自Mule的HTTP響應

<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; 
    } 

我希望收到通過HTTP響應(有效載荷)打黑服務,通過捲曲如:

捲曲-vv的 「http://本地主機:8765 /遵循/」

但我沒有收到任何有效載荷:

> * 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 

我缺少的東西?正在調用組件類中的功能,並將輸出打印在控制檯中。

+0

你究竟想達到什麼目的? – 2011-12-27 12:56:36

+0

你在控制檯中得到什麼? 「到達這裏之後:」是什麼? – 2011-12-27 16:53:18

回答

0

沒關係傢伙。我想出了一些東西,現在它工作正常。有一個名爲syncResponse的屬性,用於入站端點。將其設置爲true使其同步工作。我認爲一些與Mule 2.1.2有關的問題或者一些系統設置。

1

你有意使用這樣一個老版本的騾子嗎?有一個更新的3.2.1版本可用。我建議你轉向流式消息而不是服務。

但是要回答你的問題,如果你想要打印出響應有效負載,那麼你應該爲你的配置添加一個字符串轉換器。我不記得如何配置這個服務元素,但如果你使用流的話,你可以添加一個響應塊到流的末尾。

<http:http-response-to-string-transformer />

我希望這有助於。