Search in sources :

Example 1 with SOAPVersion

use of org.apache.axiom.soap.SOAPVersion in project webservices-axiom by apache.

the class RolePlayerChecker method matches.

@Override
public boolean matches(AxiomElement header, String unused1, String unused2) {
    // If we're filtering on namespace, check that first since the compare is simpler.
    if (namespace != null) {
        OMNamespace headerNamespace = header.getNamespace();
        if (headerNamespace == null || !namespace.equals(headerNamespace.getNamespaceURI())) {
            return false;
        }
    }
    String role = SOAPHeaderBlockHelper.getRole(header, soapHelper);
    SOAPVersion version = soapHelper.getVersion();
    // 1. If role is ultimatedest, go by what the rolePlayer says
    if (role == null || role.equals("") || (version instanceof SOAP12Version && role.equals(SOAP12Constants.SOAP_ROLE_ULTIMATE_RECEIVER))) {
        return (rolePlayer == null || rolePlayer.isUltimateDestination());
    }
    // 2. If role is next, always return true
    if (role.equals(version.getNextRoleURI()))
        return true;
    // 3. If role is none, always return false
    if (version instanceof SOAP12Version && role.equals(SOAP12Constants.SOAP_ROLE_NONE)) {
        return false;
    }
    // 4. Return t/f depending on match
    List<String> roles = (rolePlayer == null) ? null : rolePlayer.getRoles();
    if (roles != null) {
        for (String thisRole : roles) {
            if (thisRole.equals(role))
                return true;
        }
    }
    return false;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPVersion(org.apache.axiom.soap.SOAPVersion) SOAP12Version(org.apache.axiom.soap.SOAP12Version)

Example 2 with SOAPVersion

use of org.apache.axiom.soap.SOAPVersion in project wso2-synapse by wso2.

the class PayloadHelper method setXMLPayload.

public static void setXMLPayload(SOAPEnvelope envelope, OMElement element) {
    SOAPBody body = envelope.getBody();
    if (body == null) {
        SOAPVersion version = envelope.getVersion();
        if (version.getEnvelopeURI().equals(SOAP11Version.SOAP_ENVELOPE_NAMESPACE_URI)) {
            body = OMAbstractFactory.getSOAP11Factory().createSOAPBody();
        } else {
            body = OMAbstractFactory.getSOAP12Factory().createSOAPBody();
        }
        if (envelope.getHeader() != null) {
            envelope.getHeader().insertSiblingAfter(body);
        } else {
            envelope.addChild(body);
        }
    } else {
        for (Iterator it = body.getChildren(); it.hasNext(); ) {
            OMNode node = (OMNode) it.next();
            node.discard();
        }
    }
    body.addChild(element);
}
Also used : OMNode(org.apache.axiom.om.OMNode) SOAPBody(org.apache.axiom.soap.SOAPBody) SOAPVersion(org.apache.axiom.soap.SOAPVersion) Iterator(java.util.Iterator)

Example 3 with SOAPVersion

use of org.apache.axiom.soap.SOAPVersion in project wso2-axis2-transports by wso2.

the class XMPPSender method sendMessage.

/**
 * Send the given message over XMPP transport
 *
 * @param msgCtx the axis2 message context
 * @throws AxisFault on error
 */
public void sendMessage(MessageContext msgCtx, String targetAddress, OutTransportInfo outTransportInfo) throws AxisFault {
    XMPPConnection xmppConnection = null;
    XMPPOutTransportInfo xmppOutTransportInfo = null;
    XMPPConnectionFactory connectionFactory;
    // if on client side,create connection to xmpp server
    if (msgCtx.isServerSide()) {
        xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
        connectionFactory = xmppOutTransportInfo.getConnectionFactory();
    } else {
        getConnectionDetailsFromClientOptions(msgCtx);
        connectionFactory = defaultConnectionFactory;
    }
    synchronized (this) {
        xmppConnection = connectionFactory.getXmppConnection();
        if (xmppConnection == null) {
            connectionFactory.connect(serverCredentials);
            xmppConnection = connectionFactory.getXmppConnection();
        }
    }
    Message message = new Message();
    Options options = msgCtx.getOptions();
    String serviceName = XMPPUtils.getServiceName(targetAddress);
    SOAPVersion version = msgCtx.getEnvelope().getVersion();
    if (version instanceof SOAP12Version) {
        message.setProperty(XMPPConstants.CONTENT_TYPE, HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML + "; action=" + msgCtx.getSoapAction());
    } else {
        message.setProperty(XMPPConstants.CONTENT_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }
    if (targetAddress != null) {
        xmppOutTransportInfo = new XMPPOutTransportInfo(targetAddress);
        xmppOutTransportInfo.setConnectionFactory(defaultConnectionFactory);
    } else if (msgCtx.getTo() != null && !msgCtx.getTo().hasAnonymousAddress()) {
    // TODO
    } else if (msgCtx.isServerSide()) {
        xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
    }
    try {
        if (msgCtx.isServerSide()) {
            message.setProperty(XMPPConstants.IS_SERVER_SIDE, new Boolean(false));
            message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
            message.setProperty(XMPPConstants.SEQUENCE_ID, xmppOutTransportInfo.getSequenceID());
        } else {
            // message is going to be processed on server side
            message.setProperty(XMPPConstants.IS_SERVER_SIDE, new Boolean(true));
            // we are sending a soap envelope as a message
            message.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
            message.setProperty(XMPPConstants.SERVICE_NAME, serviceName);
            String action = options.getAction();
            if (action == null) {
                AxisOperation axisOperation = msgCtx.getAxisOperation();
                if (axisOperation != null) {
                    action = axisOperation.getSoapAction();
                }
            }
            if (action != null) {
                message.setProperty(XMPPConstants.ACTION, action);
            }
        }
        if (xmppConnection == null) {
            handleException("Connection to XMPP Server is not established.");
        }
        // initialize the chat manager using connection
        ChatManager chatManager = xmppConnection.getChatManager();
        Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);
        boolean waitForResponse = msgCtx.getOperationContext() != null && WSDL2Constants.MEP_URI_OUT_IN.equals(msgCtx.getOperationContext().getAxisOperation().getMessageExchangePattern());
        OMElement msgElement;
        String messageToBeSent = "";
        if (XMPPConstants.XMPP_CONTENT_TYPE_STRING.equals(xmppOutTransportInfo.getContentType())) {
            // if request is received from a chat client, whole soap envelope
            // should not be sent.
            OMElement soapBodyEle = msgCtx.getEnvelope().getBody();
            OMElement responseEle = soapBodyEle.getFirstElement();
            if (responseEle != null) {
                msgElement = responseEle.getFirstElement();
            } else {
                msgElement = responseEle;
            }
        } else {
            // if request received from a ws client whole soap envelope
            // must be sent.
            msgElement = msgCtx.getEnvelope();
        }
        messageToBeSent = msgElement.toString();
        message.setBody(messageToBeSent);
        String key = null;
        if (waitForResponse && !msgCtx.isServerSide()) {
            PacketFilter filter = new PacketTypeFilter(message.getClass());
            xmppConnection.addPacketListener(xmppClientSidePacketListener, filter);
            key = UUID.randomUUID().toString();
            xmppClientSidePacketListener.listenForResponse(key, msgCtx);
            message.setProperty(XMPPConstants.SEQUENCE_ID, key);
        }
        chat.sendMessage(message);
        log.debug("Sent message :" + message.toXML());
        // Is this the best way to do this?
        if (waitForResponse && !msgCtx.isServerSide()) {
            xmppClientSidePacketListener.waitFor(key);
            // xmppConnection.disconnect();
            log.debug("Received response sucessfully");
        }
    } catch (XMPPException e) {
        log.error("Error occurred while sending the message : " + message.toXML(), e);
        handleException("Error occurred while sending the message : " + message.toXML(), e);
    } catch (InterruptedException e) {
        log.error("Error occurred while sending the message : " + message.toXML(), e);
        handleException("Error occurred while sending the message : " + message.toXML(), e);
    } finally {
    // if(xmppConnection != null && !msgCtx.isServerSide()){
    // xmppConnection.disconnect();
    // }
    }
}
Also used : Options(org.apache.axis2.client.Options) XMPPConnectionFactory(org.apache.axis2.transport.xmpp.util.XMPPConnectionFactory) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) AxisMessage(org.apache.axis2.description.AxisMessage) Message(org.jivesoftware.smack.packet.Message) AxisOperation(org.apache.axis2.description.AxisOperation) OMElement(org.apache.axiom.om.OMElement) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPOutTransportInfo(org.apache.axis2.transport.xmpp.util.XMPPOutTransportInfo) SOAPVersion(org.apache.axiom.soap.SOAPVersion) Chat(org.jivesoftware.smack.Chat) XMPPException(org.jivesoftware.smack.XMPPException) ChatManager(org.jivesoftware.smack.ChatManager) SOAP12Version(org.apache.axiom.soap.SOAP12Version)

Aggregations

SOAPVersion (org.apache.axiom.soap.SOAPVersion)3 SOAP12Version (org.apache.axiom.soap.SOAP12Version)2 Iterator (java.util.Iterator)1 OMElement (org.apache.axiom.om.OMElement)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 OMNode (org.apache.axiom.om.OMNode)1 SOAPBody (org.apache.axiom.soap.SOAPBody)1 Options (org.apache.axis2.client.Options)1 AxisMessage (org.apache.axis2.description.AxisMessage)1 AxisOperation (org.apache.axis2.description.AxisOperation)1 XMPPConnectionFactory (org.apache.axis2.transport.xmpp.util.XMPPConnectionFactory)1 XMPPOutTransportInfo (org.apache.axis2.transport.xmpp.util.XMPPOutTransportInfo)1 Chat (org.jivesoftware.smack.Chat)1 ChatManager (org.jivesoftware.smack.ChatManager)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 Message (org.jivesoftware.smack.packet.Message)1