Search in sources :

Example 16 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.

the class CoordinationContextHandler method handleMessageOutbound.

/**
 * check for an arjuna context attached to the message context and, if found, install its identifier as the value
 * of a soap message header element
 * @param context
 * @return
 * @throws ProtocolException
 */
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
    try {
        CoordinationContextType coordinationContext = CoordinationContextManager.getThreadContext();
        if (coordinationContext != null) {
            final JAXBContext jaxbCtx = getJaxbContext();
            // insert a header into the current message containing the coordination context
            final SOAPMessage soapMessage = context.getMessage();
            final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnvelope.getHeader();
            if (soapHeader == null) {
                soapHeader = soapEnvelope.addHeader();
            }
            /*
                 * this does not work but it is what we want!!
                 *
                 * The problem here is that the marshaller creates plain old elements and inserts them top
                 * down as it goes along. but the soap header add child method checks its argument and
                 * replaces plain elements with soap header elements before inserting them. it copies the
                 * inserted element substructure into the rpelacement but since it does not exist at
                 * copy time the chiuldren get lost
                Marshaller marshaller = jaxbCtx.createMarshaller();
                marshaller.marshal(coordinationContext, soapHeader);
                 */
            /*
                 * ok, here's the workaround -- marshall the object as a child of a dummy header, detach it and
                 * then insert it as a header element.
                 */
            SOAPHeaderElement headerElement = soapHeader.addHeaderElement(getDummyQName());
            Marshaller marshaller = jaxbCtx.createMarshaller();
            marshaller.marshal(coordinationContext, headerElement);
            soapHeader.replaceChild(headerElement.getChildNodes().item(0), headerElement);
            // ok, now we need to locate the inserted node and set the mustunderstand attribute
            Iterator<SOAPHeaderElement> iterator = soapHeader.examineAllHeaderElements();
            while (iterator.hasNext()) {
                headerElement = iterator.next();
                if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
                    headerElement.setMustUnderstand(true);
                    break;
                }
            }
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException)

Example 17 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.

the class InstanceIdentifierHandler method handlemessageInbound.

/**
 * check for an arjuna instance identifier element embedded in the soap message headesr and, if found, use it to
 * label an arjuna context attached to the message context
 * @param context
 * @return
 * @throws ProtocolException
 */
private boolean handlemessageInbound(SOAPMessageContext context) throws ProtocolException {
    try {
        final SOAPMessage soapMessage = context.getMessage();
        final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
        Iterator<SOAPHeaderElement> iterator = soapEnvelope.getHeader().examineAllHeaderElements();
        while (iterator.hasNext()) {
            final SOAPHeaderElement headerElement = iterator.next();
            if (ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME.equals(headerElement.getElementQName())) {
                // found it - clear the must understand flag, retrieve the value and store an arjuna
                // context in the message context
                headerElement.setMustUnderstand(false);
                String identifierString = headerElement.getValue();
                if (identifierString != null) {
                    ArjunaContext arjunaContext = ArjunaContext.getContext(context);
                    arjunaContext.setInstanceIdentifier(new InstanceIdentifier(identifierString));
                    break;
                }
            }
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) ArjunaContext(com.arjuna.webservices11.wsarj.ArjunaContext) SOAPMessage(javax.xml.soap.SOAPMessage) ProtocolException(javax.xml.ws.ProtocolException)

Example 18 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.

the class CoordinationContextHandler method handleMessageOutbound.

/**
 * check for an arjuna context attached to the message context and, if found, install its identifier as the value
 * of a soap message header element
 * @param context
 * @return
 * @throws ProtocolException
 */
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
    try {
        CoordinationContextType coordinationContext = CoordinationContextManager.getThreadContext();
        if (coordinationContext != null) {
            final JAXBContext jaxbCtx = getJaxbContext();
            // insert a header into the current message containing the coordination context
            final SOAPMessage soapMessage = context.getMessage();
            final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnvelope.getHeader();
            if (soapHeader == null) {
                soapHeader = soapEnvelope.addHeader();
            }
            /*
                 * this does not work but it is what we want!!
                 *
                 * The problem here is that the marshaller creates plain old elements and inserts them top
                 * down as it goes along. but the soap header add child method checks its argument and
                 * replaces plain elements with soap header elements before inserting them. it copies the
                 * inserted element substructure into the rpelacement but since it does not exist at
                 * copy time the chiuldren get lost
                Marshaller marshaller = jaxbCtx.createMarshaller();
                marshaller.marshal(coordinationContext, soapHeader);
                 */
            /*
                 * ok, here's the workaround -- marshall the object as a child of a dummy header, detach it and
                 * then insert it as a header element.
                 */
            SOAPHeaderElement headerElement = soapHeader.addHeaderElement(getDummyQName());
            Marshaller marshaller = jaxbCtx.createMarshaller();
            marshaller.marshal(coordinationContext, headerElement);
            soapHeader.replaceChild(headerElement.getChildNodes().item(0), headerElement);
            // ok, now we need to locate the inserted node and set the mustunderstand attribute
            Iterator<SOAPHeaderElement> iterator = soapHeader.examineAllHeaderElements();
            while (iterator.hasNext()) {
                headerElement = iterator.next();
                if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
                    headerElement.setMustUnderstand(true);
                    break;
                }
            }
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException)

Example 19 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.

the class CoordinationContextHandler method handlemessageInbound.

/**
 * check for an arjuna instance identifier element embedded in the soap message headesr and, if found, use it to
 * label an arjuna context attached to the message context
 * @param context
 * @return
 * @throws ProtocolException
 */
private boolean handlemessageInbound(SOAPMessageContext context) throws ProtocolException {
    try {
        final SOAPMessage soapMessage = context.getMessage();
        final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
        Iterator<SOAPHeaderElement> iterator = soapEnvelope.getHeader().examineAllHeaderElements();
        while (iterator.hasNext()) {
            final SOAPHeaderElement headerElement = iterator.next();
            if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
                // found it - clear the must understand flag, retrieve the value and store an arjuna
                // context in the message context
                headerElement.setMustUnderstand(false);
                final JAXBContext jaxbCtx = getJaxbContext();
                final JAXBElement<CoordinationContextType> elt = jaxbCtx.createUnmarshaller().unmarshal(headerElement, CoordinationContextType.class);
                final CoordinationContextType coordinationContext = elt.getValue();
                CoordinationContextManager.setContext(context, coordinationContext);
            }
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) JAXBContext(javax.xml.bind.JAXBContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPMessage(javax.xml.soap.SOAPMessage) ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException)

Example 20 with SOAPEnvelope

use of javax.xml.soap.SOAPEnvelope in project scout.rt by eclipse.

the class WsseUsernameTokenAuthenticationHandler method handleMessage.

@Override
public final boolean handleMessage(final SOAPMessageContext messageContext) {
    if (MessageContexts.isInboundMessage(messageContext)) {
        return true;
    }
    SOAPEnvelope envelope;
    SOAPHeader header;
    try {
        envelope = messageContext.getMessage().getSOAPPart().getEnvelope();
        header = envelope.getHeader();
        if (header == null) {
            header = envelope.addHeader();
        }
        final SOAPElement security = header.addChildElement(WS_SEC, WSSE, NAME_SPACE_URI);
        final SOAPElement userToken = security.addChildElement(USERNAME_TOKEN, WSSE);
        userToken.addChildElement(USERNAME, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_USERNAME)));
        userToken.addChildElement(PASSWORD, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_PASSWORD)));
        return true;
    } catch (final SOAPException e) {
        throw new WebServiceException("Failed to set SOAP header for WsseUsernameTokenAuthentication", e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPHeader(javax.xml.soap.SOAPHeader)

Aggregations

SOAPEnvelope (javax.xml.soap.SOAPEnvelope)59 SOAPMessage (javax.xml.soap.SOAPMessage)34 SOAPException (javax.xml.soap.SOAPException)31 SOAPBody (javax.xml.soap.SOAPBody)24 SOAPPart (javax.xml.soap.SOAPPart)24 SOAPElement (javax.xml.soap.SOAPElement)22 SOAPHeader (javax.xml.soap.SOAPHeader)16 Name (javax.xml.soap.Name)13 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)13 Iterator (java.util.Iterator)12 QName (javax.xml.namespace.QName)12 WebServiceException (javax.xml.ws.WebServiceException)10 ProtocolException (javax.xml.ws.ProtocolException)7 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 Detail (javax.xml.soap.Detail)5 MessageFactory (javax.xml.soap.MessageFactory)5 SOAPConnection (javax.xml.soap.SOAPConnection)5 SOAPFault (javax.xml.soap.SOAPFault)5 Test (org.junit.Test)5