Search in sources :

Example 16 with InvalidPayloadException

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

the class CompositeApiProcessor method processInternal.

<T, R> boolean processInternal(final Class<T> bodyType, final Exchange exchange, final CompositeApiClient.Operation<T, R> clientOperation, final ResponseHandler<R> responseHandler, final AsyncCallback callback) throws SalesforceException {
    final T body;
    final Message in = exchange.getIn();
    try {
        body = in.getMandatoryBody(bodyType);
    } catch (final InvalidPayloadException e) {
        throw new SalesforceException(e);
    }
    clientOperation.submit(body, (response, exception) -> responseHandler.handleResponse(exchange, response, exception, callback));
    return false;
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Message(org.apache.camel.Message) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Example 17 with InvalidPayloadException

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

the class BeanProxyTest method testBeanProxyFailureInvalidReturnType.

public void testBeanProxyFailureInvalidReturnType() throws Exception {
    Endpoint endpoint = context.getEndpoint("direct:start");
    OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
    try {
        service.invalidReturnType("<order type=\"beer\">Carlsberg</order>");
        fail("Should have thrown exception");
    } catch (Exception e) {
        // expected
        InvalidPayloadException cause = assertIsInstanceOf(InvalidPayloadException.class, e.getCause());
        assertEquals(Integer.class, cause.getType());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) InvalidPayloadException(org.apache.camel.InvalidPayloadException) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Example 18 with InvalidPayloadException

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

the class TokenPairExpressionIterator method doEvaluate.

/**
     * Strategy to evaluate the exchange
     *
     * @param exchange   the exchange
     * @param closeStream whether to close the stream before returning from this method.
     * @return the evaluated value
     */
protected Object doEvaluate(Exchange exchange, boolean closeStream) {
    InputStream in = null;
    try {
        in = exchange.getIn().getMandatoryBody(InputStream.class);
        // we may read from a file, and want to support custom charset defined on the exchange
        String charset = IOHelper.getCharsetName(exchange);
        return createIterator(exchange, in, charset);
    } catch (InvalidPayloadException e) {
        exchange.setException(e);
        // must close input stream
        IOHelper.close(in);
        return null;
    } finally {
        if (closeStream) {
            IOHelper.close(in);
        }
    }
}
Also used : InputStream(java.io.InputStream) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Example 19 with InvalidPayloadException

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

the class XMLTokenExpressionIterator method doEvaluate.

/**
     * Strategy to evaluate the exchange
     *
     * @param exchange   the exchange
     * @param closeStream whether to close the stream before returning from this method.
     * @return the evaluated value
     */
protected Object doEvaluate(Exchange exchange, boolean closeStream) {
    InputStream in = null;
    try {
        in = exchange.getIn().getMandatoryBody(InputStream.class);
        String charset = IOHelper.getCharsetName(exchange);
        return createIterator(in, charset);
    } catch (InvalidPayloadException e) {
        exchange.setException(e);
        // must close input stream
        IOHelper.close(in);
        return null;
    } catch (XMLStreamException e) {
        exchange.setException(e);
        // must close input stream
        IOHelper.close(in);
        return null;
    } catch (UnsupportedEncodingException e) {
        exchange.setException(e);
        // must close input stream
        IOHelper.close(in);
        return null;
    } finally {
        if (closeStream) {
            IOHelper.close(in);
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Example 20 with InvalidPayloadException

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

the class MessageSupportTest method testGetMandatoryBody.

public void testGetMandatoryBody() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    Message in = exchange.getIn();
    try {
        in.getMandatoryBody();
        fail("Should have thrown an exception");
    } catch (InvalidPayloadException e) {
    // expected
    }
    in.setBody("Hello World");
    assertEquals("Hello World", in.getMandatoryBody());
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Aggregations

InvalidPayloadException (org.apache.camel.InvalidPayloadException)26 InputStream (java.io.InputStream)10 Exchange (org.apache.camel.Exchange)9 Message (org.apache.camel.Message)9 Processor (org.apache.camel.Processor)6 IOException (java.io.IOException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 Endpoint (org.apache.camel.Endpoint)3 GenericFileOperationFailedException (org.apache.camel.component.file.GenericFileOperationFailedException)3 Entry (java.util.Map.Entry)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 JAXBException (javax.xml.bind.JAXBException)2 GenericFileEndpoint (org.apache.camel.component.file.GenericFileEndpoint)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 StopWatch (org.apache.camel.util.StopWatch)2 Builder (com.google.protobuf.Message.Builder)1 JSchException (com.jcraft.jsch.JSchException)1 SftpException (com.jcraft.jsch.SftpException)1