Example usage for javax.xml.soap SOAPConstants URI_NS_SOAP_1_1_ENVELOPE

List of usage examples for javax.xml.soap SOAPConstants URI_NS_SOAP_1_1_ENVELOPE

Introduction

In this page you can find the example usage for javax.xml.soap SOAPConstants URI_NS_SOAP_1_1_ENVELOPE.

Prototype

String URI_NS_SOAP_1_1_ENVELOPE

To view the source code for javax.xml.soap SOAPConstants URI_NS_SOAP_1_1_ENVELOPE.

Click Source Link

Document

The namespace identifier for the SOAP 1.1 envelope.

Usage

From source file:com.googlecode.ddom.saaj.SOAPPartTest.java

@Validated
@Test/*from  w w  w .  j  a  va2 s.c  o  m*/
public void testCreateEnvelopeWithCreateElementNS() throws Exception {
    SOAPPart soapPart = factory.createMessage().getSOAPPart();
    Element element = soapPart.createElementNS(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "SOAP-ENV:Envelope");
    assertTrue(element instanceof SOAPEnvelope);
    soapPart.appendChild(element);
    SOAPEnvelope envelope = soapPart.getEnvelope();
    assertNotNull(envelope);
}

From source file:org.apache.axis2.datasource.jaxb.JAXBCustomBuilder.java

/**
 * @param namespace/*from w w w  .  ja va  2s . co  m*/
 * @param localPart
 * @return true if this ns and local part is acceptable for unmarshalling
 */
private boolean shouldUnmarshal(String namespace, String localPart) {
    boolean isHighFidelity = HandlerUtils.isHighFidelity(jdsContext.getMessageContext());

    if (isHighFidelity) {
        if (log.isDebugEnabled()) {
            log.debug("JAXB payload streaming disabled because high fidelity messages are requested.");
        }
        return false;

    }

    // Don't unmarshall SOAPFaults or anything else in the SOAP 
    // namespace.
    // Don't unmarshall elements that are unqualified
    if (localPart == null || namespace == null || namespace.length() == 0
            || SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespace)
            || SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespace)) {
        return false;
    }

    // Don't unmarshal if this looks like encrypted data
    if (localPart.equals("EncryptedData")) {
        return false;
    }

    return true;

}

From source file:org.apache.axis2.jaxws.context.listener.ParserInputStreamCustomBuilder.java

/**
 * @param namespace//from  w  w  w .  j  a v  a2  s .  co  m
 * @param localPart
 * @return true if this ns and local part is acceptable for unmarshalling
 */
private boolean shouldUnmarshal(String namespace, String localPart) {

    /**
     * The stream preserves the original message, so I think
     * we want to do unmarshal even if high fidelity is specified.
             
    boolean isHighFidelity = HandlerUtils.isHighFidelity(msgContext);
            
    if (isHighFidelity) {
    return false;
    }
    */

    // Don't unmarshal SOAPFaults.
    // If there is no localPart, this also indicates a potential problem...so don't 
    // use the custom builder
    if (localPart == null
            || (localPart.equals("Fault") && (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespace)
                    || SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespace)))) {
        return false;
    }

    /**
     * For JAXB custom building, we ignore security elements.
     * I don't think it matters for parsed entities since they preserve all the content
    if (localPart.equals("EncryptedData")) {
    return false;
    }
    */

    return true;

}

From source file:org.apache.axis2.jaxws.handler.HandlerChainProcessor.java

/**
 * Converts the Exception into an XML Fault Message that is stored on the MEPContext.
 * Note that if the forceConversion flag is true, this conversion will always occur.
 * If the checkMsg flag is true, this conversion only occurs if the Message is not already
 * a Fault (per 9,3,2.1 of the JAX-WS specification)
 * // ww w .j  a v a 2s  . c  o m
 * @param mepCtx  MEPContext
 * @param e Exception
 * @param protocol Protocol
 * @param forceConversion  If true, the Exception is always converted to a Message
 */
public static void convertToFaultMessage(MEPContext mepCtx, Exception e, Protocol protocol, boolean checkMsg) {

    // need to check if message is already a fault message or not,
    // probably by way of a flag (isFault) in the MessageContext or Message
    if (log.isDebugEnabled()) {
        log.debug("start convertToFaultMessge with exception: " + e.getClass().getName());
        log.debug(" checkMsg is : " + checkMsg);
    }

    try {
        // According to the 9.3.2.1, The message is converted into a fault only if it is not already a Fault
        Message messageFromHandler = null;
        if (checkMsg) {
            messageFromHandler = mepCtx.getMessageContext().getMessage();
        }
        if (messageFromHandler != null && messageFromHandler.isFault()) {
            if (log.isDebugEnabled()) {
                log.debug("The Message is already a SOAPFault.  The exception is not converted into a Message");
            }
        } else if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
            if (log.isDebugEnabled()) {
                log.debug("Converting Exception into a Message");
            }
            String protocolNS = (protocol == Protocol.soap11) ? SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE
                    : SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;

            // The following set of instructions is used to avoid 
            // some unimplemented methods in the Axis2 SAAJ implementation
            XMLFault xmlFault = MethodMarshallerUtils.createXMLFaultFromSystemException(e);
            javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
            SOAPMessage message = mf.createMessage();
            SOAPBody body = message.getSOAPBody();
            SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);

            MessageFactory msgFactory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
            Message msg = msgFactory.createFrom(message);
            mepCtx.setMessage(msg);

        } else {
            WebServiceException wse = ExceptionFactory
                    .makeWebServiceException(Messages.getMessage("cFaultMsgErr"));
            if (log.isDebugEnabled()) {
                log.debug("end convertToFaultMessge due to error ", wse);
            }
            throw wse;
        }

    } catch (Exception ex) {
        WebServiceException wse = ExceptionFactory.makeWebServiceException(ex);
        if (log.isDebugEnabled()) {
            log.debug("end convertToFaultMessge due to error ", wse);
        }
        throw wse;
    }

}

From source file:org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.java

/**
 * Create a system exception//from w  w w.  j a v  a  2 s . c om
 *
 * @param message
 * @return
 */
public static ProtocolException createSystemException(XMLFault xmlFault, Message message) {
    ProtocolException e = null;
    Protocol protocol = message.getProtocol();
    String text = xmlFault.getReason().getText();

    if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
        // Throw a SOAPFaultException
        if (log.isDebugEnabled()) {
            log.debug("Constructing SOAPFaultException for " + text);
        }
        String protocolNS = (protocol == Protocol.soap11) ? SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE
                : SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
        try {
            // The following set of instructions is used to avoid 
            // some unimplemented methods in the Axis2 SAAJ implementation
            javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
            SOAPBody body = mf.createMessage().getSOAPBody();
            SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
            e = new SOAPFaultException(soapFault);
        } catch (Exception ex) {
            // Exception occurred during exception processing.
            // TODO Probably should do something better here
            if (log.isDebugEnabled()) {
                log.debug("Exception occurred during fault processing:", ex);
            }
            e = ExceptionFactory.makeProtocolException(text, null);
        }
    } else if (protocol == Protocol.rest) {
        if (log.isDebugEnabled()) {
            log.debug("Constructing ProtocolException for " + text);
        }
        // TODO Is there an explicit exception for REST
        e = ExceptionFactory.makeProtocolException(text, null);
    } else if (protocol == Protocol.unknown) {
        // REVIEW What should happen if there is no protocol
        if (log.isDebugEnabled()) {
            log.debug("Constructing ProtocolException for " + text);
        }
        e = ExceptionFactory.makeProtocolException(text, null);
    }
    return e;
}

From source file:org.apache.axis2.jaxws.message.impl.MessageImpl.java

public SOAPMessage getAsSOAPMessage() throws WebServiceException {

    // TODO: /*from w w w. j  a v  a2  s  .c o m*/
    // This is a non performant way to create SOAPMessage. I will serialize
    // the xmlpart content and then create an InputStream of byte.
    // Finally create SOAPMessage using this InputStream.
    // The real solution may involve using non-spec, implementation
    // constructors to create a Message from an Envelope
    try {
        if (log.isDebugEnabled()) {
            log.debug("start getAsSOAPMessage");
        }
        // Get OMElement from XMLPart.
        OMElement element = xmlPart.getAsOMElement();

        // Get the namespace so that we can determine SOAP11 or SOAP12
        OMNamespace ns = element.getNamespace();

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        element.serialize(outStream);

        // In some cases (usually inbound) the builder will not be closed after
        // serialization.  In that case it should be closed manually.
        if (element.getBuilder() != null && !element.getBuilder().isCompleted()) {
            element.close(false);
        }

        byte[] bytes = outStream.toByteArray();

        if (log.isDebugEnabled()) {
            String text = new String(bytes);
            log.debug("  inputstream = " + text);
        }

        // Create InputStream
        ByteArrayInputStream inStream = new ByteArrayInputStream(bytes);

        // Create MessageFactory that supports the version of SOAP in the om element
        MessageFactory mf = getSAAJConverter().createMessageFactory(ns.getNamespaceURI());

        // Create soapMessage object from Message Factory using the input
        // stream created from OM.

        // Get the MimeHeaders from the transportHeaders map
        MimeHeaders defaultHeaders = new MimeHeaders();
        if (transportHeaders != null) {
            Iterator it = transportHeaders.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                String key = (String) entry.getKey();
                if (entry.getValue() == null) {
                    // This is not necessarily a problem; log it and make sure not to NPE
                    if (log.isDebugEnabled()) {
                        log.debug(
                                "  Not added to transport header. header =" + key + " because value is null;");
                    }
                } else if (entry.getValue() instanceof String) {
                    // Normally there is one value per key
                    if (log.isDebugEnabled()) {
                        log.debug("  add transport header. header =" + key + " value = " + entry.getValue());
                    }
                    defaultHeaders.addHeader(key, (String) entry.getValue());
                } else {
                    // There may be multiple values for each key.  This code
                    // assumes the value is an array of String.
                    String values[] = (String[]) entry.getValue();
                    for (int i = 0; i < values.length; i++) {
                        if (log.isDebugEnabled()) {
                            log.debug("  add transport header. header =" + key + " value = " + values[i]);
                        }
                        defaultHeaders.addHeader(key, values[i]);
                    }
                }
            }
        }

        // Toggle based on SOAP 1.1 or SOAP 1.2
        String contentType = null;
        if (ns.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
            contentType = SOAPConstants.SOAP_1_1_CONTENT_TYPE;
        } else {
            contentType = SOAPConstants.SOAP_1_2_CONTENT_TYPE;
        }

        // Override the content-type
        String ctValue = contentType + "; charset=UTF-8";
        defaultHeaders.setHeader("Content-type", ctValue);
        if (log.isDebugEnabled()) {
            log.debug("  setContentType =" + ctValue);
        }
        SOAPMessage soapMessage = mf.createMessage(defaultHeaders, inStream);

        // At this point the XMLPart is still an OMElement.  
        // We need to change it to the new SOAPEnvelope.
        createXMLPart(soapMessage.getSOAPPart().getEnvelope());

        // If axiom read the message from the input stream, 
        // then one of the attachments is a SOAPPart.  Ignore this attachment
        String soapPartContentID = getSOAPPartContentID(); // This may be null

        if (log.isDebugEnabled()) {
            log.debug("  soapPartContentID =" + soapPartContentID);
        }

        List<String> dontCopy = new ArrayList<String>();
        if (soapPartContentID != null) {
            dontCopy.add(soapPartContentID);
        }

        // Add any new attachments from the SOAPMessage to this Message
        Iterator it = soapMessage.getAttachments();
        while (it.hasNext()) {

            AttachmentPart ap = (AttachmentPart) it.next();
            String cid = ap.getContentId();
            if (log.isDebugEnabled()) {
                log.debug("  add SOAPMessage attachment to Message.  cid = " + cid);
            }
            addDataHandler(ap.getDataHandler(), cid);
            dontCopy.add(cid);
        }

        // Add the attachments from this Message to the SOAPMessage
        for (String cid : getAttachmentIDs()) {
            DataHandler dh = attachments.getDataHandler(cid);
            if (!dontCopy.contains(cid)) {
                if (log.isDebugEnabled()) {
                    log.debug("  add Message attachment to SoapMessage.  cid = " + cid);
                }
                AttachmentPart ap = MessageUtils.createAttachmentPart(cid, dh, soapMessage);
                soapMessage.addAttachmentPart(ap);
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("  The SOAPMessage has the following attachments");
            Iterator it2 = soapMessage.getAttachments();
            while (it2.hasNext()) {
                AttachmentPart ap = (AttachmentPart) it2.next();
                log.debug("    AttachmentPart cid=" + ap.getContentId());
                log.debug("        contentType =" + ap.getContentType());
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("end getAsSOAPMessage");
        }
        return soapMessage;
    } catch (Exception e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }

}

From source file:org.apache.axis2.jaxws.message.impl.MessageImpl.java

public Object getValue(Object context, BlockFactory blockFactory) throws WebServiceException {
    try {/*w w  w  .  ja  v a  2  s  .  com*/
        Object value = null;
        if (protocol == Protocol.rest) {
            // The implementation of rest stores the rest xml inside a dummy soap 1.1 envelope.
            // So use the get body block logic.
            Block block = xmlPart.getBodyBlock(context, blockFactory);
            if (block != null) {
                value = block.getBusinessObject(true);
            }

        } else {
            // Must be SOAP
            if (blockFactory instanceof SOAPEnvelopeBlockFactory) {
                value = getAsSOAPMessage();
            } else {
                // TODO: This doesn't seem right to me.
                // We should not have an intermediate StringBlock.
                // This is not performant. Scheu
                OMElement messageOM = getAsOMElement();
                String stringValue = messageOM.toString();
                String soapNS = (protocol == Protocol.soap11) ? SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE
                        : SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
                QName soapEnvQname = new QName(soapNS, "Envelope");

                XMLStringBlockFactory stringFactory = (XMLStringBlockFactory) FactoryRegistry
                        .getFactory(XMLStringBlockFactory.class);
                Block stringBlock = stringFactory.createFrom(stringValue, null, soapEnvQname);
                Block block = blockFactory.createFrom(stringBlock, context);
                value = block.getBusinessObject(true);
            }
        }
        return value;
    } catch (Throwable e) {
        throw ExceptionFactory.makeWebServiceException(e);
    }
}