use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class WeightedRoundRobin method init.
public void init(SynapseEnvironment se) {
if (endpoints == null) {
String msg = "Endpoints are not set, cannot initialize the algorithm";
log.error(msg);
throw new SynapseException(msg);
}
endpointStates = new EndpointState[endpoints.size()];
for (int i = 0; i < endpoints.size(); i++) {
Endpoint endpoint = endpoints.get(i);
if (!(endpoint instanceof PropertyInclude)) {
EndpointState state = new EndpointState(i, DEFAULT_WEIGHT);
endpointStates[i] = state;
} else {
MediatorProperty property = ((PropertyInclude) endpoint).getProperty(LOADBALANCE_WEIGHT);
EndpointState state;
if (property != null) {
int weight = Integer.parseInt(property.getValue());
if (weight <= 0) {
String msg = "Weight must be greater than zero";
log.error(msg);
throw new SynapseException(msg);
}
state = new EndpointState(i, weight);
} else {
state = new EndpointState(i, DEFAULT_WEIGHT);
}
endpointStates[i] = state;
}
}
if (loadBalanceEndpoint instanceof PropertyInclude) {
MediatorProperty threadLocalProperty = ((PropertyInclude) loadBalanceEndpoint).getProperty(LOADBALANCE_ThEADLOCAL);
if (threadLocalProperty != null && threadLocalProperty.getValue().equals("true")) {
isThreadLocal = true;
}
}
view = new WeightedRoundRobinView(this);
MBeanRegistrar.getInstance().registerMBean(view, "LBAlgorithms", loadBalanceEndpoint.getName() != null ? loadBalanceEndpoint.getName() : "LBEpr");
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class WeightedRoundRobin method changeWeight.
public void changeWeight(int pos, int weight) {
Lock writeLock = lock.writeLock();
writeLock.lock();
try {
EndpointState state = null;
for (EndpointState s : endpointStates) {
if (s.getEndpointPosition() == pos) {
state = s;
}
}
if (state == null) {
throw new SynapseException("The specified endpoint position cannot be found");
}
state.weight = weight;
calculate();
reset(null);
} finally {
writeLock.unlock();
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled.
/**
* Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the
* 'enablePublishWSDLSafeMode' set to true.
*
* @throws Exception if an error occurs when converting the URI string to a URI
*/
public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled() throws Exception {
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration axisCfg = new AxisConfiguration();
ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeDisabled");
proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
AddressEndpoint wsdlEndpoint = new AddressEndpoint();
EndpointDefinition endpointDefinition = new EndpointDefinition();
endpointDefinition.setAddress((new URI("http://localhost/SimpleStockService.wsdl")).toString());
wsdlEndpoint.setDefinition(endpointDefinition);
proxyService.addParameter("enablePublishWSDLSafeMode", false);
synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
try {
proxyService.buildAxisService(synCfg, axisCfg);
Assert.fail("Axis service built with an unreachable wsdl endpoint should throw fault");
} catch (SynapseException e) {
Assert.assertTrue("Unexpected exception thrown: " + e, e.getMessage().contains("Error reading from wsdl URI"));
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class InboundEndpointTestCase method testCreateInvalidInboundEP.
public void testCreateInvalidInboundEP() throws Exception {
InboundEndpointFactory factory = new InboundEndpointFactory();
try {
ep = factory.createInboundEndpoint(AXIOMUtil.stringToOM(invalidSampleEP), config);
Assert.fail("Expected exception is not thrown for invalid inbound EP");
} catch (SynapseException e) {
Assert.assertEquals(e.getMessage().contains("Inbound Endpoint name cannot be null"), true);
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class TransactionMediatorSerializationTest method testCreatingMediatorWithInvalidInstance.
/**
* Test for transaction mediator serialization with an invalid mediator instance
*
* @throws Exception
*/
public void testCreatingMediatorWithInvalidInstance() throws Exception {
try {
LogMediator logMediator = new LogMediator();
transactionMediatorSerializer.serializeSpecificMediator(logMediator);
fail("Test for transaction mediator serialization with an invalid mediator instance fails.");
} catch (SynapseException e) {
assertEquals("Unsupported mediator passed in for serialization : LogMediator", e.getMessage());
}
}
Aggregations