Search in sources :

Example 1 with Endpoint

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

the class CloneMediator method init.

public void init(SynapseEnvironment se) {
    synapseEnv = se;
    for (Target target : targets) {
        ManagedLifecycle seq = target.getSequence();
        if (seq != null) {
            seq.init(se);
        } else if (target.getSequenceRef() != null) {
            SequenceMediator targetSequence = (SequenceMediator) se.getSynapseConfiguration().getSequence(target.getSequenceRef());
            if (targetSequence == null || targetSequence.isDynamic()) {
                se.addUnavailableArtifactRef(target.getSequenceRef());
            }
        }
        Endpoint endpoint = target.getEndpoint();
        if (endpoint != null) {
            endpoint.init(se);
        }
    }
}
Also used : Target(org.apache.synapse.mediators.eip.Target) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 2 with Endpoint

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

the class ForwardingService method validateResponse.

/**
 * Validate if response can be considered as a successful Back-end invocation
 *
 * @param responseMessage MessageContext of response
 * @return true if it is a successful invocation
 */
private boolean validateResponse(MessageContext responseMessage) {
    boolean isSuccessful;
    String responseSc = ((Axis2MessageContext) responseMessage).getAxis2MessageContext().getProperty(SynapseConstants.HTTP_SC).toString();
    // Some events where response code is null (i.e. sender socket timeout
    // when there is no response from endpoint)
    int sc = 0;
    try {
        sc = Integer.parseInt(responseSc.trim());
        isSuccessful = getHTTPStatusCodeFamily(sc).equals(HTTPStatusCodeFamily.SUCCESSFUL) || isNonRetryErrorCode(responseSc);
    } catch (NumberFormatException nfe) {
        isSuccessful = false;
    }
    if (!isSuccessful) {
        String statusCode = " ";
        if (sc != 0) {
            statusCode = Integer.toString(sc);
        }
        log.info("Message processor [" + this.messageProcessor.getName() + "] received a response with HTTP_SC: " + statusCode + " from backend " + targetEndpoint + ". Message forwarding failed.");
    }
    return isSuccessful;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 3 with Endpoint

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

the class EndpointDeployer method undeploySynapseArtifact.

@Override
public void undeploySynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Endpoint Undeployment of the endpoint named : " + artifactName + " : Started");
    }
    try {
        Endpoint ep = getSynapseConfiguration().getDefinedEndpoints().get(artifactName);
        if (ep != null) {
            CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");
            getSynapseConfiguration().removeEndpoint(artifactName);
            if (log.isDebugEnabled()) {
                log.debug("Destroying the endpoint named : " + artifactName);
            }
            ep.destroy();
            if (log.isDebugEnabled()) {
                log.debug("Endpoint Undeployment of the endpoint named : " + artifactName + " : Completed");
            }
            log.info("Endpoint named '" + ep.getName() + "' has been undeployed");
        } else if (log.isDebugEnabled()) {
            log.debug("Endpoint " + artifactName + " has already been undeployed");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Endpoint Undeployement of endpoint named : " + artifactName + " : Failed", e);
    }
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 4 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, SessionCookie cookie) {
    if (cookie == null || "".equals(cookie.getSessionId())) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find Session ID from the cookie.");
        }
        return;
    }
    String sessionId = cookie.getSessionId();
    String path = cookie.getPath();
    boolean createSession = false;
    if (log.isDebugEnabled()) {
        log.debug("Starting to update the session for : " + cookie);
    }
    // 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 corresponds to: " + cookie);
        }
        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();
        // This assumes that there can only be one path
        if (!sessionId.equals(oldSessionID) && pathMatches(path, oldSession.getPath())) {
            if (log.isDebugEnabled()) {
                log.debug("Renew the session : previous session id :" + oldSessionID + " new session :" + cookie);
            }
            removeSession(oldSessionID);
            endpoints = oldSession.getEndpointList();
            currentMember = oldSession.getMember();
            createSession = true;
        } else {
            SessionInformation information = getSessionInformation(oldSessionID);
            if (information == null) {
                // 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;
        List<String> paths = new ArrayList<String>();
        // add the new path
        paths.add(path);
        if (currentMember == null) {
            newInformation = createSessionInformation(synCtx, sessionId, endpoints, paths);
        } else {
            newInformation = createSessionInformation(synCtx, sessionId, currentMember, paths);
        }
        if (log.isDebugEnabled()) {
            log.debug("Establishing a session for :" + cookie + " 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)

Example 5 with Endpoint

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

the class SALSessions method fillMap.

/*
     * Helper method to get a map from a list - This is for clustered env.
     */
private void fillMap(List<Endpoint> endpoints, Map<String, Endpoint> endpointsMap) {
    if (endpoints != null) {
        for (Endpoint endpoint : endpoints) {
            String endpointName = getEndpointName(endpoint);
            if (endpointsMap.containsKey(endpointName)) {
                handleException("Endpoint Name with ' " + endpointName + "' already there. " + "Endpoint name must be unique.");
            }
            endpointsMap.put(endpointName, endpoint);
            fillMap(endpoint.getChildren(), endpointsMap);
        }
    }
}
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)

Aggregations

Endpoint (org.apache.synapse.endpoints.Endpoint)65 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)10 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)9 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)8 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)8 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)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