Search in sources :

Example 6 with NoSuchEndpointException

use of org.apache.camel.NoSuchEndpointException in project camel by apache.

the class EndpointReferenceTest method testReferenceEndpointFromOtherCamelContext.

public void testReferenceEndpointFromOtherCamelContext() throws Exception {
    CamelContext context = applicationContext.getBean("camel2", CamelContext.class);
    RouteContext routeContext = new DefaultRouteContext(context);
    try {
        routeContext.resolveEndpoint(null, "endpoint1");
        fail("Should have thrown exception");
    } catch (NoSuchEndpointException exception) {
        assertTrue("Get a wrong exception message", exception.getMessage().contains("make sure the endpoint has the same camel context as the route does"));
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultRouteContext(org.apache.camel.impl.DefaultRouteContext) DefaultRouteContext(org.apache.camel.impl.DefaultRouteContext) RouteContext(org.apache.camel.spi.RouteContext) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

Example 7 with NoSuchEndpointException

use of org.apache.camel.NoSuchEndpointException in project camel by apache.

the class ExpressionBuilder method toExpression.

/**
     * Returns an expression processing the exchange to the given endpoint uri
     *
     * @param uri endpoint uri to send the exchange to
     * @return an expression object which will return the OUT body
     */
public static Expression toExpression(final String uri) {
    return new ExpressionAdapter() {

        public Object evaluate(Exchange exchange) {
            String text = simpleExpression(uri).evaluate(exchange, String.class);
            Endpoint endpoint = exchange.getContext().getEndpoint(text);
            if (endpoint == null) {
                throw new NoSuchEndpointException(text);
            }
            Producer producer;
            try {
                producer = endpoint.createProducer();
                producer.start();
                producer.process(exchange);
                producer.stop();
            } catch (Exception e) {
                throw ObjectHelper.wrapRuntimeCamelException(e);
            }
            // return the OUT body, but check for exchange pattern
            if (ExchangeHelper.isOutCapable(exchange)) {
                return exchange.getOut().getBody();
            } else {
                return exchange.getIn().getBody();
            }
        }

        @Override
        public String toString() {
            return "to(" + uri + ")";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException) InvalidPayloadException(org.apache.camel.InvalidPayloadException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ExpressionAdapter(org.apache.camel.support.ExpressionAdapter) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

Example 8 with NoSuchEndpointException

use of org.apache.camel.NoSuchEndpointException in project camel by apache.

the class CamelDestinationTest method testCAMEL4073.

@Test
public void testCAMEL4073() throws Exception {
    try {
        Endpoint.publish("camel://foo", new Person() {

            public void getPerson(Holder<String> personId, Holder<String> ssn, Holder<String> name) throws UnknownPersonFault {
            }
        });
        fail("Should throw and Exception");
    } catch (WebServiceException ex) {
        Throwable c = ex.getCause();
        assertNotNull(c);
        assertTrue(c instanceof NoSuchEndpointException);
    }
}
Also used : UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault) WebServiceException(javax.xml.ws.WebServiceException) Person(org.apache.camel.wsdl_first.Person) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) Test(org.junit.Test)

Aggregations

NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)8 Endpoint (org.apache.camel.Endpoint)4 IOException (java.io.IOException)1 WebServiceException (javax.xml.ws.WebServiceException)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 FailedToCreateConsumerException (org.apache.camel.FailedToCreateConsumerException)1 InvalidPayloadException (org.apache.camel.InvalidPayloadException)1 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1 Producer (org.apache.camel.Producer)1 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultRouteContext (org.apache.camel.impl.DefaultRouteContext)1 OptimisticLockingAggregationRepository (org.apache.camel.spi.OptimisticLockingAggregationRepository)1 RecoverableAggregationRepository (org.apache.camel.spi.RecoverableAggregationRepository)1 RouteContext (org.apache.camel.spi.RouteContext)1 ExpressionAdapter (org.apache.camel.support.ExpressionAdapter)1 Person (org.apache.camel.wsdl_first.Person)1 UnknownPersonFault (org.apache.camel.wsdl_first.UnknownPersonFault)1