Question

In my case, with the right query server always returns an XML response that is normally processed and sent back. But at the same time, the server configuration is such that when an incorrect query it returns an HTML response instead of XML.If you attempt to handle or how to replace, re-create the body of the response I just get an error parsing the only thing that works is simply sent back to the user.Is it possible to somehow avoid the parsing process and send the error in my personal format?

Few details:

so I get a response code

<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="$axis2:HTTP_SC" scope="default" type="STRING"/>

choose a processor and just send all got back to the user

<switch xmlns:ns="http://org.apache.synapse/xsd" source="$axis2:HTTP_SC">
  <case regex="401">
     <send/>
  </case>

in this case, everything worked. Here are just a user gets a HTML server response as is.

BUT! when you try to replace the body of the response like this

<case regex="401">
     <payloadFactory media-type="xml">
        <format>
           <error xmlns="">   
              <message>some message</message>
           </error>
        </format>
     </payloadFactory>
     <send/>

I get an error

[2013-09-11 15:20:06,669] ERROR - AnonymousListMediator Error while building messageorg.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxParsingException: Unexpected lose tag </head>; expected </link>. at [row,col {unknown-source}]: [13,6] at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)

is any attempt to replace the answer (even through fault mediator) lead to this error. Any ideas?

Was it helpful?

Solution

Forgive me for asking that question literally just managed to solve it! In the search for solutions has been spent a lot of time and then I just leave the resolution of this issue here. The problem was that the default settings for

contentType="text/html"

in the system settings not specified Message Builder for this content type. In order that all would work to find a file {WSO2 ESB HOME}/repository/conf/axis2/axis2.xml

Find it section ( Message Builders ) So, in this section there is no handler for that content type. (if I was a developer WSO I would ask what that default handler but alas, in this situation, it is not suitable) And so, in this section you need to add a handler for our type of content

<messageBuilder contentType="text/html"
                    class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

so it will process the message as binary. But at the same time, it will not cause system crash.After this manipulation, you can safely use PayloadFactory as indicated above. It works for me! Maybe someone else would be useful. Thank you for your attention. Personal thanks Chanaka udaya for trying.

OTHER TIPS

You can see whether the payloadFactory mediator has created the body of the message or not by adding a mediator after the mediator like below.

<case regex="401">
     <payloadFactory media-type="xml">
        <format>
           <error xmlns="">   
              <message>some message</message>
           </error>
        </format>
     </payloadFactory>
**<log level="full"/>**
     <send/>

You can verify the message is build or not with this log mediator. If you can share the entire synapse config, we can give a proper solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top