Search in sources :

Example 6 with EndpointReference

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

the class APIManagerExtensionHandlerTest method testHandleRequestWithGlobalOutSeqWithoutFurtherMediationAndCustomOutSeq.

// Test when both global and custom out sequences are there and global sequence instructs to hault with the
// the custom mediation execution. (global mediation seq returns a false after mediation)
@Test
public void testHandleRequestWithGlobalOutSeqWithoutFurtherMediationAndCustomOutSeq() {
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    SynapseConfiguration synapseConfig = Mockito.mock(SynapseConfiguration.class);
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
    Options options = Mockito.mock(Options.class);
    EndpointReference endPoint = Mockito.mock(EndpointReference.class);
    Map localRegistry = Mockito.mock(Map.class);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    Mockito.when(((Axis2MessageContext) messageContext).getConfiguration()).thenReturn(synapseConfig);
    Mockito.when(synapseConfig.getLocalRegistry()).thenReturn(localRegistry);
    Mockito.when(axis2MsgCntxt.getOptions()).thenReturn(options);
    Mockito.when(options.getTo()).thenReturn(endPoint);
    Mockito.when(endPoint.getAddress()).thenReturn("http://localhost:9443/test");
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API)).thenReturn(API_NAME);
    SequenceMediator outSeq = Mockito.mock(SequenceMediator.class);
    SequenceMediator globalOutSeq = Mockito.mock(SequenceMediator.class);
    Mockito.when(localRegistry.get(API_NAME + "--" + DIRECTION_OUT)).thenReturn(outSeq);
    Mockito.when(localRegistry.get(EXT_SEQUENCE_PREFIX + DIRECTION_OUT)).thenReturn(globalOutSeq);
    Mockito.when(((Mediator) outSeq).mediate(messageContext)).thenReturn(true);
    // Global mediation returns a false to prevent any further mediation
    Mockito.when(((Mediator) globalOutSeq).mediate(messageContext)).thenReturn(false);
    APIManagerExtensionHandler handler = createAPIManagerExtensionHandler();
    // both methods are executed during a full request path
    handler.handleRequest(messageContext);
    handler.handleResponse(messageContext);
    // check whether custom out sequnce is not executed
    Mockito.verify(outSeq, Mockito.never()).mediate(messageContext);
    // check whether global out sequnce is executed once
    Mockito.verify(globalOutSeq, Mockito.times(1)).mediate(messageContext);
}
Also used : Options(org.apache.axis2.client.Options) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Map(java.util.Map) EndpointReference(org.apache.axis2.addressing.EndpointReference) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 7 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 8 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 9 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)

Example 10 with EndpointReference

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

the class XFormURLEncodedBuilderTest method testProcessDocumentPostMethod.

/**
 * Test XFormURLEncodedBuilder with HTTP POST method
 * @throws AxisFault
 */
public void testProcessDocumentPostMethod() throws AxisFault {
    String expectedSoapEnvelope = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body>" + "<xformValues>" + "<price>10</price>" + "<symbol>WSO2</symbol>" + "</xformValues>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    String expectedSoapEnvelope2 = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body>" + "<xformValues>" + "<symbol>WSO2</symbol>" + "<price>10</price>" + "</xformValues>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    MessageContext messageContext = Util.newMessageContext();
    messageContext.setTo(new EndpointReference("http://localhost:9000/stockquote/test?symbol=WSO2&price=10"));
    messageContext.setProperty(HTTPConstants.HTTP_METHOD, "POST");
    XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
    OMElement element = urlEncodedBuilder.processDocument(null, "", messageContext);
    boolean assertion = expectedSoapEnvelope.equals(element.toString()) || expectedSoapEnvelope2.equals(element.toString());
    assertTrue("Invalid SOAPEnvelope received", assertion);
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)126 Options (org.apache.axis2.client.Options)49 ServiceClient (org.apache.axis2.client.ServiceClient)29 OMElement (org.apache.axiom.om.OMElement)26 AxisFault (org.apache.axis2.AxisFault)26 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)25 MessageContext (org.apache.axis2.context.MessageContext)25 MessageContext (org.apache.synapse.MessageContext)25 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)25 Map (java.util.Map)20 Test (org.junit.Test)14 URL (java.net.URL)13 HttpTransportProperties (org.apache.axis2.transport.http.HttpTransportProperties)13 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)13 QName (javax.xml.namespace.QName)12 AxisService (org.apache.axis2.description.AxisService)12 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 MalformedURLException (java.net.MalformedURLException)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10