Search in sources :

Example 1 with Member

use of org.apache.axis2.clustering.Member in project pentaho-platform by pentaho.

the class AxisWebServiceManager method initServices.

/*
   * (non-Javadoc)
   * 
   * @see org.pentaho.platform.plugin.services.pluginmgr.IServiceManager#initServices()
   */
public void initServices() throws ServiceInitializationException {
    getConfigurator().setSession(PentahoSessionHolder.getSession());
    AxisConfigurator axisConfigurator = getConfigurator();
    // create the axis configuration and make it accessible to content generators via static member
    ConfigurationContext configContext = null;
    try {
        configContext = ConfigurationContextFactory.createConfigurationContext(axisConfigurator);
    } catch (AxisFault e) {
        throw new ServiceInitializationException(e);
    }
    configContext.setProperty(Constants.CONTAINER_MANAGED, Constants.VALUE_TRUE);
    currentAxisConfigContext = configContext;
    currentAxisConfiguration = configContext.getAxisConfiguration();
    // now load the services
    axisConfigurator.loadServices();
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SystemSolutionAxisConfigurator(org.pentaho.platform.plugin.services.webservices.SystemSolutionAxisConfigurator) AbstractAxisConfigurator(org.pentaho.platform.plugin.services.webservices.AbstractAxisConfigurator) AxisConfigurator(org.apache.axis2.engine.AxisConfigurator) ServiceInitializationException(org.pentaho.platform.api.engine.ServiceInitializationException)

Example 2 with Member

use of org.apache.axis2.clustering.Member in project wso2-synapse by wso2.

the class ServiceDynamicLoadbalanceEndpoint method sendMessage.

private void sendMessage(MessageContext synCtx) {
    logSetter();
    setCookieHeader(synCtx);
    // TODO: Refactor Session Aware LB dispatching code
    // Check whether a valid session for session aware dispatching is available
    Member currentMember = null;
    SessionInformation sessionInformation = null;
    if (isSessionAffinityBasedLB()) {
        // first check if this session is associated with a session. if so, get the endpoint
        // associated for that session.
        sessionInformation = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        if (sessionInformation == null && currentMember == null) {
            sessionInformation = dispatcher.getSession(synCtx);
            if (sessionInformation != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Current session id : " + sessionInformation.getId());
                }
                currentMember = sessionInformation.getMember();
                synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
                // This is for reliably recovery any session information if while response is getting ,
                // session information has been removed by cleaner.
                // This will not be a cost as  session information a not heavy data structure
                synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
            }
        }
    }
    // Dispatch request the relevant member
    String targetHost = getTargetHost(synCtx);
    ConfigurationContext configCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
    if (slbMembershipHandler.getConfigurationContext() == null) {
        slbMembershipHandler.setConfigurationContext(configCtx);
    }
    ServiceDynamicLoadbalanceFaultHandlerImpl faultHandler = new ServiceDynamicLoadbalanceFaultHandlerImpl();
    faultHandler.setHost(targetHost);
    setupTransportHeaders(synCtx);
    if (sessionInformation != null && currentMember != null) {
        // send message on current session
        sessionInformation.updateExpiryTime();
        sendToApplicationMember(synCtx, currentMember, faultHandler, false);
    } else {
        // prepare for a new session
        currentMember = slbMembershipHandler.getNextApplicationMember(targetHost);
        if (currentMember == null) {
            String msg = "No application members available";
            log.error(msg);
            throw new SynapseException(msg);
        }
        sendToApplicationMember(synCtx, currentMember, faultHandler, true);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SessionInformation(org.apache.synapse.endpoints.dispatch.SessionInformation) SynapseException(org.apache.synapse.SynapseException) Member(org.apache.axis2.clustering.Member)

Example 3 with Member

use of org.apache.axis2.clustering.Member in project wso2-synapse by wso2.

the class DynamicLoadbalanceEndpoint method sendToApplicationMember.

protected void sendToApplicationMember(MessageContext synCtx, Member currentMember, DynamicLoadbalanceFaultHandler faultHandler, boolean newSession) {
    // Rewriting the URL
    org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
    // Removing the REST_URL_POSTFIX - this is a hack.
    // In this loadbalance endpoint we create an endpoint per request by setting the complete url as the adress.
    // If a REST message comes Axis2FlexibleMEPClient append the REST_URL_POSTFIX to the adress. Hence endpoint fails
    // do send the request. e.g.  http://localhost:8080/example/index.html/example/index.html
    axis2MsgCtx.removeProperty(NhttpConstants.REST_URL_POSTFIX);
    String transport = axis2MsgCtx.getTransportIn().getName();
    String address = synCtx.getTo().getAddress();
    int incomingPort = extractPort(synCtx, transport);
    EndpointReference to = getEndpointReferenceAfterURLRewrite(currentMember, transport, address, incomingPort);
    synCtx.setTo(to);
    faultHandler.setTo(to);
    faultHandler.setCurrentMember(currentMember);
    synCtx.pushFaultHandler(faultHandler);
    if (isFailover()) {
        synCtx.getEnvelope().build();
    }
    Endpoint endpoint = getEndpoint(to, currentMember, synCtx);
    faultHandler.setCurrentEp(endpoint);
    if (isSessionAffinityBasedLB()) {
        synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT, getSessionTimeout());
        synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_DISPATCHER, dispatcher);
        prepareEndPointSequence(synCtx, endpoint);
        if (newSession) {
            synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
            // we should also indicate that this is the first message in the session. so that
            // onFault(...) method can resend only the failed attempts for the first message.
            synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_FIRST_MESSAGE_IN_SESSION, Boolean.TRUE);
        }
    }
    Map<String, String> memberHosts;
    if ((memberHosts = (Map<String, String>) currentMember.getProperties().get(HttpSessionDispatcher.HOSTS)) == null) {
        currentMember.getProperties().put(HttpSessionDispatcher.HOSTS, memberHosts = new HashMap<String, String>());
    }
    memberHosts.put(extractHost(synCtx), "true");
    setupTransportHeaders(synCtx);
    try {
        endpoint.send(synCtx);
    } catch (Exception e) {
        if (e.getMessage().toLowerCase().contains("io reactor shutdown")) {
            log.fatal("System cannot continue normal operation. Restarting", e);
            // restart
            System.exit(121);
        } else {
            throw new SynapseException(e);
        }
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) MalformedURLException(java.net.MalformedURLException) SynapseException(org.apache.synapse.SynapseException) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 4 with Member

use of org.apache.axis2.clustering.Member in project wso2-synapse by wso2.

the class DynamicLoadbalanceEndpoint method sendMessage.

private void sendMessage(MessageContext synCtx) {
    logSetter();
    SessionInformation sessionInformation = null;
    Member currentMember = null;
    // TODO Temp hack: ESB removes the session id from request in a random manner.
    setCookieHeader(synCtx);
    ConfigurationContext configCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
    if (lbMembershipHandler.getConfigurationContext() == null) {
        lbMembershipHandler.setConfigurationContext(configCtx);
    }
    if (isSessionAffinityBasedLB()) {
        // first check if this session is associated with a session. if so, get the endpoint
        // associated for that session.
        sessionInformation = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
        currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
        if (sessionInformation == null && currentMember == null) {
            sessionInformation = dispatcher.getSession(synCtx);
            if (sessionInformation != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Current session id : " + sessionInformation.getId());
                }
                currentMember = sessionInformation.getMember();
                synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
                // This is for reliably recovery any session information if while response is getting ,
                // session information has been removed by cleaner.
                // This will not be a cost as  session information a not heavy data structure
                synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
            }
        }
    }
    DynamicLoadbalanceFaultHandlerImpl faultHandler = new DynamicLoadbalanceFaultHandlerImpl();
    if (sessionInformation != null && currentMember != null) {
        // send message on current session
        sessionInformation.updateExpiryTime();
        sendToApplicationMember(synCtx, currentMember, faultHandler, false);
    } else {
        // prepare for a new session
        currentMember = lbMembershipHandler.getNextApplicationMember(algorithmContext);
        if (currentMember == null) {
            String msg = "No application members available";
            log.error(msg);
            throw new SynapseException(msg);
        }
        sendToApplicationMember(synCtx, currentMember, faultHandler, true);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SessionInformation(org.apache.synapse.endpoints.dispatch.SessionInformation) SynapseException(org.apache.synapse.SynapseException) Member(org.apache.axis2.clustering.Member)

Example 5 with Member

use of org.apache.axis2.clustering.Member 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)

Aggregations

Member (org.apache.axis2.clustering.Member)14 SynapseException (org.apache.synapse.SynapseException)7 EndpointReference (org.apache.axis2.addressing.EndpointReference)5 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)5 Endpoint (org.apache.synapse.endpoints.Endpoint)5 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 OMElement (org.apache.axiom.om.OMElement)4 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)4 URL (java.net.URL)3 AxisFault (org.apache.axis2.AxisFault)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 QName (javax.xml.namespace.QName)2 ClusteringAgent (org.apache.axis2.clustering.ClusteringAgent)2 MessageContext (org.apache.synapse.MessageContext)2 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)2 DynamicLoadbalanceEndpoint (org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint)2 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)2 SALoadbalanceEndpoint (org.apache.synapse.endpoints.SALoadbalanceEndpoint)2