Search in sources :

Example 16 with EndpointReference

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

the class AxisOperationClient method setMessageContext.

/**
 * Creating the message context of the soap message     *
 * @param addUrl WS-Addressing EPR url
 * @param trpUrl Transport url
 * @param action Soap action
 */
private void setMessageContext(String addUrl, String trpUrl, String action) {
    outMsgCtx = new MessageContext();
    // assigning message context’s option object into instance variable
    Options options = outMsgCtx.getOptions();
    // setting properties into option
    if (trpUrl != null && !"null".equals(trpUrl)) {
        options.setProperty(Constants.Configuration.TRANSPORT_URL, trpUrl);
    }
    if (addUrl != null && !"null".equals(addUrl)) {
        options.setTo(new EndpointReference(addUrl));
    }
    if (action != null && !"null".equals(action)) {
        options.setAction(action);
    }
}
Also used : Options(org.apache.axis2.client.Options) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 17 with EndpointReference

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

the class XQueryReplaceEmptyMessageBodyTestCase method testXQueryTransformationForEmptyBody.

public void testXQueryTransformationForEmptyBody() throws AxisFault {
    ServiceClient sender = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference("http://localhost:8280/services/xQueryMediatorReplaceEmptyMessageBodyTestProxy"));
    options.setAction("urn:getQuote");
    sender.setOptions(options);
    OMElement response = sender.sendReceive(null);
    assertNotNull("Response is null", response);
    assertEquals("Symbol name mismatched", "WSO2", response.getFirstElement().getFirstChildWithName(new QName("http://services.samples/xsd", "symbol")).getText());
}
Also used : Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 18 with EndpointReference

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

the class GetPropertyFunction method evaluate.

/**
 * Returns the string value of the property using arg one as key and arg two as scope
 *
 * @param scopeObject scope will decide from where property will be picked up from
 *        i.e. axis2, transport, default/synapse
 * @param keyObject the key of the property
 * @param navigator object model which can be used for navigation around
 * @param dateformat The dateformat that need to convert
 * @return The String value of property using arg one as key and arg two as scope
 */
public Object evaluate(Object scopeObject, Object keyObject, Object dateformat, Navigator navigator) {
    boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
    boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
    String scope = StringFunction.evaluate(scopeObject, navigator);
    String key = StringFunction.evaluate(keyObject, navigator);
    if (key == null || "".equals(key)) {
        if (traceOrDebugOn) {
            traceOrDebug(traceOn, "property-name should be provided when executing synapse:get-property" + "(scope,prop-name) or synapse:get-property(prop-name) Xpath function");
        }
        return NULL_STRING;
    }
    if (SynapseConstants.SYSTEM_DATE.equals(key)) {
        if (dateformat != null) {
            Format formatter = new SimpleDateFormat(dateformat.toString());
            return formatter.format(new java.util.Date());
        } else {
            Format formatter = new SimpleDateFormat();
            return formatter.format(new java.util.Date());
        }
    }
    // return the current system time as a string , don't care scope
    if (SynapseConstants.SYSTEM_TIME.equals(key)) {
        return Long.toString(System.currentTimeMillis());
    }
    if (XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
        if (SynapseConstants.HEADER_TO.equals(key)) {
            EndpointReference toEPR = synCtx.getTo();
            if (toEPR != null) {
                return toEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_FROM.equals(key)) {
            EndpointReference fromEPR = synCtx.getFrom();
            if (fromEPR != null) {
                return fromEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_ACTION.equals(key)) {
            String wsaAction = synCtx.getWSAAction();
            if (wsaAction != null) {
                return wsaAction;
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_FAULT.equals(key)) {
            EndpointReference faultEPR = synCtx.getFaultTo();
            if (faultEPR != null) {
                return faultEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_REPLY_TO.equals(key)) {
            EndpointReference replyToEPR = synCtx.getReplyTo();
            if (replyToEPR != null) {
                return replyToEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_RELATES_TO.equals(key)) {
            RelatesTo relatesTo = synCtx.getRelatesTo();
            if (relatesTo != null) {
                return relatesTo.getValue();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_MESSAGE_ID.equals(key)) {
            String messageID = synCtx.getMessageID();
            if (messageID != null) {
                return messageID;
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.PROPERTY_FAULT.equals(key)) {
            if (synCtx.getEnvelope().hasFault()) {
                return SynapseConstants.TRUE;
            } else if (synCtx instanceof Axis2MessageContext) {
                org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                if (axis2MessageContext.getProperty(BaseConstants.FAULT_MESSAGE) != null && SynapseConstants.TRUE.equals(axis2MessageContext.getProperty(BaseConstants.FAULT_MESSAGE))) {
                    return SynapseConstants.TRUE;
                }
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.PROPERTY_MESSAGE_FORMAT.equals(key)) {
            if (synCtx.isDoingPOX())
                return SynapseConstants.FORMAT_POX;
            else if (synCtx.isDoingGET())
                return SynapseConstants.FORMAT_GET;
            else if (synCtx.isSOAP11())
                return SynapseConstants.FORMAT_SOAP11;
            else
                return SynapseConstants.FORMAT_SOAP12;
        } else if (SynapseConstants.PROPERTY_OPERATION_NAME.equals(key) || SynapseConstants.PROPERTY_OPERATION_NAMESPACE.equals(key)) {
            if (synCtx instanceof Axis2MessageContext) {
                AxisOperation axisOperation = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getAxisOperation();
                if (axisOperation != null) {
                    if (SynapseConstants.PROPERTY_OPERATION_NAMESPACE.equals(key)) {
                        return axisOperation.getName().getNamespaceURI();
                    } else {
                        return axisOperation.getName().getLocalPart();
                    }
                }
            }
        } else {
            Object result = synCtx.getProperty(key);
            if (result != null) {
                return result;
            } else {
                return synCtx.getLocalEntry(key);
            }
        }
    } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) {
        org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
        return axis2MessageContext.getProperty(key);
    } else if (XMLConfigConstants.SCOPE_FUNC.equals(scope)) {
        Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
        TemplateContext topCtxt = functionStack.peek();
        if (topCtxt != null) {
            return topCtxt.getParameterValue(key);
        }
    } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) {
        org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
        Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
        if (headers != null && headers instanceof Map) {
            Map headersMap = (Map) headers;
            return headersMap.get(key);
        }
    } else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope) && synCtx instanceof Axis2MessageContext) {
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        return axis2smc.getAxis2MessageContext().getOperationContext().getProperty(key);
    } else if (XMLConfigConstants.SCOPE_REGISTRY.equals(scope)) {
        String[] regParam = key.split("@");
        String regPath = null;
        String propName = null;
        if (regParam.length == 2) {
            regPath = regParam[0];
            propName = regParam[1];
        } else if (regParam.length == 1) {
            regPath = regParam[0];
        }
        Entry propEntry = synCtx.getConfiguration().getEntryDefinition(regPath);
        if (propEntry == null) {
            propEntry = new Entry();
            propEntry.setType(Entry.REMOTE_ENTRY);
            propEntry.setKey(key);
        }
        Registry registry = synCtx.getConfiguration().getRegistry();
        if (registry != null) {
            registry.getResource(propEntry, new Properties());
            if (propName != null) {
                Properties reqProperties = propEntry.getEntryProperties();
                if (reqProperties != null) {
                    if (reqProperties.get(propName) != null) {
                        return reqProperties.getProperty(propName);
                    }
                }
            } else if (propEntry.getValue() != null) {
                if (propEntry.getValue() instanceof OMText) {
                    return ((OMText) propEntry.getValue()).getText();
                }
                return propEntry.getValue().toString();
            }
        }
    } else if (XMLConfigConstants.SCOPE_SYSTEM.equals(scope)) {
        String propVal = System.getProperty(key);
        if (propVal != null) {
            return propVal;
        } else {
            if (traceOrDebugOn) {
                traceOrDebug(traceOn, "System property " + key + " not found");
            }
            return NULL_STRING;
        }
    } else if (XMLConfigConstants.SCOPE_ENVIRONMENT.equals(scope)) {
        String propVal = System.getenv(key);
        if (propVal != null) {
            return propVal;
        } else {
            if (traceOrDebugOn) {
                traceOrDebug(traceOn, "Environment property " + key + " not found");
            }
            return NULL_STRING;
        }
    } else if (XMLConfigConstants.SCOPE_FILE.equals(scope)) {
        String propVal = FilePropertyLoader.getInstance().getValue(key);
        if (propVal != null) {
            return propVal;
        } else {
            if (traceOrDebugOn) {
                traceOrDebug(traceOn, "Property " + key + " not found in properties file");
            }
            return NULL_STRING;
        }
    } else {
        if (traceOrDebugOn) {
            traceOrDebug(traceOn, "Invalid scope : '" + scope + "' has been set for the " + "synapse:get-property(scope,prop-name) XPath function");
        }
    }
    return NULL_STRING;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) Properties(java.util.Properties) RelatesTo(org.apache.axis2.addressing.RelatesTo) Entry(org.apache.synapse.config.Entry) Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) OMText(org.apache.axiom.om.OMText) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Registry(org.apache.synapse.registry.Registry) TemplateContext(org.apache.synapse.mediators.template.TemplateContext) EndpointReference(org.apache.axis2.addressing.EndpointReference) Stack(java.util.Stack) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map)

Example 19 with EndpointReference

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

the class SynapseCommodityServiceTest method testN2N.

public void testN2N() throws Exception {
    // Creating the Simple Commodity Client
    System.getProperties().remove(org.apache.axis2.Constants.AXIS2_CONF);
    ServiceClient businessClient = new ServiceClient(null, null);
    Options options = new Options();
    options.setTo(new EndpointReference("http://127.0.0.1:10100/CommodityQuote"));
    businessClient.setOptions(options);
    OMElement response = null;
    response = businessClient.sendReceive(commodityPayload());
    assertNotNull(response);
    SynapseXPath xPath = new SynapseXPath("//return");
    xPath.addNamespace("ns", "http://services.samples/xsd");
    OMElement returnEle = (OMElement) xPath.selectSingleNode(response);
    assertNotNull(returnEle);
    assertEquals(returnEle.getText().trim(), "100");
}
Also used : Options(org.apache.axis2.client.Options) SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 20 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)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)258 Options (org.apache.axis2.client.Options)96 AxisFault (org.apache.axis2.AxisFault)65 OMElement (org.apache.axiom.om.OMElement)64 MessageContext (org.apache.axis2.context.MessageContext)58 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)57 ServiceClient (org.apache.axis2.client.ServiceClient)51 QName (javax.xml.namespace.QName)40 ArrayList (java.util.ArrayList)37 AxisService (org.apache.axis2.description.AxisService)28 Map (java.util.Map)25 MessageContext (org.apache.synapse.MessageContext)25 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)25 Test (org.junit.Test)20 IOException (java.io.IOException)19 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)18 RelatesTo (org.apache.axis2.addressing.RelatesTo)18 URL (java.net.URL)17 SOAPFactory (org.apache.axiom.soap.SOAPFactory)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17