2013-06-19 183 views
4

我正在研究WSO2 ESB代理服務,它涉及通過ESB上的SOAP端點公開內部RESTful服務。 我的RESTful服務需要Content-type =「application/rdf + xml」。我嘗試使用文檔中提到的所有3個屬性來設置它:messageType,ContentType和CONTENT_TYPE。但是,請求Content-type仍然是「application/xml」。WSO2 ESB覆蓋ContentType屬性

這裏是我的順序調用REST服務的摘錄:

<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/> 
    <property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/> 
    <property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    <property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    <property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    <send> 
     <endpoint name="CQ"> 
     <address uri="http://my_url" format="pox"> 
     </address> 
     <property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/> 
     <property name="OSLC-Core-Version" value="2.0" scope="transport"/> 
     <property name="Accept" value="application/rdf+xml" scope="transport"/> 
     </endpoint> 
    </send> 

我TCPMon的,也不管我用什麼樣的內容類型的屬性,要求中仍包含「應用程序/ XML」進行了測試。

請指教。

+0

我猜你正在使用ESB 4.6.0。 ESB 4.6.0中有一個已知的錯誤,它總是將傳出的內容類型更改爲application/xml。解決方法是切換到NHTTP傳輸。 – RaviU

回答

5

你可以試試WSO2 ESB 4.7.0與下面的配置?需要注意的是,我已經改變了從「痘」的地址格式爲「休息」

<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/> 
    <property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/> 
    <property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    <property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    <property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    <send> 
     <endpoint name="CQ"> 
     <address uri="http://my_url" format="rest"> 
     </address> 
     <property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/> 
     <property name="OSLC-Core-Version" value="2.0" scope="transport"/> 
     <property name="Accept" value="application/rdf+xml" scope="transport"/> 
     </endpoint> 
    </send> 

現在這些發送的HTTP標頭(來自TCPMON捕獲)

PUT /record/12345 HTTP/1.1 
Cookie: region1_configure_menu=none; region3_registry_menu=none; region4_monitor_menu=none; region5_tools_menu=none; JSESSIONID=54D2911FCD5559C6B2F723E7C6FA9B44; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23 
Authorization: null 
OSLC-Core-Version: 2.0 
Content-Type: application/rdf+xml 
Accept: application/rdf+xml 
Transfer-Encoding: chunked 
Host: www.foo.com:8080 
Connection: Keep-Alive 
User-Agent: Synapse-PT-HttpComponents-NIO 
+1

This Works!實際上,僅將messageType屬性設置爲「application/rdf + xml」就足夠了。謝謝! +1 –

1

在您已經附加的配置中,您已將地址uri的格式指定爲「pox」。

<address uri="http://my_url" format="pox"> 

這將是您獲取內容類型爲application/xml的原因。請刪除此屬性並嘗試。它應該是

<address uri="http://my_url"> 

如果您仍然看到問題,然後嘗試切換到RaviU建議的NHTTP傳輸。爲此,您可以先將axis2.xml(ESB_HOME/repository/conf/axis2/axis2.xml)備份爲axis2_back.xml,然後將axis2_nhttp.xml文件(相同位置)重命名爲axis2.xml。

+0

Chanaka/RaviU,我嘗試了你的兩個建議,但都沒有工作。當我刪除「format ='pox'」時,Content-type被設置爲「application/soap + xml」。我已經使用NHTTP傳輸代替PassThrough: and

0

你可以像這樣設置內容類型屬性;

<property name="Content-Type」 value="application/rdf+xml" scope="transport"/> 

請刪除其他內容類型屬性..

如果你像這樣定義;

[1]<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/> 
    [2]<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/> 

[1],以選擇messageformatter

[2],選擇消息的助洗劑

編輯; 嘗試這樣

<inSequence> 
      <log level="custom"> 
       <property name="in seq --------------of proxy" expression="$trp:Content-Type"/> 
      </log> 
      <property name="messageType" 
         value="application/json" 
         scope="axis2" 
         type="STRING"/> 
      <property name="Content-Type" 
         value="application/json" 
         scope="transport" 
         type="STRING"/> 
      <log level="custom"> 
       <property name="in seq --------------of proxy" expression="$trp:Content-Type"/> 
      </log> 
      <send> 
       <endpoint> 
        <address uri="http://localhost:5555/com"/> 
       </endpoint> 
      </send> 
+0

Ratha,我只是嘗試了你的建議,但TCPMon仍然顯示」Content-Type:application/xml; charset = UTF-8「。您能否根據我的配置快速創建自己的代理並自行嘗試? –

+0

@AlexYakimovich;我爲jSON提供了一個示例,在您的情況下它是不同的消息類型。您需要在axis2.xml中添加特定的消息格式 – Ratha

+0

它也不工作。 –