Refine search
public <T> T evaluate(Exchange exchange, Class<T> tClass) { try { Expression expression = parseExpression(); EvaluationContext evaluationContext = createEvaluationContext(exchange); Object value = expression.getValue(evaluationContext); // Let Camel handle the type conversion return exchange.getContext().getTypeConverter().convertTo(tClass, value); } catch (Exception e) { throw new ExpressionEvaluationException(this, exchange, e); } }
@Override public T onRdd(JavaRDDLike rdd, Object... payloads) { if (payloads.length != payloadsTypes.length) { String message = format("Received %d payloads, but expected %d.", payloads.length, payloadsTypes.length); throw new IllegalArgumentException(message); } for (int i = 0; i < payloads.length; i++) { payloads[i] = camelContext.getTypeConverter().convertTo(payloadsTypes[i], payloads[i]); } return doOnRdd(rdd, payloads); }
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { byte[] bytes = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, graph); String body = reverseBytes(bytes); stream.write(body.getBytes()); }
private static String asString(Exchange exchange, Object value) { return exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value); }
@SuppressWarnings("rawtypes") private List<DBObject> attemptConvertToList(List insertList, Exchange exchange) throws CamelMongoDbException { List<DBObject> dbObjectList = new ArrayList<>(insertList.size()); TypeConverter converter = exchange.getContext().getTypeConverter(); for (Object item : insertList) { try { DBObject dbObject = converter.mandatoryConvertTo(DBObject.class, item); dbObjectList.add(dbObject); } catch (Exception e) { throw new CamelMongoDbException("MongoDB operation = insert, Assuming List variant of MongoDB insert operation, but List contains non-DBObject items", e); } } return dbObjectList; }
/** * Extract an Exception from the exchange. This method will always return a * * @param exchange the Camel exchange * @return an exception */ public Exception extractException(Exchange exchange) { Exception e = exchange.getException(); if (e == null || convertExceptions) { e = context.getTypeConverter().convertTo(FaultException.class, exchange); } return e; }
private OutputStream resolveStreamFromHeader(Object o, Exchange exchange) throws CamelExchangeException { return exchange.getContext().getTypeConverter().convertTo(OutputStream.class, o); }
protected static boolean hasParameter(String nextParam, Exchange exchange, Object body) { Map<?, ?> bodyMap = safeMap(exchange.getContext().getTypeConverter().tryConvertTo(Map.class, body)); Map<?, ?> headersMap = safeMap(exchange.getIn().getHeaders()); if ((nextParam.startsWith("$simple{") || nextParam.startsWith("${")) && nextParam.endsWith("}")) { return true; } else if (bodyMap.containsKey(nextParam)) { return true; } else if (headersMap.containsKey(nextParam)) { return true; } return false; }
public TwitterTimelineEndpoint(String uri, String remaining, String user, TwitterTimelineComponent component, TwitterConfiguration properties) { super(uri, component, properties); if (remaining == null) { throw new IllegalArgumentException(String.format("The timeline type must be specified for '%s'", uri)); } this.timelineType = component.getCamelContext().getTypeConverter().convertTo(TimelineType.class, remaining); this.user = user; }
@Override public <T> T evaluate(Exchange exchange, Class<T> type) { Object result = evaluate(exchange); return exchange.getContext().getTypeConverter().convertTo(type, exchange, result); } }
/** * Attempts to convert the object to the same type as the serialized class specified */ protected Object tryConvertToSerializedType(Exchange exchange, Object object, String serializerClass) { Object answer = null; if (KafkaConstants.KAFKA_DEFAULT_SERIALIZER.equals(serializerClass)) { answer = exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange, object); } else if ("org.apache.kafka.common.serialization.ByteArraySerializer".equals(serializerClass)) { answer = exchange.getContext().getTypeConverter().tryConvertTo(byte[].class, exchange, object); } else if ("org.apache.kafka.common.serialization.ByteBufferSerializer".equals(serializerClass)) { answer = exchange.getContext().getTypeConverter().tryConvertTo(ByteBuffer.class, exchange, object); } else if ("org.apache.kafka.common.serialization.BytesSerializer".equals(serializerClass)) { // we need to convert to byte array first byte[] array = exchange.getContext().getTypeConverter().tryConvertTo(byte[].class, exchange, object); if (array != null) { answer = new Bytes(array); } } return answer != null ? answer : object; }
public TwitterStreamingEndpoint(String uri, String remaining, String keywords, TwitterStreamingComponent component, TwitterConfiguration properties) { super(uri, component, properties); if (remaining == null) { throw new IllegalArgumentException(String.format("The streaming type must be specified for '%s'", uri)); } this.streamingType = component.getCamelContext().getTypeConverter().convertTo(StreamingType.class, remaining); this.keywords = keywords; }
@Override public <T> T evaluate(Exchange exchange, Class<T> type) { Object result = evaluate(exchange); return exchange.getContext().getTypeConverter().convertTo(type, exchange, result); } }
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { byte[] bytes = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, stream); String body = reverseBytes(bytes); return body; }
@Override public Object onRdd(JavaRDDLike rdd, Object... payloads) { try { List<Object> arguments = new ArrayList<>(payloads.length + 1); arguments.add(rdd); arguments.addAll(asList(payloads)); if (arguments.get(1) == null) { arguments.remove(1); } Method callbackMethod = rddCallbacks.get(0); callbackMethod.setAccessible(true); if (camelContext != null) { for (int i = 1; i < arguments.size(); i++) { arguments.set(i, camelContext.getTypeConverter().convertTo(callbackMethod.getParameterTypes()[i], arguments.get(i))); } } return callbackMethod.invoke(objectWithCallback, arguments.toArray(new Object[arguments.size()])); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }
@Override public <T> T evaluate(Exchange exchange, Class<T> type) { Object result = evaluate(exchange); return exchange.getContext().getTypeConverter().convertTo(type, exchange, result); }
private void doRun(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception { Object job = exchange.getIn().getBody(); if (Collection.class.isAssignableFrom(job.getClass())) { Collection<?> col = (Collection<?>) job; TypeConverter tc = exchange.getContext().getTypeConverter(); Collection<IgniteRunnable> runnables = new ArrayList<>(col.size()); for (Object o : col) { runnables.add(tc.mandatoryConvertTo(IgniteRunnable.class, o)); } compute.run(runnables); } else if (IgniteRunnable.class.isAssignableFrom(job.getClass())) { compute.run((IgniteRunnable) job); } else { throw new RuntimeCamelException(String.format( "Ignite Compute endpoint with RUN executionType is only " + "supported for IgniteRunnable payloads, or collections of them. The payload type was: %s.", job.getClass().getName())); } }
private GeoApiContext.Builder configureProxyAuth(GeoApiContext.Builder builder) { AuthenticationMethod auth = getCamelContext().getTypeConverter().convertTo(AuthenticationMethod.class, proxyAuthMethod); if (auth == AuthenticationMethod.Basic || auth == AuthenticationMethod.Digest) { builder = builder.proxyAuthentication(proxyAuthUsername, proxyAuthPassword); } else { throw new IllegalArgumentException("Unknown proxyAuthMethod " + proxyAuthMethod); } return builder; }
@Override public <T> T evaluate(Exchange exchange, Class<T> type) { Object result = ClosureSupport.call(closure, exchange); return exchange.getContext().getTypeConverter().convertTo(type, result); }
private Function<Exchange, Object> createDoCount() { return exchange -> { BasicDBObject query = exchange.getContext().getTypeConverter().tryConvertTo(BasicDBObject.class, exchange, exchange.getIn().getBody()); if (query == null) { query = new BasicDBObject(); } return (Long) calculateCollection(exchange).count(query); }; }