Search in sources :

Example 1 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project tdi-studio-se by Talend.

the class MSCRMClient method setServiceClientOptions.

private static void setServiceClientOptions(ServiceClient sc, SecurityData securityData) throws AxisFault, XMLStreamException {
    Options options = sc.getOptions();
    options.setMessageId("urn:uuid:" + UUID.randomUUID().toString());
    EndpointReference endPoint = new EndpointReference("http://www.w3.org/2005/08/addressing/anonymous");
    options.setReplyTo(endPoint);
    sc.setOptions(options);
    sc.addHeader(createCRMSecurityHeaderBlock(securityData));
    HttpTransportProperties.ProxyProperties proxyProps = getProxyProperties();
    if (proxyProps != null) {
        sc.getOptions().setProperty(HTTPConstants.PROXY, proxyProps);
    }
    try {
        sc.engageModule("addressing");
    } catch (AxisFault e) {
        logger.error(e.getMessage());
        throw e;
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) ProxyProperties(org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project wso2-axis2-transports by wso2.

the class XMPPPacketListener method createMessageContext.

/**
 * Creates message context using values received in XMPP packet
 * @param packet
 * @return MessageContext
 * @throws AxisFault
 */
private MessageContext createMessageContext(Packet packet) throws AxisFault {
    Message message = (Message) packet;
    Boolean isServerSide = (Boolean) message.getProperty(XMPPConstants.IS_SERVER_SIDE);
    String serviceName = (String) message.getProperty(XMPPConstants.SERVICE_NAME);
    String action = (String) message.getProperty(XMPPConstants.ACTION);
    MessageContext msgContext = null;
    TransportInDescription transportIn = configurationContext.getAxisConfiguration().getTransportIn("xmpp");
    TransportOutDescription transportOut = configurationContext.getAxisConfiguration().getTransportOut("xmpp");
    if ((transportIn != null) && (transportOut != null)) {
        msgContext = configurationContext.createMessageContext();
        msgContext.setTransportIn(transportIn);
        msgContext.setTransportOut(transportOut);
        if (isServerSide != null) {
            msgContext.setServerSide(isServerSide.booleanValue());
        }
        msgContext.setProperty(CONTENT_TYPE, "text/xml");
        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
        msgContext.setIncomingTransportName("xmpp");
        Map services = configurationContext.getAxisConfiguration().getServices();
        AxisService axisService = (AxisService) services.get(serviceName);
        msgContext.setAxisService(axisService);
        msgContext.setSoapAction(action);
        // pass the configurationFactory to transport sender
        msgContext.setProperty("XMPPConfigurationFactory", this.xmppConnectionFactory);
        if (packet.getFrom() != null) {
            msgContext.setFrom(new EndpointReference(packet.getFrom()));
        }
        if (packet.getTo() != null) {
            msgContext.setTo(new EndpointReference(packet.getTo()));
        }
        XMPPOutTransportInfo xmppOutTransportInfo = new XMPPOutTransportInfo();
        xmppOutTransportInfo.setConnectionFactory(this.xmppConnectionFactory);
        String packetFrom = packet.getFrom();
        if (packetFrom != null) {
            EndpointReference fromEPR = new EndpointReference(packetFrom);
            xmppOutTransportInfo.setFrom(fromEPR);
            xmppOutTransportInfo.setDestinationAccount(packetFrom);
        }
        // Save Message-Id to set as In-Reply-To on reply
        String xmppMessageId = packet.getPacketID();
        if (xmppMessageId != null) {
            xmppOutTransportInfo.setInReplyTo(xmppMessageId);
        }
        xmppOutTransportInfo.setSequenceID((String) message.getProperty(XMPPConstants.SEQUENCE_ID));
        msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, xmppOutTransportInfo);
        buildSOAPEnvelope(packet, msgContext);
    } else {
        throw new AxisFault("Either transport in or transport out is null");
    }
    return msgContext;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Message(org.jivesoftware.smack.packet.Message) AxisService(org.apache.axis2.description.AxisService) MessageContext(org.apache.axis2.context.MessageContext) TransportInDescription(org.apache.axis2.description.TransportInDescription) Map(java.util.Map) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 3 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project wso2-axis2-transports by wso2.

the class SMSManager method dispatchToAxis2.

/**
 * Dispatch the SMS message to Axis2 Engine
 * @param sms
 */
public void dispatchToAxis2(SMSMessage sms) {
    try {
        MessageContext msgctx = messageBuilder.buildMessaage(sms, configurationContext);
        msgctx.setReplyTo(new EndpointReference("sms://" + sms.getSender() + "/"));
        AxisEngine.receive(msgctx);
    } catch (InvalidMessageFormatException e) {
        log.debug("Invalid message format " + e);
    } catch (AxisFault axisFault) {
        log.debug(axisFault);
    } catch (Throwable e) {
        log.debug("Unknown Exception ", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 4 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project wso2-synapse by wso2.

the class JsonStreamBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext) throws AxisFault {
    if (inputStream != null) {
        OMElement element = JsonUtil.getNewJsonPayload(messageContext, inputStream, false, false);
        if (element != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("#processDocument. Built JSON payload from JSON stream. MessageID: " + messageContext.getMessageID());
            }
            return element;
        }
    } else {
        EndpointReference endpointReference = messageContext.getTo();
        if (endpointReference == null) {
            logger.error("#processDocument. Cannot build payload without a valid EPR. MessageID: " + messageContext.getMessageID());
            throw new AxisFault("Cannot build payload without a valid EPR.");
        }
        String requestURL;
        try {
            requestURL = URIEncoderDecoder.decode(endpointReference.getAddress());
        } catch (UnsupportedEncodingException e) {
            logger.error("#processDocument. Could not decode request URL. MessageID: " + messageContext.getMessageID());
            throw new AxisFault("Could not decode request URL.", e);
        }
        String jsonString;
        int index;
        // half as the incoming JSON message
        if ((index = requestURL.indexOf('=')) > 0) {
            jsonString = requestURL.substring(index + 1);
            messageContext.setProperty(Constants.JSON_STRING, jsonString);
            ByteArrayInputStream is = new ByteArrayInputStream(jsonString.getBytes());
            return processDocument(is, s, messageContext);
        } else {
            messageContext.setProperty(Constants.JSON_STRING, null);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("#processDocument. No JSON payload found in request. MessageID: " + messageContext.getMessageID());
    }
    SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
    return factory.getDefaultEnvelope();
}
Also used : AxisFault(org.apache.axis2.AxisFault) OMElement(org.apache.axiom.om.OMElement) SOAPFactory(org.apache.axiom.soap.SOAPFactory) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 5 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project wso2-synapse by wso2.

the class XFormURLEncodedBuilder method processDocumentWrapper.

/**
 * @return Returns the document element.
 */
private OMElement processDocumentWrapper(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
    MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();
    SOAPFactory soapFactory;
    AxisBindingOperation axisBindingOperation = (AxisBindingOperation) messageContext.getProperty(Constants.AXIS_BINDING_OPERATION);
    String queryParameterSeparator = null;
    String templatedPath = null;
    if (axisBindingOperation != null) {
        queryParameterSeparator = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
        templatedPath = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
    }
    if (queryParameterSeparator == null) {
        queryParameterSeparator = WSDL20DefaultValueHolder.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR_DEFAULT;
    }
    AxisEndpoint axisEndpoint = (AxisEndpoint) messageContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
    if (axisEndpoint != null) {
        AxisBinding axisBinding = axisEndpoint.getBinding();
        String soapVersion = (String) axisBinding.getProperty(WSDL2Constants.ATTR_WSOAP_VERSION);
        soapFactory = getSOAPFactory(soapVersion);
    } else {
        soapFactory = getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    }
    EndpointReference endpointReference = messageContext.getTo();
    if (endpointReference == null) {
        throw new AxisFault("Cannot create DocumentElement without destination EPR");
    }
    String requestURL = endpointReference.getAddress();
    try {
        requestURL = extractParametersUsingHttpLocation(templatedPath, parameterMap, requestURL, queryParameterSeparator);
    } catch (UnsupportedEncodingException e) {
        throw AxisFault.makeFault(e);
    }
    String query = requestURL;
    int index;
    if ((index = requestURL.indexOf("?")) > -1) {
        query = requestURL.substring(index + 1);
    }
    extractParametersFromRequest(parameterMap, query, queryParameterSeparator, (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING), inputStream);
    messageContext.setProperty(Constants.REQUEST_PARAMETER_MAP, parameterMap);
    return BuilderUtil.buildsoapMessage(messageContext, parameterMap, soapFactory);
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisBinding(org.apache.axis2.description.AxisBinding) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MultipleEntryHashMap(org.apache.axis2.util.MultipleEntryHashMap) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) AxisEndpoint(org.apache.axis2.description.AxisEndpoint) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)95 Options (org.apache.axis2.client.Options)28 MessageContext (org.apache.axis2.context.MessageContext)25 OMElement (org.apache.axiom.om.OMElement)23 AxisFault (org.apache.axis2.AxisFault)22 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)21 ServiceClient (org.apache.axis2.client.ServiceClient)20 MessageContext (org.apache.synapse.MessageContext)14 URL (java.net.URL)12 QName (javax.xml.namespace.QName)12 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)11 AxisService (org.apache.axis2.description.AxisService)10 MalformedURLException (java.net.MalformedURLException)9 Map (java.util.Map)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)9 HttpTransportProperties (org.apache.axis2.transport.http.HttpTransportProperties)8 HashMap (java.util.HashMap)7 SynapseException (org.apache.synapse.SynapseException)7 SOAPFactory (org.apache.axiom.soap.SOAPFactory)6 OperationClient (org.apache.axis2.client.OperationClient)6