use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class IgniteComputeProducer method doCall.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void doCall(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
Object job = exchange.getIn().getBody();
IgniteReducer<Object, Object> reducer = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_REDUCER, IgniteReducer.class);
if (Collection.class.isAssignableFrom(job.getClass())) {
Collection<?> col = (Collection<?>) job;
TypeConverter tc = exchange.getContext().getTypeConverter();
Collection<IgniteCallable<?>> callables = new ArrayList<>(col.size());
for (Object o : col) {
callables.add(tc.mandatoryConvertTo(IgniteCallable.class, o));
}
if (reducer != null) {
compute.call((Collection) callables, reducer);
} else {
compute.call((Collection) callables);
}
} else if (IgniteCallable.class.isAssignableFrom(job.getClass())) {
compute.call((IgniteCallable<Object>) job);
} else {
throw new RuntimeCamelException(String.format("Ignite Compute endpoint with CALL executionType is only " + "supported for IgniteCallable payloads, or collections of them. The payload type was: %s.", job.getClass().getName()));
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class IgniteComputeProducer method doAffinityRun.
private void doAffinityRun(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
IgniteRunnable job = exchange.getIn().getBody(IgniteRunnable.class);
String affinityCache = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_AFFINITY_CACHE_NAME, String.class);
Object affinityKey = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_AFFINITY_KEY, Object.class);
if (job == null || affinityCache == null || affinityKey == null) {
throw new RuntimeCamelException(String.format("Ignite Compute endpoint with AFFINITY_RUN executionType is only " + "supported for IgniteRunnable payloads, along with an affinity cache and key. The payload type was: %s.", exchange.getIn().getBody().getClass().getName()));
}
compute.affinityRun(affinityCache, affinityKey, job);
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class CamelSSLIRCConnection method connect.
@Override
public void connect() throws IOException {
if (sslContextParameters == null) {
super.connect();
} else {
if (level != 0) {
throw new SocketException("Socket closed or already open (" + level + ")");
}
IOException exception = null;
final SSLContext sslContext;
try {
sslContext = sslContextParameters.createSSLContext(camelContext);
} catch (GeneralSecurityException e) {
throw new RuntimeCamelException("Error in SSLContextParameters configuration or instantiation.", e);
}
final SSLSocketFactory sf = sslContext.getSocketFactory();
SSLSocket s = null;
for (int i = 0; i < ports.length && s == null; i++) {
try {
s = (SSLSocket) sf.createSocket(host, ports[i]);
s.startHandshake();
exception = null;
} catch (SSLNotSupportedException exc) {
if (s != null) {
s.close();
}
s = null;
throw exc;
} catch (IOException exc) {
if (s != null) {
s.close();
}
s = null;
exception = exc;
}
}
if (exception != null) {
// connection wasn't successful at any port
throw exception;
}
prepare(s);
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class IrcConfiguration method sanitize.
@Deprecated
public static String sanitize(String uri) {
// may be removed in camel-3.0.0
// make sure it's an URL first
int colon = uri.indexOf(':');
if (colon != -1 && uri.indexOf("://") != colon) {
uri = uri.substring(0, colon) + "://" + uri.substring(colon + 1);
}
try {
URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
String[] userInfo = u.getUserInfo() != null ? u.getUserInfo().split(":") : null;
String username = userInfo != null ? userInfo[0] : null;
String password = userInfo != null && userInfo.length > 1 ? userInfo[1] : null;
String path = URLDecoder.decode(u.getPath() != null ? u.getPath() : "", "UTF-8");
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.startsWith("#") && !path.startsWith("##")) {
path = path.substring(1);
}
Map<String, Object> parameters = URISupport.parseParameters(u);
String user = (String) parameters.get("username");
String nick = (String) parameters.get("nickname");
// not specified in authority
if (user != null) {
if (username == null) {
username = user;
} else if (!username.equals(user)) {
LOG.warn("Username specified twice in endpoint URI with different values. " + "The userInfo value ('{}') will be used, paramter ('{}') ignored", username, user);
}
parameters.remove("username");
}
if (nick != null) {
if (username == null) {
username = nick;
}
if (username.equals(nick)) {
// redundant
parameters.remove("nickname");
}
}
if (username == null) {
throw new RuntimeCamelException("IrcEndpoint URI with no user/nick specified is invalid");
}
String pwd = (String) parameters.get("password");
if (pwd != null) {
password = pwd;
parameters.remove("password");
}
// Remove unneeded '#' channel prefixes per convention
// and replace ',' separators and merge channel and key using convention "channel!key"
List<String> cl = new ArrayList<String>();
String channels = (String) parameters.get("channels");
String keys = (String) parameters.get("keys");
// if @keys ends with a ',' it will miss the last empty key after split(",")
keys = keys == null ? keys : keys + " ";
if (channels != null) {
String[] chs = channels.split(",");
String[] ks = keys != null ? keys.split(",") : null;
parameters.remove("channels");
int count = chs.length;
if (ks != null) {
parameters.remove("keys");
if (!path.isEmpty()) {
LOG.warn("Specifying a channel '{}' in the URI path is ambiguous" + " when @channels and @keys are provided and will be ignored", path);
path = "";
}
if (ks.length != chs.length) {
count = count < ks.length ? count : ks.length;
LOG.warn("Different count of @channels and @keys. Only the first {} are used.", count);
}
}
for (int i = 0; i < count; i++) {
String channel = chs[i].trim();
String key = ks != null ? ks[i].trim() : null;
if (channel.startsWith("#") && !channel.startsWith("##")) {
channel = channel.substring(1);
}
if (key != null && !key.isEmpty()) {
channel += "!" + key;
}
cl.add(channel);
}
} else {
if (path.isEmpty()) {
LOG.warn("No channel specified for the irc endpoint");
}
cl.add(path);
}
parameters.put("channel", cl);
StringBuilder sb = new StringBuilder();
sb.append(u.getScheme());
sb.append("://");
sb.append(username);
sb.append(password == null ? "" : ":" + password);
sb.append("@");
sb.append(u.getHost());
sb.append(u.getPort() == -1 ? "" : ":" + u.getPort());
// ignore the path we have it as a @channel now
String query = formatQuery(parameters);
if (!query.isEmpty()) {
sb.append("?");
sb.append(query);
}
// make things a bit more predictable
return sb.toString();
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
use of org.apache.camel.RuntimeCamelException in project camel by apache.
the class ResultSetIterator method next.
@Override
public Map<String, Object> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
try {
Map<String, Object> row = new LinkedHashMap<String, Object>();
for (Column column : columns) {
if (useGetBytes && column instanceof BlobColumn) {
row.put(column.getName(), ((BlobColumn) column).getBytes(resultSet));
} else {
row.put(column.getName(), column.getValue(resultSet));
}
}
loadNext();
return row;
} catch (SQLException e) {
close();
throw new RuntimeCamelException("Cannot process result", e);
}
}
Aggregations