Search in sources :

Example 51 with Endpoint

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

the class EndpointDeployer method restoreSynapseArtifact.

@Override
public void restoreSynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Restoring the Endpoint with name : " + artifactName + " : Started");
    }
    try {
        Endpoint ep = getSynapseConfiguration().getDefinedEndpoints().get(artifactName);
        CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");
        OMElement epElem = EndpointSerializer.getElementFromEndpoint(ep);
        if (ep.getFileName() != null) {
            String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.ENDPOINTS_DIR + File.separator + ep.getFileName();
            writeToFile(epElem, fileName);
            if (log.isDebugEnabled()) {
                log.debug("Restoring the Endpoint with name : " + artifactName + " : Completed");
            }
            log.info("Endpoint named '" + artifactName + "' has been restored");
        } else {
            handleSynapseArtifactDeploymentError("Couldn't restore the endpoint named '" + artifactName + "', filename cannot be found");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Restoring of the endpoint named '" + artifactName + "' has failed", e);
    }
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) OMElement(org.apache.axiom.om.OMElement) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 52 with Endpoint

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

the class SynapseConfiguration method init.

/**
 * This method will be called in the startup of Synapse or in an initiation
 * and will initialize all the managed parts of the Synapse Configuration
 *
 * @param se SynapseEnvironment specifying the env to be initialized
 */
public synchronized void init(SynapseEnvironment se) {
    SynapseConfiguration previouseConfiguration = null;
    if (log.isDebugEnabled()) {
        log.debug("Initializing the Synapse Configuration using the SynapseEnvironment");
    }
    // initialize registry
    if (registry != null && registry instanceof ManagedLifecycle) {
        ((ManagedLifecycle) registry).init(se);
    }
    // we initialize xpath extensions here since synapse environment is available
    initXpathExtensions(se);
    initCarbonTenantConfigurator(se);
    // initialize endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        try {
            endpoint.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing endpoint [" + endpoint.getName() + "] " + e.getMessage());
        }
    }
    // initialize sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        try {
            seqTemplate.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Sequence Template [" + seqTemplate.getName() + "] " + e.getMessage());
        }
    }
    String tenantDomain = getTenantDomain(se);
    if (tenantDomain != null) {
        previouseConfiguration = SynapseConfigUtils.getSynapseConfiguration(tenantDomain);
        SynapseConfigUtils.addSynapseConfiguration(tenantDomain, this);
    }
    if (previouseConfiguration != null) {
        destroyExistingInbounds(previouseConfiguration);
    }
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        try {
            endpoint.init(se);
        } catch (Exception e) {
            inboundEndpointMap.remove(endpoint.getName());
            log.error(" Error in initializing inbound endpoint [" + endpoint.getName() + "] " + e.getMessage());
        }
    }
    // initialize managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        if (seq != null) {
            try {
                seq.init(se);
            } catch (Exception e) {
                log.error(" Error in initializing Sequence " + e.getMessage());
            }
        }
    }
    // initialize all the proxy services
    for (ProxyService proxy : getProxyServices()) {
        try {
            if (proxy.getTargetInLineEndpoint() != null) {
                proxy.getTargetInLineEndpoint().init(se);
            }
            if (proxy.getTargetInLineInSequence() != null) {
                proxy.getTargetInLineInSequence().init(se);
            }
            if (proxy.getTargetInLineOutSequence() != null) {
                proxy.getTargetInLineOutSequence().init(se);
            }
            if (proxy.getTargetInLineFaultSequence() != null) {
                proxy.getTargetInLineFaultSequence().init(se);
            }
        } catch (Exception e) {
            log.error(" Error in initializing Proxy Service [ " + proxy.getName() + "] " + e.getMessage());
        }
    }
    // initialize the startups
    for (ManagedLifecycle stp : getStartups()) {
        if (stp != null) {
            try {
                stp.init(se);
            } catch (Exception e) {
                log.error(" Error in initializing Stratups " + e.getMessage());
            }
        }
    }
    // initialize sequence executors
    for (PriorityExecutor executor : getPriorityExecutors().values()) {
        try {
            executor.init();
        } catch (Exception e) {
            log.error(" Error in initializing Executor [ " + executor.getName() + "] " + e.getMessage());
        }
    }
    // initialize message stores
    for (MessageStore messageStore : messageStores.values()) {
        try {
            messageStore.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Message Store [ " + messageStore.getName() + "] " + e.getMessage());
        }
    }
    // initialize message processors
    for (MessageProcessor messageProcessor : messageProcessors.values()) {
        try {
            messageProcessor.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing Message Processor [ " + messageProcessor.getName() + "] " + e.getMessage());
        }
    }
    for (API api : apiTable.values()) {
        try {
            api.init(se);
        } catch (Exception e) {
            log.error(" Error in initializing API [ " + api.getName() + "] " + e.getMessage());
        }
    }
    initImportedLibraries(se);
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

Example 53 with Endpoint

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

the class SynapseConfiguration method destroy.

public synchronized void destroy(boolean preserverState) {
    if (log.isDebugEnabled()) {
        log.debug("Destroying the Synapse Configuration");
    }
    // clear the timer tasks of Synapse
    synapseTimer.cancel();
    synapseTimer = null;
    // stop and shutdown all the proxy services
    for (ProxyService p : getProxyServices()) {
        if (p.getTargetInLineInSequence() != null) {
            p.getTargetInLineInSequence().destroy();
        }
        if (p.getTargetInLineOutSequence() != null) {
            p.getTargetInLineOutSequence().destroy();
        }
    }
    // destroy the managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        seq.destroy();
    }
    // destroy sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        seqTemplate.destroy();
    }
    // destroy inbound endpoint
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        // This path trigger from server shutdown hook. So we don't want to remove scheduled inbound tasks
        // from registry. Only un-deployment should remove task from registry. Ref product-ei#1206
        endpoint.destroy(false);
    }
    // destroy the managed endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        endpoint.destroy();
    }
    // destroy the startups
    for (ManagedLifecycle stp : startups.values()) {
        stp.destroy();
    }
    // clear session information used for SA load balancing
    try {
        SALSessions.getInstance().reset();
        DataSourceRepositoryHolder.getInstance().getDataSourceRepositoryManager().clear();
    } catch (Throwable ignored) {
    }
    // destroy the priority executors.
    for (PriorityExecutor pe : executors.values()) {
        pe.destroy();
    }
    // destroy the Message Stores
    for (MessageStore ms : messageStores.values()) {
        if (ms instanceof AbstractMessageProcessor) {
            ((AbstractMessageProcessor) ms).destroy(preserverState);
        } else {
            ms.destroy();
        }
    }
    // destroy the Message processors
    for (MessageProcessor mp : messageProcessors.values()) {
        mp.destroy();
    }
    for (API api : apiTable.values()) {
        api.destroy();
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 54 with Endpoint

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

the class Target method mediate.

/**
 * process the message through this target (may be to mediate
 * using the target sequence, send message to the target endpoint or both)
 *
 * @param synCtx - MessageContext to be mediated
 * @return <code>false</code> if the target is mediated as synchronous and the sequence
 * mediation returns <code>false</code>, <code>true</code> otherwise
 */
public boolean mediate(MessageContext synCtx) {
    boolean returnValue = true;
    if (log.isDebugEnabled()) {
        log.debug("Target mediation : START");
    }
    if (soapAction != null) {
        if (log.isDebugEnabled()) {
            log.debug("Setting the SOAPAction as : " + soapAction);
        }
        synCtx.setSoapAction(soapAction);
    }
    if (toAddress != null) {
        if (log.isDebugEnabled()) {
            log.debug("Setting the To header as : " + toAddress);
        }
        if (synCtx.getTo() != null) {
            synCtx.getTo().setAddress(toAddress);
        } else {
            synCtx.setTo(new EndpointReference(toAddress));
        }
    }
    // through a sequence and then again with an endpoint
    if (sequence != null) {
        if (asynchronous) {
            if (log.isDebugEnabled()) {
                log.debug("Asynchronously mediating using the in-lined anonymous sequence");
            }
            synCtx.getEnvironment().injectAsync(synCtx, sequence);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Synchronously mediating using the in-lined anonymous sequence");
            }
            returnValue = sequence.mediate(synCtx);
        }
    } else if (sequenceRef != null) {
        SequenceMediator refSequence = (SequenceMediator) synCtx.getSequence(sequenceRef);
        // if target directs the message to a defined sequence, ReliantContState added by
        // Clone/Iterate mediator is no longer needed as defined sequence can be directly
        // referred from a SeqContinuationState
        ContinuationStackManager.removeReliantContinuationState(synCtx);
        if (refSequence != null) {
            if (asynchronous) {
                if (log.isDebugEnabled()) {
                    log.debug("Asynchronously mediating using the sequence " + "named : " + sequenceRef);
                }
                synCtx.getEnvironment().injectAsync(synCtx, refSequence);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Synchronously mediating using the sequence " + "named : " + sequenceRef);
                }
                try {
                    returnValue = refSequence.mediate(synCtx);
                } catch (SynapseException syne) {
                    if (!synCtx.getFaultStack().isEmpty()) {
                        log.warn("Executing fault handler due to exception encountered");
                        ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
                    } else {
                        log.warn("Exception encountered but no fault handler found - message dropped");
                    }
                } catch (Exception e) {
                    String msg = "Unexpected error occurred executing the Target";
                    log.error(msg, e);
                    if (synCtx.getServiceLog() != null) {
                        synCtx.getServiceLog().error(msg, e);
                    }
                    if (!synCtx.getFaultStack().isEmpty()) {
                        log.warn("Executing fault handler due to exception encountered");
                        ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, e);
                    } else {
                        log.warn("Exception encountered but no fault handler found - message dropped");
                    }
                }
            }
        } else {
            handleException("Couldn't find the sequence named : " + sequenceRef);
        }
    } else if (endpoint != null) {
        if (log.isDebugEnabled()) {
            log.debug("Sending using the in-lined anonymous endpoint");
        }
        ContinuationStackManager.removeReliantContinuationState(synCtx);
        endpoint.send(synCtx);
    } else if (endpointRef != null) {
        ContinuationStackManager.removeReliantContinuationState(synCtx);
        Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef);
        if (epr != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending using the endpoint named : " + endpointRef);
            }
            if (!epr.isInitialized()) {
                // initializing registry
                epr.init(synCtx.getEnvironment());
            // base endpoint configuration
            }
            epr.send(synCtx);
        // epr.destroy();
        } else {
            handleException("Couldn't find the endpoint named : " + endpointRef);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Target mediation : END");
    }
    return returnValue;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) FaultHandler(org.apache.synapse.FaultHandler) SynapseException(org.apache.synapse.SynapseException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 55 with Endpoint

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

the class SALSessions method updateSession.

/**
 * Update or establish a session
 *
 * @param synCtx    Synapse MessageContext
 * @param sessionID session id
 */
public void updateSession(MessageContext synCtx, String sessionID) {
    if (sessionID == null || "".equals(sessionID)) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find session ID .Returing null");
        }
        return;
    }
    boolean createSession = false;
    // if this is related to the already established session
    SessionInformation oldSession = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
    List<Endpoint> endpoints = null;
    Member currentMember = null;
    if (oldSession == null) {
        if (log.isDebugEnabled()) {
            log.debug("Going to create a New session with id  " + sessionID);
        }
        endpoints = (List<Endpoint>) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        createSession = true;
    } else {
        String oldSessionID = oldSession.getId();
        if (!sessionID.equals(oldSessionID)) {
            if (log.isDebugEnabled()) {
                log.debug("Renew the session : previous session id :" + oldSessionID + " new session id :" + sessionID);
            }
            removeSession(oldSessionID);
            endpoints = oldSession.getEndpointList();
            currentMember = oldSession.getMember();
            createSession = true;
        } else {
            SessionInformation information = getSessionInformation(oldSessionID);
            if (information == null) {
                // Therefore, it is recovered using session information in the message context
                if (log.isDebugEnabled()) {
                    log.debug("Recovering lost session information for session id " + sessionID);
                }
                endpoints = oldSession.getEndpointList();
                currentMember = oldSession.getMember();
                createSession = true;
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Session with id : " + sessionID + " is still live.");
                }
            }
        }
    }
    if (createSession) {
        SessionInformation newInformation;
        if (currentMember == null) {
            newInformation = createSessionInformation(synCtx, sessionID, endpoints);
        } else {
            newInformation = createSessionInformation(synCtx, sessionID, currentMember, null);
        }
        if (log.isDebugEnabled()) {
            log.debug("Establishing a session with id :" + sessionID + " and it's endpoint sequence : " + endpoints);
        }
        if (isClustered) {
            Replicator.setAndReplicateState(SESSION_IDS + sessionID, newInformation, configCtx);
        } else {
            establishedSessions.put(sessionID, newInformation);
        }
    }
}
Also used : SALoadbalanceEndpoint(org.apache.synapse.endpoints.SALoadbalanceEndpoint) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) DynamicLoadbalanceEndpoint(org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint) Member(org.apache.axis2.clustering.Member)

Aggregations

Endpoint (org.apache.synapse.endpoints.Endpoint)64 OMElement (org.apache.axiom.om.OMElement)22 SynapseException (org.apache.synapse.SynapseException)13 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)13 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)11 ArrayList (java.util.ArrayList)10 MessageContext (org.apache.synapse.MessageContext)9 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)8 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)8 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)8 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)8 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)8 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)8 OMAttribute (org.apache.axiom.om.OMAttribute)7 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)7 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)7 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)7 QName (javax.xml.namespace.QName)6 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)6 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)6