WSO2 ESB overwrites a ContentType property
Asked Answered
E

4

6

I am working on the WSO2 ESB Proxy service, which involves exposing the internal RESTful service via SOAP endpoint on the ESB. My RESTful service requires Content-type = "application/rdf+xml". I tried setting it using all 3 properties mentioned in the documentation: messageType, ContentType and CONTENT_TYPE. However, the request Content-type still remains "application/xml".

Here is an excerpt from my sequence that calls REST service:

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

I tested it with TCPMon and no matter what Content-type property I use, request still contains "application/xml".

Please advice.

Evelyne answered 19/6, 2013 at 14:58 Comment(1)
I'm guessing you're using ESB 4.6.0. There's a known bug in ESB 4.6.0 that always changes the outgoing content type to application/xml. A workaround is to switch to the NHTTP transport.Galileo
F
6

Can you try WSO2 ESB 4.7.0 with following configuration? Note that, I have changed the address format from "pox" to "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>

These are the http headers sent now (captured from 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
Feck answered 12/7, 2013 at 3:41 Comment(1)
This works! In fact, setting messageType property only to "application/rdf+xml" is enough. Thank you! +1Evelyne
M
1

In the configuration you have attached, you have specified the format of the address uri as "pox" .

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

This will be the reason that you are getting content-type as application/xml always. Please remove this attribute and try. It should be

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

If you still see the issue, then try to switch to the NHTTP transport as suggested by RaviU. For that, you can first backup the axis2.xml (ESB_HOME/repository/conf/axis2/axis2.xml) as axis2_back.xml and then rename the axis2_nhttp.xml file (same location) as axis2.xml.

Mathews answered 20/6, 2013 at 6:10 Comment(1)
Chanaka / RaviU, I tried both of your suggestions but none of them worked. When I removed "format='pox'", Content-type was set to "application/soap+xml". And I already was using NHTTP transport instead of the PassThrough: <transportReceiver class="org.apache.synapse.transport.nhttp.HttpCoreNIOListener" name="http"> and <transportSender class="org.apache.synapse.transport.nhttp.HttpCoreNIOSender" name="http">Evelyne
N
1

Can you set the content type property like this;

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

Please remove other content-type properties..

If you define like this;

 [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, to select messageformatter

[2]for, to select message builders

Edit; try like this

 <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>
Numerous answered 27/6, 2013 at 12:23 Comment(2)
Ratha, I just tried your suggestion but TCPMon still displays "Content-Type: application/xml; charset=UTF-8". Can you quickly create your own Proxy based on my configuration and try it yourself?Evelyne
@AlexYakimovich; i provided a sample for jSON, in your case it is different message type..You need to add the specific messageformatter in the axis2.xmlNumerous
R
0

Sometimes, you have to enable those message formatters in axis2.xml before using them.

Check this article out. It may help if you haven't done so yet.
http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf

Rolandrolanda answered 19/6, 2013 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.