Search in sources :

Example 26 with AddressEndpoint

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);
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) SendMediator(org.apache.synapse.mediators.builtin.SendMediator) Properties(java.util.Properties) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Example 27 with 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);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) BlockingMsgSender(org.apache.synapse.message.senders.blocking.BlockingMsgSender) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition)

Example 28 with AddressEndpoint

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;
}
Also used : AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition)

Example 29 with AddressEndpoint

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());
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 30 with AddressEndpoint

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;
}
Also used : AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) MediatorProperty(org.apache.synapse.mediators.MediatorProperty) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) ArrayList(java.util.ArrayList) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint)

Aggregations

AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)34 OMElement (org.apache.axiom.om.OMElement)17 Endpoint (org.apache.synapse.endpoints.Endpoint)12 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)10 MessageContext (org.apache.synapse.MessageContext)10 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)10 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)10 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)7 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)7 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)7 Test (org.junit.Test)7 List (java.util.List)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)6 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)6 LoadbalanceEndpoint (org.apache.synapse.endpoints.LoadbalanceEndpoint)6 SynapseException (org.apache.synapse.SynapseException)5 FailoverEndpoint (org.apache.synapse.endpoints.FailoverEndpoint)4 CallMediator (org.apache.synapse.mediators.builtin.CallMediator)4 SendMediator (org.apache.synapse.mediators.builtin.SendMediator)4