FileDocCategorySizeDatePackage
UnWrappedMessage.javaAPI DocGlassfish v2 API40266Fri May 04 22:30:28 BST 2007com.sun.enterprise.jbi.serviceengine.comm

UnWrappedMessage

public final class UnWrappedMessage extends com.sun.xml.ws.api.message.Message implements com.sun.enterprise.jbi.serviceengine.util.JBIConstants, com.sun.enterprise.jbi.serviceengine.util.soap.SOAPConstants
This class is used to unwrap the incoming JBI request message when the Java EE Service Engine is the Provider. This class unwraps and extracts the 'payload' from the incomoming request message which is in normalized form. The current implentation supports the following WSDL1.1 SOAP binding styles : 1. Wrapped Document/literal 2. RPC/Literal The characterstics of the Wrapped Document/literal style are 1. The input message has a single part. 2. The part is an element. 3. The element has the same name as the operation. 4. The element's complex type has no attributes. For wrapped document/literal, the incoming request message looks like : 1.0 2.0 and the payLoad node for this is : 1.0 2.0 For RPC/literal, the incoming request message looks like this : 1 2 and the payLoad node for this is: 1 2 The styles which are not supported by JAX-WS 2.0 are: RPC/encoded Document/encoded The style(s) which are treated/converted as wrapped document/literal by JAX-WS tools are document/literal
author
bhavanishankar@dev.java.net

Fields Summary
private static Logger
logger
private String
payloadLocalName
private String
payloadNamespaceURI
private Source
payLoadAsSource
private XMLStreamReader
payLoadAsStreamReader
private ByteArrayOutputStream
payLoadAsBaos
private com.sun.xml.ws.api.message.HeaderList
headers
private boolean
isFault
private boolean
log
Source
nmContent
Variables used for unwrapping the message.
javax.jbi.messaging.NormalizedMessage
normalizedMessage
QName
wsdlMessageType
String
wsdlBindingStyle
List
wsdlOrderedParts
int[]
wsdlPartBindings
Constructors Summary
public UnWrappedMessage()

        setLog();
    
Methods Summary
private voidaddHeader(org.w3c.dom.Node n)
Adds the header node to the header list.

        if(log) {
            logger.log(Level.FINE, "Header = " + toString(n));
        }
        DOMHeader header = new DOMHeader((Element)n);
        headers.add(header);
    
private voidaddHeader(javax.xml.stream.XMLStreamReader r)
Adds the header node pointed by XMLStreamReader to the header list.

        try {
            if(log) {
                logger.log(Level.FINE, "Header = " + r.getName());
            }
            StreamHeader11 header = new StreamHeader11(r);
            headers.add(header);
        } catch(Exception ex) {
            logger.log(Level.SEVERE, ex.getMessage(), ex);
        }
    
public com.sun.xml.ws.api.message.Messagecopy()

        return null;
    
public voidcopyPayLoad(javax.xml.stream.XMLStreamReader r)

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter writer = XOF.createXMLStreamWriter(baos);
        DOMUtil.UTIL.writeNode(r, writer);
        writer.flush();
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        XMLStreamReader reader = XIF.createXMLStreamReader(bais);
        if(log) {
            logger.log(Level.FINE, "Payload = " + baos.toString());
        }
        setPayLoad(reader);
    
private booleanfindJBINode(javax.xml.stream.XMLStreamReader reader, java.lang.String localName)

        while(reader.hasNext()) {
            if(isJBINode(reader,localName)) {
                return true;
            }
            reader.next();
        }
        return false;
    
public com.sun.xml.ws.api.message.HeaderListgetHeaders()

        if(log) {
            logger.log(Level.FINE, "Headers = " + headers);
        }
        return headers;
    
public org.w3c.dom.NodegetOwnerDocument(org.w3c.dom.Node n)

        Node ownerDocument = n.getOwnerDocument();
        return ownerDocument != null
                ? ownerDocument
                : n;
    
public java.lang.StringgetPayloadLocalPart()

        return payloadLocalName;
    
public java.lang.StringgetPayloadNamespaceURI()

        return payloadNamespaceURI;
    
public javax.xml.transform.stream.StreamSourcegetStreamSource(javax.xml.transform.Source src)

        try {
            if(src instanceof StreamSource) {
                return (StreamSource)src;
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            StreamResult result = new StreamResult(baos);
            TF.newTransformer().transform(src, result);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            StreamSource ss = new StreamSource(bais);
            return ss;
        } catch(Exception ex) {
            ex.printStackTrace();
            return null;
        }
        
    
public booleanhasHeaders()

        return (headers.size() != 0);
    
public booleanhasPayload()

        return payLoadAsStreamReader == null;
    
public booleanisFault()

        return isFault;
    
private booleanisJBINode(org.w3c.dom.Node node, java.lang.String localName)

        if(WRAPPER_DEFAULT_NAMESPACE.equalsIgnoreCase(node.getNamespaceURI()) &&
                localName.equalsIgnoreCase(node.getLocalName())) {
            return true;
        }
        return false;
    
private booleanisJBINode(javax.xml.stream.XMLStreamReader reader, java.lang.String localName)

        if(reader.getEventType() != XMLStreamReader.START_ELEMENT) {
            return false;
        }
        if(WRAPPER_DEFAULT_NAMESPACE.equalsIgnoreCase(reader.getNamespaceURI()) &&
                localName.equalsIgnoreCase(reader.getLocalName())) {
            return true;
        }
        return false;
    
public voidprintPayLoad(java.lang.String message)

        if(!log) {
            return;
        }
        StringBuffer msg = new StringBuffer("\n\n");
        if(payLoadAsSource instanceof DOMSource) {
            Node n = ((DOMSource)payLoadAsSource).getNode();
            msg.append("Unwrapped message " + UnWrappedMessage.toString(n));
        }
        msg
                .append(message)
                .append("\n\npayLoadLocalName = ")
                .append(payloadLocalName)
                .append("\npayLoadNamespaceURI = ")
                .append(payloadNamespaceURI)
                .append("\n\n");
        
        logger.log(Level.FINE, msg.toString());
    
private voidprocessAttachments()

        for(String aName : (Set<String>)normalizedMessage.getAttachmentNames()) {
            logger.log(Level.FINE, "Adding attachment with ID = " + aName);
            getAttachments().add(new DataHandlerAttachment(
                    aName, normalizedMessage.getAttachment(aName)));
        }
    
public javax.xml.soap.SOAPMessagereadAsSOAPMessage()

        String methodSig =
                "\ncom.sun.enterprise.jbi.serviceengine.comm.UnWrappedMessage" +
                "::readAsSOAPMessage()";
        String usedWith = System.getProperty(USED_WITH);
        if(usedWith == null || usedWith.indexOf(USED_WITH_JMAC_PROVIDER) == -1) {
            throw new SOAPException(
                    methodSig + " operation is not supported." +
                    "\nSet this system property to workaround this issue : " +
                    "com.sun.enterprise.jbi.se.usedwith=jmacprovider");
        }
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter writer = XOF.createXMLStreamWriter(baos);
            writer.writeStartDocument();
            writer.writeStartElement(SOAP_ENVELOPE);
            writer.writeAttribute("xmlns:" + SOAP_PREFIX, SOAP_NAMESPACE);
            writer.writeEmptyElement(SOAP_HEADER);
            writer.writeStartElement(SOAP_BODY);
            if(payLoadAsBaos == null) {
                if(payLoadAsSource instanceof DOMSource) {
                    Node payLoadNode = ((DOMSource)payLoadAsSource).getNode();
                    DOMUtil.UTIL.writeNode(payLoadNode, writer);
                } else {
                    DOMUtil.UTIL.writeNode(payLoadAsStreamReader, writer);
                }
            } else {
                baos.write(">".getBytes());
                baos.write(payLoadAsBaos.toByteArray());
            }
            writer.writeEndElement();
            writer.writeEndElement();
            writer.writeEndDocument();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            
            SOAPMessage message = MessageFactory.newInstance().createMessage(null, bais);
            if(log) {
                logger.log(Level.FINE, methodSig + " :: SOAPMessage = " + toString(message));
            }
            return message;
        } catch(Exception ex) {
            throw new SOAPException(methodSig + ex.getMessage());
        }
    
public javax.xml.transform.SourcereadEnvelopeAsSource()

        return null;
    
public javax.xml.stream.XMLStreamReaderreadPayload()

        if(log) {
            logger.log(Level.FINE, "UnWrappedMessage :: readPayLoad()");
        }
        return payLoadAsStreamReader;
    
public TreadPayloadAsJAXB(javax.xml.bind.Unmarshaller unmarshaller)

        return (T)unmarshaller.unmarshal(payLoadAsSource);
    
public TreadPayloadAsJAXB(com.sun.xml.bind.api.Bridge bridge)

        return bridge.unmarshal(payLoadAsSource);
    
public javax.xml.transform.SourcereadPayloadAsSource()

        if(log) {
            logger.log(Level.FINE, "UnWrappedMessage :: readPayLoadAsSource()");
        }
        return payLoadAsSource;
    
private voidsetLog()

    
       
        if(logger.isLoggable(Level.FINE)) {
            log = true;
        }
    
public voidsetNormalizedMessage(javax.jbi.messaging.NormalizedMessage normalizedMessage)

        this.normalizedMessage = normalizedMessage;
        this.nmContent = normalizedMessage.getContent();
    
public voidsetPayLoad(javax.xml.transform.Source s)

        if(s instanceof DOMSource) {
            setPayLoad(((DOMSource)s).getNode());
        } else if(s instanceof StreamSource) {
            XMLStreamReader reader = XIF.
                    createXMLStreamReader(((StreamSource)s).getInputStream());
            setPayLoad(reader);
        }  else if(s instanceof SAXSource) {
            InputSource source = ((SAXSource) s).getInputSource();
            XMLStreamReader reader = (source.getCharacterStream() != null)?
                    XIF.createXMLStreamReader(source.getCharacterStream()):
                    XIF.createXMLStreamReader(source.getByteStream());
            setPayLoad(reader);
        } else {
            logger.log(Level.WARNING, "UnWrappedMessage :: Transforming the input message to DOM");
            Transformer t = TF.newTransformer();
            DOMResult result = new DOMResult();
            t.transform(s, result);
            setPayLoad(result.getNode());
        }
    
public voidsetPayLoad(org.w3c.dom.Node n)

        if(n.getNodeType() == Node.DOCUMENT_NODE) {
            n = n.getFirstChild();
        }
        payloadLocalName = n.getLocalName();
        payloadNamespaceURI = n.getNamespaceURI();
        payLoadAsSource = new DOMSource(n);
        payLoadAsStreamReader = new DOMStreamReader(n);
        printPayLoad("");
    
public voidsetPayLoad(javax.xml.stream.XMLStreamReader reader)

        if(reader.getEventType() == XMLStreamReader.START_DOCUMENT) {
            reader.next();
        }
        payloadLocalName =  reader.getLocalName();
        payloadNamespaceURI = reader.getNamespaceURI();
        payLoadAsSource = new StAXSource(reader, true); // StAXSource will be available in JDK6.
        payLoadAsStreamReader = reader;
        XMLStreamReader r = reader;
        printPayLoad("");
    
public voidsetPayLoad(byte[] data)

        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        payLoadAsStreamReader = XIF.createXMLStreamReader(bais);
        payLoadAsStreamReader.next(); // skip the <?xml ...?> node.
        payLoadAsSource = new StAXSource(payLoadAsStreamReader, true);
        payloadLocalName = payLoadAsStreamReader.getLocalName();
        payloadNamespaceURI = payLoadAsStreamReader.getNamespaceURI();
    
public voidsetWSDLBindingStyle(java.lang.String wsdlBindingStyle)

        this.wsdlBindingStyle = wsdlBindingStyle;
    
public voidsetWSDLMessageType(javax.xml.namespace.QName wsdlMessageType)

        this.wsdlMessageType = wsdlMessageType;
    
public voidsetWSDLOrderedParts(java.util.List wsdlOrderedParts)

        this.wsdlOrderedParts = wsdlOrderedParts;
    
public voidsetWSDLPartBindings(int[] wsdlPartBindings)

        this.wsdlPartBindings = wsdlPartBindings;
    
public static java.lang.StringtoString(javax.xml.soap.SOAPMessage soapMessage)

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            soapMessage.writeTo(baos);
            return baos.toString();
        } catch(Exception e) {
            return e.getMessage();
        }
    
public static java.lang.StringtoString(org.w3c.dom.Node n)

        return toString(new DOMSource(n));
    
public static java.lang.StringtoString(javax.xml.stream.XMLStreamReader reader)

        return toString(new StAXSource(reader, true));
    
public static java.lang.StringtoString(javax.xml.transform.Source s)

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            StreamResult sr = new StreamResult(baos);
            TF.newTransformer().transform(s, sr);
            return baos.toString();
        } catch(Exception ex) {
            ex.printStackTrace();
            return null;
        }
    
private voidunWrapFault()

        Source s = this.nmContent;
        Node n;
        if(s instanceof DOMSource) {
            n = ((DOMSource)s).getNode();
        } else {
            Transformer t = TF.newTransformer();
            DOMResult result = new DOMResult();
            t.transform(s, result);
            n = result.getNode();
        }
        
        Document d = (n instanceof Document) ? (Document) n : n.getOwnerDocument();
        
        NodeList nl = d.getElementsByTagNameNS(WRAPPER_DEFAULT_NAMESPACE, WRAPPER_PART_LOCALNAME);
        Node jbiPart = (nl != null && nl.getLength() > 0)
        ? nl.item(0).getFirstChild()
        : d.getFirstChild();
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter writer = XOF.createXMLStreamWriter(baos);
        
        writer.writeStartDocument();
        writer.writeStartElement(SOAP_FAULT);
        writer.writeAttribute("xmlns:" + SOAP_PREFIX, SOAP_NAMESPACE);
        
        String faultCode = jbiPart == null ? SERVER_FAULT_CODE : CLIENT_FAULT_CODE;
        String faultString = FAULT_STRING;
        
        writer.writeStartElement(FAULT_CODE_ELEMENT);
        writer.writeCharacters(SOAP_PREFIX + ":" + faultCode);
        writer.writeEndElement();
        
        writer.writeStartElement(FAULT_STRING_ELEMENT);
        writer.writeCharacters(faultString);
        writer.writeEndElement();
        
        writer.writeStartElement(FAULT_DETAIL_ELEMENT);
        if(jbiPart != null)
            DOMUtil.UTIL.writeNode(jbiPart, writer);
        
        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        
        setPayLoad(baos.toByteArray());
        
        printPayLoad("\n\nUnwrapped fault = " + baos.toString());
    
public voidunwrap()

        
        if(log) {
            String s = (nmContent instanceof DOMSource) ? toString(nmContent) : "StreamSource";
            logger.log(Level.FINE, "bindingStyle = " + wsdlBindingStyle + ", received message = " + s);
        }
        
        if(JavaEEServiceEngineContext.getInstance().isServiceMix()) {
            if(log) {
                logger.log(Level.FINE, "Skipping the unwrapping...");
            }
            setPayLoad(nmContent);
        } else {
            if(RPC_STYLE.equalsIgnoreCase(wsdlBindingStyle)) {
                new RPCStyleUnWrapper().unwrap();
            } else {
                new DocumentStyleUnWrapper().unwrap();
            }
        }
        
        processAttachments();
        
        if(payLoadAsStreamReader == null) {
            throw new Exception(StringTranslator.getDefaultInstance().getString(
                    "serviceengine.unwrapping_failed"));
        }
        
    
public voidunwrapFault()

        
        if(log) {
            String s = (nmContent instanceof DOMSource) ? toString(nmContent) : "StreamSource";
            logger.log(Level.FINE, "bindingStyle = " + wsdlBindingStyle + ", received fault = " + s);
        }
        
        isFault = true;
        if(JavaEEServiceEngineContext.getInstance().isServiceMix()) {
            if(log) {
                logger.log(Level.FINE, "Skipping the unwrapping...");
            }
            setPayLoad(nmContent);
        } else {
            unWrapFault();
        }
        
        if(payLoadAsStreamReader == null) {
            throw new Exception(StringTranslator.getDefaultInstance().getString(
                    "serviceengine.unwrapping_failed"));
        }
    
public voidwritePayloadTo(javax.xml.stream.XMLStreamWriter sw)

        throw new XMLStreamException("Operaion is not supported.");
    
public voidwriteTo(javax.xml.stream.XMLStreamWriter sw)

        throw new XMLStreamException("Operaion is not supported.");
    
public voidwriteTo(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler)

        throw new SAXException("Operaion is not supported.");