我正在研究WSO2 ESB代理服务,该服务涉及通过ESB上的SOAP端点公开内部RESTful服务。 我的RESTful服务需要Content-type =“application / rdf + xml”。我尝试使用文档中提到的所有3个属性设置它:messageType,ContentType和CONTENT_TYPE。但是,请求Content-type仍然是“application / xml”。
以下是我的序列中的一个调用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测试它,无论我使用什么Content-type属性,request仍然包含“application / xml”。
请建议。
答案 0 :(得分:5)
您可以尝试使用以下配置的WSO2 ESB 4.7.0吗?请注意,我已将地址格式从“pox”更改为“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="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 :(得分: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。
答案 2 :(得分:0)
有时,您必须在使用之前在axis2.xml中启用这些消息格式化程序。
查看此文章。如果你还没有这样做,它可能会有所帮助 http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf
答案 3 :(得分: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] for,选择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>