Search in sources :

Example 26 with SoapVersion

use of org.apache.cxf.binding.soap.SoapVersion in project steve by RWTH-i5-IDSG.

the class MediatorInInterceptor method handleMessage.

public final void handleMessage(SoapMessage message) {
    String schemaNamespace = "";
    InterceptorChain chain = message.getInterceptorChain();
    // Scan the incoming message for its schema namespace
    try {
        // Create a buffered stream so that we get back the original stream after scanning
        InputStream is = message.getContent(InputStream.class);
        BufferedInputStream bis = new BufferedInputStream(is);
        bis.mark(bis.available());
        message.setContent(InputStream.class, bis);
        String encoding = (String) message.get(Message.ENCODING);
        XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(bis, encoding);
        DepthXMLStreamReader xmlReader = new DepthXMLStreamReader(reader);
        if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
            String ns = xmlReader.getNamespaceURI();
            SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
            // Advance just past header
            StaxUtils.toNextTag(xmlReader, soapVersion.getBody());
            // Past body
            xmlReader.nextTag();
        }
        schemaNamespace = xmlReader.getName().getNamespaceURI();
        bis.reset();
    } catch (IOException | XMLStreamException ex) {
        log.error("Exception happened", ex);
    }
    // We redirect the message to the actual OCPP service
    Server targetServer = actualServers.get(schemaNamespace);
    // Redirect the request
    if (targetServer != null) {
        MessageObserver mo = targetServer.getDestination().getMessageObserver();
        mo.onMessage(message);
    }
    // Now the response has been put in the message, abort the chain
    chain.abort();
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) MessageObserver(org.apache.cxf.transport.MessageObserver) XMLStreamException(javax.xml.stream.XMLStreamException) Server(org.apache.cxf.endpoint.Server) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) IOException(java.io.IOException)

Aggregations

SoapVersion (org.apache.cxf.binding.soap.SoapVersion)26 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)15 QName (javax.xml.namespace.QName)12 Element (org.w3c.dom.Element)11 SoapFault (org.apache.cxf.binding.soap.SoapFault)10 Header (org.apache.cxf.headers.Header)7 Fault (org.apache.cxf.interceptor.Fault)7 SOAPMessage (javax.xml.soap.SOAPMessage)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)5 Message (org.apache.cxf.common.i18n.Message)5 Exchange (org.apache.cxf.message.Exchange)5 Node (org.w3c.dom.Node)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)4 SOAPElement (javax.xml.soap.SOAPElement)4 SOAPException (javax.xml.soap.SOAPException)4