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;
}
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());
}
}
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);
}
}
}
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);
}
}
}
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());
}
Aggregations