use of org.apache.synapse.endpoints.AddressEndpoint in project wso2-synapse by wso2.
the class SendMediatorSerializationTest method testNestedLoadbalanceFailoverSendSerialization.
public void testNestedLoadbalanceFailoverSendSerialization() {
String sendConfig = "<send xmlns=\"http://ws.apache.org/ns/synapse\">" + "<endpoint>" + "<loadbalance>" + "<endpoint>" + "<address uri=\"http://localhost:9001/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<failover>" + "<endpoint>" + "<address uri=\"http://localhost:9002/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9003/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "</failover>" + "</endpoint>" + "</loadbalance>" + "</endpoint>" + "</send>";
OMElement config1 = createOMElement(sendConfig);
SendMediator send1 = (SendMediator) factory.createMediator(config1, new Properties());
OMElement config2 = serializer.serializeMediator(null, send1);
SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());
assertTrue("Top level endpoint should be a load balance endpoint.", send2.getEndpoint() instanceof LoadbalanceEndpoint);
LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();
List children = loadbalanceEndpoint.getChildren();
assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);
assertTrue("First child should be a address endpoint", children.get(0) instanceof AddressEndpoint);
assertTrue("Second child should be a fail over endpoint", children.get(1) instanceof FailoverEndpoint);
FailoverEndpoint failoverEndpoint = (FailoverEndpoint) children.get(1);
List children2 = failoverEndpoint.getChildren();
assertEquals("Fail over endpoint should have 2 children.", children2.size(), 2);
assertTrue("Children of the fail over endpoint should be address endpoints.", children2.get(0) instanceof AddressEndpoint);
assertTrue("Children of the fail over endpoint should be address endpoints.", children2.get(1) instanceof AddressEndpoint);
}
use of org.apache.synapse.endpoints.AddressEndpoint in project wso2-synapse by wso2.
the class CalloutMediator method init.
public void init(SynapseEnvironment synEnv) {
try {
configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepository != null ? clientRepository : DEFAULT_CLIENT_REPO, axis2xml != null ? axis2xml : DEFAULT_AXIS2_XML);
if (serviceURL != null) {
serviceURL = changeEndPointReference(serviceURL);
}
blockingMsgSender = new BlockingMsgSender();
blockingMsgSender.setConfigurationContext(configCtx);
blockingMsgSender.init();
EndpointDefinition endpointDefinition = null;
if (serviceURL != null) {
// If Service URL is specified, it is given the highest priority
endpoint = new AddressEndpoint();
endpointDefinition = new EndpointDefinition();
endpointDefinition.setAddress(serviceURL);
((AddressEndpoint) endpoint).setDefinition(endpointDefinition);
isWrappingEndpointCreated = true;
} else if (endpoint == null && endpointKey == null) {
// Use a default endpoint in this case - i.e. the To header
endpoint = new DefaultEndpoint();
endpointDefinition = new EndpointDefinition();
((DefaultEndpoint) endpoint).setDefinition(endpointDefinition);
isWrappingEndpointCreated = true;
}
if (endpointDefinition != null && isSecurityOn()) {
endpointDefinition.setSecurityOn(true);
if (wsSecPolicyKey != null) {
endpointDefinition.setWsSecPolicyKey(wsSecPolicyKey);
} else {
if (inboundWsSecPolicyKey != null) {
endpointDefinition.setInboundWsSecPolicyKey(inboundWsSecPolicyKey);
}
if (outboundWsSecPolicyKey != null) {
endpointDefinition.setOutboundWsSecPolicyKey(outboundWsSecPolicyKey);
}
}
}
} catch (AxisFault e) {
String msg = "Error initializing callout mediator : " + e.getMessage();
log.error(msg, e);
throw new SynapseException(msg, e);
}
}
use of org.apache.synapse.endpoints.AddressEndpoint in project wso2-synapse by wso2.
the class SynapseEventSource method getEndpointFromURL.
/**
* Create a Endpoint for a given URL
*
* @param endpointUrl URL
* @param se synapse environment
* @return AddressEndpoint address endpoint
*/
private Endpoint getEndpointFromURL(String endpointUrl, SynapseEnvironment se) {
AddressEndpoint endpoint = new AddressEndpoint();
EndpointDefinition def = new EndpointDefinition();
def.setAddress(endpointUrl.trim());
endpoint.setDefinition(def);
endpoint.init(se);
return endpoint;
}
use of org.apache.synapse.endpoints.AddressEndpoint in project wso2-synapse by wso2.
the class ProxyServiceTest method testBuildAxisServiceWithFaultyPublishWsdlEndpoint.
/**
* Tests building a proxy service with a faulty wsdl endpoint specified as the wsdl endpoint.
*
* @throws Exception if an error occurs when converting the URI string to a URI
*/
public void testBuildAxisServiceWithFaultyPublishWsdlEndpoint() throws Exception {
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration axisCfg = new AxisConfiguration();
ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxy");
proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
try {
proxyService.buildAxisService(synCfg, axisCfg);
Assert.fail("Axis service built with null wsdl endpoint should throw fault");
} catch (SynapseException e) {
Assert.assertEquals("Unexpected exception thrown: " + e, "Unable to resolve WSDL url. wsdlEndPoint is null", e.getMessage());
}
AddressEndpoint wsdlEndpoint = new AddressEndpoint();
EndpointDefinition endpointDefinition = new EndpointDefinition();
endpointDefinition.setAddress(getClass().getResource("SimpleStockService.wsdl").toURI().toString());
wsdlEndpoint.setDefinition(endpointDefinition);
synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
try {
proxyService.buildAxisService(synCfg, axisCfg);
Assert.fail("Axis service built with faulty wsdl endpoint should be null");
} catch (SynapseException e) {
Assert.assertEquals("Unexpected exception thrown: " + e, "Error building service from WSDL", e.getMessage());
}
}
use of org.apache.synapse.endpoints.AddressEndpoint in project wso2-synapse by wso2.
the class WeightedRRLCAlgorithmTest method createEndpoints.
private List<Endpoint> createEndpoints() {
List<Endpoint> endpoints = new ArrayList<Endpoint>();
for (int i = 0; i < hosts.length; i++) {
AddressEndpoint addressEndpoint = new AddressEndpoint();
EndpointDefinition definition = new EndpointDefinition();
definition.setAddress("http://" + hosts[i] + "/");
addressEndpoint.setDefinition(definition);
MediatorProperty property = new MediatorProperty();
property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT);
property.setValue(weights[i]);
addressEndpoint.addProperty(property);
endpoints.add(addressEndpoint);
}
return endpoints;
}
Aggregations