Search in sources :

Example 1 with DefaultEndpoint

use of org.apache.synapse.endpoints.DefaultEndpoint in project wso2-synapse by wso2.

the class CallMediator method handleBlockingCall.

/**
 * Send request in blocking manner
 *
 * @param synInCtx message context
 * @return  continue the mediation flow or not
 */
private boolean handleBlockingCall(MessageContext synInCtx) {
    SynapseLog synLog = getLog(synInCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start : Call mediator - Blocking Call");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synInCtx.getEnvelope());
        }
    }
    MessageContext resultMsgCtx = null;
    // set initClientOption with blockingMsgsender
    blockingMsgSender.setInitClientOptions(initClientOptions);
    // blocking sender.
    if (endpoint == null) {
        endpoint = new DefaultEndpoint();
        EndpointDefinition endpointDefinition = new EndpointDefinition();
        ((DefaultEndpoint) endpoint).setDefinition(endpointDefinition);
        isWrappingEndpointCreated = true;
    }
    try {
        if ("true".equals(synInCtx.getProperty(SynapseConstants.OUT_ONLY))) {
            blockingMsgSender.send(endpoint, synInCtx);
        } else {
            resultMsgCtx = blockingMsgSender.send(endpoint, synInCtx);
            if ("true".equals(resultMsgCtx.getProperty(SynapseConstants.BLOCKING_SENDER_ERROR))) {
                handleFault(synInCtx, (Exception) resultMsgCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
            }
        }
    } catch (Exception ex) {
        handleFault(synInCtx, ex);
    }
    if (resultMsgCtx != null) {
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Response payload received : " + resultMsgCtx.getEnvelope());
        }
        try {
            synInCtx.setEnvelope(resultMsgCtx.getEnvelope());
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("End : Call mediator - Blocking Call");
            }
            return true;
        } catch (Exception e) {
            handleFault(synInCtx, e);
        }
    } else {
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Service returned a null response");
        }
    }
    return true;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) MessageContext(org.apache.synapse.MessageContext) SynapseException(org.apache.synapse.SynapseException)

Example 2 with DefaultEndpoint

use of org.apache.synapse.endpoints.DefaultEndpoint in project wso2-synapse by wso2.

the class StatisticSynapseConfigurationObserverTest method testEndpointAdded.

/**
 * Test EndpointAdded by hash generation.
 */
@Test
public void testEndpointAdded() {
    DefaultEndpoint endpoint = new DefaultEndpoint();
    observer.endpointAdded(endpoint);
    Assert.assertNotNull("New hash must be set by the method", endpoint.getDefinition().getAspectConfiguration().getHashCode());
}
Also used : DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) Test(org.junit.Test)

Example 3 with DefaultEndpoint

use of org.apache.synapse.endpoints.DefaultEndpoint in project wso2-synapse by wso2.

the class DefaultEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof DefaultEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    DefaultEndpoint defaultEndpoint = (DefaultEndpoint) endpoint;
    serializeCommonAttributes(defaultEndpoint, endpointElement);
    EndpointDefinition epAddress = defaultEndpoint.getDefinition();
    OMElement defaultElement = serializeEndpointDefinition(epAddress);
    endpointElement.addChild(defaultElement);
    // serialize the properties
    serializeProperties(defaultEndpoint, endpointElement);
    return endpointElement;
}
Also used : DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement)

Example 4 with DefaultEndpoint

use of org.apache.synapse.endpoints.DefaultEndpoint in project wso2-synapse by wso2.

the class DefaultEndpointFactory method createEndpoint.

protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    DefaultEndpoint defaultEndpoint = new DefaultEndpoint();
    OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name != null) {
        defaultEndpoint.setName(name.getAttributeValue());
    }
    OMElement defaultElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "default"));
    if (defaultElement != null) {
        EndpointDefinition endpoint = createEndpointDefinition(defaultElement);
        defaultEndpoint.setDefinition(endpoint);
        processAuditStatus(endpoint, defaultEndpoint.getName(), defaultElement);
    }
    processProperties(defaultEndpoint, epConfig);
    return defaultEndpoint;
}
Also used : DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) QName(javax.xml.namespace.QName) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 5 with DefaultEndpoint

use of org.apache.synapse.endpoints.DefaultEndpoint in project wso2-synapse by wso2.

the class CalloutMediator method init.

public void init(SynapseEnvironment synEnv) {
    try {
        configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepository != null ? clientRepository : DEFAULT_CLIENT_REPO, axis2xml != null ? axis2xml : DEFAULT_AXIS2_XML);
        if (serviceURL != null) {
            serviceURL = changeEndPointReference(serviceURL);
        }
        blockingMsgSender = new BlockingMsgSender();
        blockingMsgSender.setConfigurationContext(configCtx);
        blockingMsgSender.init();
        EndpointDefinition endpointDefinition = null;
        if (serviceURL != null) {
            // If Service URL is specified, it is given the highest priority
            endpoint = new AddressEndpoint();
            endpointDefinition = new EndpointDefinition();
            endpointDefinition.setAddress(serviceURL);
            ((AddressEndpoint) endpoint).setDefinition(endpointDefinition);
            isWrappingEndpointCreated = true;
        } else if (endpoint == null && endpointKey == null) {
            // Use a default endpoint in this case - i.e. the To header
            endpoint = new DefaultEndpoint();
            endpointDefinition = new EndpointDefinition();
            ((DefaultEndpoint) endpoint).setDefinition(endpointDefinition);
            isWrappingEndpointCreated = true;
        }
        if (endpointDefinition != null && isSecurityOn()) {
            endpointDefinition.setSecurityOn(true);
            if (wsSecPolicyKey != null) {
                endpointDefinition.setWsSecPolicyKey(wsSecPolicyKey);
            } else {
                if (inboundWsSecPolicyKey != null) {
                    endpointDefinition.setInboundWsSecPolicyKey(inboundWsSecPolicyKey);
                }
                if (outboundWsSecPolicyKey != null) {
                    endpointDefinition.setOutboundWsSecPolicyKey(outboundWsSecPolicyKey);
                }
            }
        }
    } catch (AxisFault e) {
        String msg = "Error initializing callout mediator : " + e.getMessage();
        log.error(msg, e);
        throw new SynapseException(msg, e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) BlockingMsgSender(org.apache.synapse.message.senders.blocking.BlockingMsgSender) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition)

Aggregations

DefaultEndpoint (org.apache.synapse.endpoints.DefaultEndpoint)6 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)4 OMElement (org.apache.axiom.om.OMElement)3 SynapseException (org.apache.synapse.SynapseException)2 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 AxisFault (org.apache.axis2.AxisFault)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseLog (org.apache.synapse.SynapseLog)1 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)1 BlockingMsgSender (org.apache.synapse.message.senders.blocking.BlockingMsgSender)1 Test (org.junit.Test)1