Linked Questions

Popular Questions

XMLStreamReader parser affects MuleEventContext

Asked by At

I'm using Mule Studio (Mule 3.2.1CE) to configure a proxy service which simply calls a remote web service. Everything works fine with calling and getting the proper response (using soapUI). I want to log SOAP message received within the ESB. I'm getting a DepthXMLStreamReader message as expected by the CXF component but I'm facing an odd behavior when I use XMLStreamReader object's next() method. Here is the code I use:

public Object onCall(MuleEventContext context) throws Exception {
    MuleMessage message = context.getMessage();
    DepthXMLStreamReader streamReader = new DepthXMLStreamReader((XMLStreamReader) message.getPayload());

    while(streamReader.hasNext()){
                streamReader.next();
                if(streamReader.getEventType() == XMLStreamReader.START_ELEMENT)
                {
                    System.out.println(streamReader.getLocalName());
                }
            }
    return context.getMessageAsString();

The above code works and prints XML elements but I get the following error afterwards:

 org.apache.cxf.interceptor.Fault: Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=..., connector=HttpConnector
...
    Caused by: org.mule.transport.http.HttpResponseException: Internal Server Error, code: 500

I tried using StaxUtils.nextEvent and StaxUtils.toNextElement, but no difference in result. I wonder why parsing XML by next() method affects mule context. If I use System.out.println(context.getMessageAsString()); before the return statement it prints "[Messaage could not be converted to string]" but it works before while statement in the above code.

Here is my mule config:

<flow name="wsFlow1" doc:name="wsFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8090" contentType="text/xml" doc:name="HTTP"/>
    <cxf:proxy-service bindingId="..." namespace="http://..." service="..." payload="body" wsdlLocation="..." enableMuleSoapHeaders="false" doc:name="SOAP"/>
    <component class="mule.ws.SoapLogging" doc:name="Java"/>
    <http:outbound-endpoint exchange-pattern="request-response" address="http://..." contentType="text/xml" doc:name="HTTP"/>
</flow>

Thanks

Related Questions