【问题标题】:WSO2 ESB overwrites a ContentType propertyWSO2 ESB 覆盖 ContentType 属性
【发布时间】:2013-06-16 04:27:27
【问题描述】:

我正在开发 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 属性,请求仍然包含“application/xml”。

请指教。

【问题讨论】:

  • 我猜你使用的是 ESB 4.6.0。 ESB 4.6.0 中有一个已知的错误,它总是将传出内容类型更改为 application/xml。一种解决方法是切换到 NHTTP 传输。

标签: wso2 wso2esb


【解决方案1】:

有时,您必须先在axis2.xml 中启用这些消息格式化程序,然后才能使用它们。

查看这篇文章。如果您还没有这样做,它可能会有所帮助。
http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf

【讨论】:

    【解决方案2】:

    在您附加的配置中,您已将地址 uri 的格式指定为“pox”。

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

    这将是您始终将 content-type 设为 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。

    【讨论】:

    • Chanaka / RaviU,我尝试了你的两个建议,但都没有奏效。当我删除“format='pox'”时,Content-type 被设置为“application/soap+xml”。而且我已经在使用 NHTTP 传输而不是 PassThrough:
    【解决方案3】:

    你可以这样设置内容类型属性吗?

     <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, 选择消息格式化程序

    [2]for, 选择消息构建器

    编辑; 试试这样

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

    【讨论】:

    • Ratha,我刚刚尝试了您的建议,但 TCPMon 仍然显示“Content-Type: application/xml; charset=UTF-8”。能不能根据我的配置快速创建自己的Proxy,自己试试?
    • @AlexYakimovich;我为 jSON 提供了一个示例,在您的情况下,它是不同的消息类型。您需要在 axis2.xml 中添加特定的消息格式化程序
    【解决方案4】:

    您可以尝试使用以下配置的 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
    

    【讨论】:

    • 这行得通!事实上,只将 messageType 属性设置为“application/rdf+xml”就足够了。谢谢! +1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2014-07-07
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2015-03-27
    • 1970-01-01
    相关资源
    最近更新 更多