Search in sources :

Example 36 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class ServiceDynamicLoadbalanceEndpoint method init.

@Override
public void init(SynapseEnvironment synapseEnvironment) {
    if (!initialized) {
        super.init(synapseEnvironment);
        ConfigurationContext cfgCtx = ((Axis2SynapseEnvironment) synapseEnvironment).getAxis2ConfigurationContext();
        ClusteringAgent clusteringAgent = cfgCtx.getAxisConfiguration().getClusteringAgent();
        if (clusteringAgent == null) {
            throw new SynapseException("Axis2 ClusteringAgent not defined in axis2.xml");
        }
        // Add the Axis2 GroupManagement agents
        for (String domain : hostDomainMap.values()) {
            if (clusteringAgent.getGroupManagementAgent(domain) == null) {
                clusteringAgent.addGroupManagementAgent(new DefaultGroupManagementAgent(), domain);
            }
        }
        slbMembershipHandler = new ServiceLoadBalanceMembershipHandler(hostDomainMap, getAlgorithm(), cfgCtx, isClusteringEnabled, getName());
        // Initialize the SAL Sessions if already has not been initialized.
        SALSessions salSessions = SALSessions.getInstance();
        if (!salSessions.isInitialized()) {
            salSessions.initialize(isClusteringEnabled, cfgCtx);
        }
        initialized = true;
        log.info("ServiceDynamicLoadbalanceEndpoint initialized");
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) DefaultGroupManagementAgent(org.apache.axis2.clustering.management.DefaultGroupManagementAgent) SynapseException(org.apache.synapse.SynapseException) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent) SALSessions(org.apache.synapse.endpoints.dispatch.SALSessions) ServiceLoadBalanceMembershipHandler(org.apache.synapse.core.axis2.ServiceLoadBalanceMembershipHandler)

Example 37 with SynapseException

use of org.apache.synapse.SynapseException 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 38 with SynapseException

use of org.apache.synapse.SynapseException 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 39 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class InboundEndpoint method init.

public void init(SynapseEnvironment se) {
    log.info("Initializing Inbound Endpoint: " + getName());
    synapseEnvironment = se;
    if (isSuspend) {
        log.info("Inbound endpoint " + name + " is currently suspended.");
        return;
    }
    inboundRequestProcessor = getInboundRequestProcessor();
    if (inboundRequestProcessor != null) {
        try {
            inboundRequestProcessor.init();
        } catch (Exception e) {
            String msg = "Error initializing inbound endpoint " + getName();
            log.error(msg);
            throw new SynapseException(msg, e);
        }
    } else {
        String msg = "Inbound Request processor not found for Inbound EP : " + name + " Protocol: " + protocol + " Class" + classImpl;
        log.error(msg);
        throw new SynapseException(msg);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) JaxenException(org.jaxen.JaxenException) SynapseException(org.apache.synapse.SynapseException)

Example 40 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class WeightedRRLCAlgorithm method intialize.

/**
 * Initialize the algorithm reading the configurations from the endpoints.
 */
private void intialize() {
    // get the global properties
    if (loadBalanceEndpoint != null && loadBalanceEndpoint instanceof PropertyInclude) {
        PropertyInclude include = (PropertyInclude) loadBalanceEndpoint;
        MediatorProperty val = include.getProperty(LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
        if (val != null) {
            roundsPerRecalculation = Integer.parseInt(val.getValue());
        }
    }
    // initialize the states list, this runs only once
    list = new WeightedState[endpoints.size()];
    int totalWeight = 0;
    for (Endpoint endpoint : endpoints) {
        if (endpoint instanceof PropertyInclude) {
            PropertyInclude include = (PropertyInclude) endpoint;
            MediatorProperty val = include.getProperty(LB_WEIGHTED_RRLC_WEIGHT);
            if (val == null) {
                String msg = "Parameter " + "loadbalance.weighted.weight should be specified for every " + "endpoint in the load balance group";
                log.error(msg);
                throw new SynapseException(msg);
            }
            totalWeight += Integer.parseInt(val.getValue());
        }
    }
    this.totalWeight = totalWeight;
    for (int i = 0; i < endpoints.size(); i++) {
        Endpoint e = endpoints.get(i);
        if (e instanceof PropertyInclude) {
            PropertyInclude include = (PropertyInclude) e;
            MediatorProperty weight = include.getProperty(LB_WEIGHTED_RRLC_WEIGHT);
            String key;
            URL url;
            if (e instanceof AddressEndpoint) {
                AddressEndpoint addressEndpoint = (AddressEndpoint) e;
                try {
                    url = new URL(addressEndpoint.getDefinition().getAddress());
                } catch (MalformedURLException e1) {
                    String msg = "Mulformed URL in address endpoint";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            } else if (e instanceof WSDLEndpoint) {
                WSDLEndpoint wsdlEndpoint = (WSDLEndpoint) e;
                try {
                    url = new URL(wsdlEndpoint.getDefinition().getAddress());
                } catch (MalformedURLException e1) {
                    String msg = "Mulformed URL in address endpoint";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            } else {
                String msg = "Only AddressEndpoint and WSDLEndpoint can be used " + "with WeightedRRLCAlgorithm";
                log.error(msg);
                throw new SynapseException(msg);
            }
            // construct the key
            key = url.getHost() + ":" + url.getPort();
            WeightedState state = new WeightedState(Integer.parseInt(weight.getValue()), i, key);
            MediatorProperty minimumWeight = include.getProperty(LB_WEIGHTED_RRLC_WEIGHT_MIN);
            if (minimumWeight != null) {
                state.setMinWeight(Integer.parseInt(minimumWeight.getValue()));
            }
            MediatorProperty maxWeight = include.getProperty(LB_WEIGHTED_RRLC_WEIGHT_MAX);
            if (maxWeight != null) {
                state.setMaxWeight(Integer.parseInt(maxWeight.getValue()));
            }
            list[i] = state;
        }
    }
    // sort the states according to the initial fixed weights
    Arrays.sort(list, new Comparator<WeightedState>() {

        public int compare(WeightedState o1, WeightedState o2) {
            return o2.getFixedWeight() - o1.getFixedWeight();
        }
    });
}
Also used : WSDLEndpoint(org.apache.synapse.endpoints.WSDLEndpoint) MalformedURLException(java.net.MalformedURLException) MediatorProperty(org.apache.synapse.mediators.MediatorProperty) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) WSDLEndpoint(org.apache.synapse.endpoints.WSDLEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) SynapseException(org.apache.synapse.SynapseException) PropertyInclude(org.apache.synapse.PropertyInclude) WSDLEndpoint(org.apache.synapse.endpoints.WSDLEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) URL(java.net.URL)

Aggregations

SynapseException (org.apache.synapse.SynapseException)136 OMElement (org.apache.axiom.om.OMElement)31 OMAttribute (org.apache.axiom.om.OMAttribute)23 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 QName (javax.xml.namespace.QName)15 Iterator (java.util.Iterator)14 JaxenException (org.jaxen.JaxenException)14 XMLStreamException (javax.xml.stream.XMLStreamException)13 AxisFault (org.apache.axis2.AxisFault)13 Map (java.util.Map)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)8 OMNode (org.apache.axiom.om.OMNode)7 Mediator (org.apache.synapse.Mediator)7 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)7