use of org.apache.camel.RuntimeExchangeException in project camel by apache.
the class XmppPubSubProducer method process.
public void process(Exchange exchange) throws Exception {
try {
if (connection == null) {
connection = endpoint.createConnection();
}
// make sure we are connected
if (!connection.isConnected()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Reconnecting to: " + XmppEndpoint.getConnectionMessage(connection));
}
connection.connect();
}
} catch (XMPPException e) {
throw new RuntimeExchangeException("Cannot connect to XMPP Server: " + ((connection != null) ? XmppEndpoint.getConnectionMessage(connection) : endpoint.getHost()), exchange, e);
}
try {
Object body = exchange.getIn().getBody(Object.class);
if (body instanceof PubSub) {
PubSub pubsubpacket = (PubSub) body;
endpoint.getBinding().populateXmppPacket(pubsubpacket, exchange);
exchange.getIn().setHeader(XmppConstants.DOC_HEADER, pubsubpacket);
connection.sendPacket(pubsubpacket);
} else {
throw new Exception("Message does not contain a pubsub packet");
}
} catch (XMPPException xmppe) {
throw new RuntimeExchangeException("Cannot send XMPP pubsub: from " + endpoint.getUser() + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot send XMPP pubsub: from " + endpoint.getUser() + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, e);
}
}
use of org.apache.camel.RuntimeExchangeException in project camel by apache.
the class NettyHttpHelper method createURL.
/**
* Creates the URL to invoke.
*
* @param exchange the exchange
* @param endpoint the endpoint
* @return the URL to invoke
*/
public static String createURL(Exchange exchange, NettyHttpEndpoint endpoint) throws URISyntaxException {
// rest producer may provide an override url to be used which we should discard if using (hence the remove)
String uri = (String) exchange.getIn().removeHeader(Exchange.REST_HTTP_URI);
if (uri == null) {
uri = endpoint.getEndpointUri();
}
// resolve placeholders in uri
try {
uri = exchange.getContext().resolvePropertyPlaceholders(uri);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
}
// append HTTP_PATH to HTTP_URI if it is provided in the header
String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
// NOW the HTTP_PATH is just related path, we don't need to trim it
if (path != null) {
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.length() > 0) {
// inject the dynamic path before the query params, if there are any
int idx = uri.indexOf("?");
// if there are no query params
if (idx == -1) {
// make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
uri = uri.endsWith("/") ? uri : uri + "/";
uri = uri.concat(path);
} else {
// there are query params, so inject the relative path in the right place
String base = uri.substring(0, idx);
base = base.endsWith("/") ? base : base + "/";
base = base.concat(path);
uri = base.concat(uri.substring(idx));
}
}
}
// ensure uri is encoded to be valid
uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);
return uri;
}
use of org.apache.camel.RuntimeExchangeException in project camel by apache.
the class HttpHelper method createURL.
/**
* Creates the URL to invoke.
*
* @param exchange the exchange
* @param endpoint the endpoint
* @return the URL to invoke
*/
public static String createURL(Exchange exchange, HttpCommonEndpoint endpoint) {
// rest producer may provide an override url to be used which we should discard if using (hence the remove)
String uri = (String) exchange.getIn().removeHeader(Exchange.REST_HTTP_URI);
if (uri == null && !(endpoint.isBridgeEndpoint())) {
uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
}
if (uri == null) {
uri = endpoint.getHttpUri().toASCIIString();
}
// resolve placeholders in uri
try {
uri = exchange.getContext().resolvePropertyPlaceholders(uri);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
}
// append HTTP_PATH to HTTP_URI if it is provided in the header
String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
// NOW the HTTP_PATH is just related path, we don't need to trim it
if (path != null) {
if (path.length() > 1 && path.startsWith("/")) {
path = path.substring(1);
}
if (path.length() > 0) {
// inject the dynamic path before the query params, if there are any
int idx = uri.indexOf("?");
// if there are no query params
if (idx == -1) {
// make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
uri = uri.endsWith("/") || path.startsWith("/") ? uri : uri + "/";
uri = uri.concat(path);
} else {
// there are query params, so inject the relative path in the right place
String base = uri.substring(0, idx);
base = base.endsWith("/") ? base : base + "/";
base = base.concat(path);
uri = base.concat(uri.substring(idx));
}
}
}
// ensure uri is encoded to be valid
uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);
return uri;
}
use of org.apache.camel.RuntimeExchangeException in project camel by apache.
the class CMISProducerTest method failCreatingFolderAtNonExistingPath.
@Test
public void failCreatingFolderAtNonExistingPath() throws Exception {
String existingFolderStructure = "/No/Path/Here";
Exchange exchange = createExchangeWithInBody(null);
exchange.getIn().getHeaders().put(PropertyIds.NAME, "folder1");
exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
template.send(exchange);
assertTrue(exchange.getException() instanceof RuntimeExchangeException);
}
use of org.apache.camel.RuntimeExchangeException in project camel by apache.
the class AhcHelper method doCreateURL.
private static String doCreateURL(Exchange exchange, AhcEndpoint endpoint) {
String uri = null;
if (!(endpoint.isBridgeEndpoint())) {
uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
}
if (uri == null) {
uri = endpoint.getHttpUri().toASCIIString();
}
// resolve placeholders in uri
try {
uri = exchange.getContext().resolvePropertyPlaceholders(uri);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
}
// append HTTP_PATH to HTTP_URI if it is provided in the header
String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
if (path != null) {
if (path.startsWith("/")) {
URI baseURI;
String baseURIString = exchange.getIn().getHeader(Exchange.HTTP_BASE_URI, String.class);
try {
if (baseURIString == null) {
if (exchange.getFromEndpoint() != null) {
baseURIString = exchange.getFromEndpoint().getEndpointUri();
} else {
// will set a default one for it
baseURIString = "/";
}
}
baseURI = new URI(baseURIString);
String basePath = baseURI.getPath();
if (path.startsWith(basePath)) {
path = path.substring(basePath.length());
if (path.startsWith("/")) {
path = path.substring(1);
}
} else {
throw new RuntimeExchangeException("Cannot analyze the Exchange.HTTP_PATH header, due to: cannot find the right HTTP_BASE_URI", exchange);
}
} catch (Throwable t) {
throw new RuntimeExchangeException("Cannot analyze the Exchange.HTTP_PATH header, due to: " + t.getMessage(), exchange, t);
}
}
if (path.length() > 0) {
// HTTP_PATH
if (!uri.endsWith("/")) {
uri = uri + "/";
}
uri = uri.concat(path);
}
}
// ensure uri is encoded to be valid
uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);
return uri;
}
Aggregations