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");
}
}
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);
}
}
}
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);
}
}
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);
}
}
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();
}
});
}
Aggregations