use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class Olingo2Producer method process.
@Override
public boolean process(final Exchange exchange, final AsyncCallback callback) {
// properties for method arguments
final Map<String, Object> properties = new HashMap<String, Object>();
properties.putAll(endpoint.getEndpointProperties());
propertiesHelper.getExchangeProperties(exchange, properties);
// let the endpoint and the Producer intercept properties
endpoint.interceptProperties(properties);
interceptProperties(properties);
// create response handler
properties.put(Olingo2Endpoint.RESPONSE_HANDLER_PROPERTY, new Olingo2ResponseHandler<Object>() {
@Override
public void onResponse(Object response) {
// producer returns a single response, even for methods with List return types
exchange.getOut().setBody(response);
// copy headers
exchange.getOut().setHeaders(exchange.getIn().getHeaders());
interceptResult(response, exchange);
callback.done(false);
}
@Override
public void onException(Exception ex) {
exchange.setException(ex);
callback.done(false);
}
@Override
public void onCanceled() {
exchange.setException(new RuntimeCamelException("OData HTTP Request cancelled!"));
callback.done(false);
}
});
// decide which method to invoke
final ApiMethod method = findMethod(exchange, properties);
if (method == null) {
// synchronous failure
callback.done(true);
return true;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Invoking operation {} with {}", method.getName(), properties.keySet());
}
try {
doInvokeMethod(method, properties);
} catch (Throwable t) {
exchange.setException(ObjectHelper.wrapRuntimeCamelException(t));
callback.done(true);
return true;
}
return false;
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class AttachmentHttpBinding method populateAttachments.
@Override
protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
try {
Collection<Part> parts = request.getParts();
for (Part part : parts) {
DataSource ds = new PartDataSource(part);
Attachment attachment = new DefaultAttachment(ds);
for (String headerName : part.getHeaderNames()) {
for (String headerValue : part.getHeaders(headerName)) {
attachment.addHeader(headerName, headerValue);
}
}
message.addAttachmentObject(part.getName(), attachment);
}
} catch (Exception e) {
throw new RuntimeCamelException("Cannot populate attachments", e);
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class SmppConnectionFactory method connectProxy.
private void connectProxy(String host, int port, Socket socket) throws IOException {
try {
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
String connectString = "CONNECT " + host + ":" + port + " HTTP/1.0\r\n";
out.write(connectString.getBytes());
String username = config.getHttpProxyUsername();
String password = config.getHttpProxyPassword();
if (username != null && password != null) {
String usernamePassword = username + ":" + password;
byte[] code = Base64.encodeBase64(usernamePassword.getBytes());
out.write("Proxy-Authorization: Basic ".getBytes());
out.write(code);
out.write("\r\n".getBytes());
}
Map<String, String> proxyHeaders = config.getProxyHeaders();
if (proxyHeaders != null) {
for (Map.Entry<String, String> entry : proxyHeaders.entrySet()) {
out.write((entry.getKey() + ": " + entry.getValue()).getBytes());
out.write("\r\n".getBytes());
}
}
out.write("\r\n".getBytes());
out.flush();
int ch = 0;
BufferedReader reader = IOHelper.buffered(new InputStreamReader(in));
String response = reader.readLine();
if (response == null) {
throw new RuntimeCamelException("Empty response to CONNECT request to host " + host + ":" + port);
}
String reason = "Unknown reason";
int code = -1;
try {
ch = response.indexOf(' ');
int bar = response.indexOf(' ', ch + 1);
code = Integer.parseInt(response.substring(ch + 1, bar));
reason = response.substring(bar + 1);
} catch (NumberFormatException e) {
throw new RuntimeCamelException("Invalid response to CONNECT request to host " + host + ":" + port + " - cannot parse code from response string: " + response);
}
if (code != 200) {
throw new RuntimeCamelException("Proxy error: " + reason);
}
// read until empty line
for (; response.length() > 0; ) {
response = reader.readLine();
if (response == null) {
throw new RuntimeCamelException("Proxy error: reached end of stream");
}
}
} catch (RuntimeException re) {
closeSocket(socket);
throw re;
} catch (Exception e) {
closeSocket(socket);
throw new RuntimeException("SmppConnectionFactory: " + e.getMessage());
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class TransactionalClientDataSourceWithOnExceptionTest method testTransactionRollback.
public void testTransactionRollback() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:error");
mock.expectedMessageCount(1);
try {
template.sendBody("direct:fail", "Hello World");
fail("Should have thrown exception");
} catch (RuntimeCamelException e) {
// expected as we fail
assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
assertEquals("We don't have Donkeys, only Camels", e.getCause().getCause().getMessage());
}
assertMockEndpointsSatisfied();
int count = jdbc.queryForObject("select count(*) from books", Integer.class);
assertEquals("Number of books", 1, count);
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class TransactionalClientDataSourceAsyncTest method testTransactionRollback.
public void testTransactionRollback() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:error");
mock.expectedMessageCount(1);
try {
template.sendBody("direct:fail", "Hello World");
fail("Should have thrown exception");
} catch (RuntimeCamelException e) {
// expected as we fail
assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
assertEquals("We don't have Donkeys, only Camels", e.getCause().getCause().getMessage());
}
assertMockEndpointsSatisfied();
int count = jdbc.queryForObject("select count(*) from books", Integer.class);
assertEquals("Number of books", 1, count);
}
Aggregations