Search in sources :

Example 41 with SynapseException

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");
}
Also used : MediatorProperty(org.apache.synapse.mediators.MediatorProperty) SynapseException(org.apache.synapse.SynapseException) Endpoint(org.apache.synapse.endpoints.Endpoint) PropertyInclude(org.apache.synapse.PropertyInclude) Endpoint(org.apache.synapse.endpoints.Endpoint)

Example 42 with SynapseException

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();
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 43 with SynapseException

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"));
    }
}
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) URI(java.net.URI)

Example 44 with SynapseException

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);
    }
}
Also used : InboundEndpointFactory(org.apache.synapse.config.xml.inbound.InboundEndpointFactory) SynapseException(org.apache.synapse.SynapseException)

Example 45 with SynapseException

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());
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) LogMediator(org.apache.synapse.mediators.builtin.LogMediator)

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