Refine search
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); }
public void process(Exchange exchange) throws Exception { Command<?> cmd = exchange.getIn().getBody( Command.class ); throw new RuntimeCamelException( "Body of in message not of the expected type 'org.drools.command.Command' for uri" + de.getEndpointUri() ); ExecutionNodePipelineContextImpl droolsContext = exchange.getProperty( "drools-context", ExecutionNodePipelineContextImpl.class ); if ( droolsContext != null ) { exec = de.getExecutor(); if ( exec == null ) { String lookup = exchange.getIn().getHeader( DroolsComponent.DROOLS_LOOKUP, String.class ); if ( StringUtils.isEmpty( lookup ) && (cmd instanceof BatchExecutionCommandImpl) ) { exchange.getOut().setBody( results );
private Message getNextElement() { if (asn1InputStream == null) { return null; } try { ASN1Primitive current = getNextEntry(); if (current != null) { Message answer = new DefaultMessage(exchange.getContext()); answer.getHeaders().putAll(exchange.getIn().getHeaders()); answer.setBody(current.getEncoded()); return answer; } else { LOGGER.trace("close asn1InputStream"); return null; } } catch (IOException exception) { //Just wrap the IOException as CamelRuntimeException throw new RuntimeCamelException(exception); } }
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())); } }
dataformat, parameters, false); } catch (Exception e) { throw new RuntimeCamelException(e); if (ObjectHelper.isNotEmpty(customizers)) { for (DataFormatCustomizer<ZipDataFormat> customizer : customizers) { boolean useCustomizer = (customizer instanceof HasId)
/** * Define how the message should be processed. * * @param exchange the current camel message exchange */ public void process(final Exchange exchange) throws IOException { final Message in = exchange.getIn(); final CamelContext ctx = exchange.getContext(); final StringBuilder key = new StringBuilder("/buckets/"); try { final String prefix = ctx.resolvePropertyPlaceholders("{{riak.bucket}}"); key.append(prefix); } catch (final Exception ex) { throw new RuntimeCamelException("Could not resolve properties", ex); } key.append("/keys/"); key.append(URLEncoder.encode( in.getHeader(FcrepoHeaders.FCREPO_IDENTIFIER, String.class), "UTF-8")); in.removeHeader(Exchange.HTTP_URL); in.setHeader(Exchange.HTTP_PATH, key.toString()); } }
exchange.getIn().getBody(); exchange.getIn().getHeaders(); LOG.trace("Processing exchange {} synchronously", exchange.getExchangeId()); rce = wrapRuntimeCamelException(e); LOG.trace("onMessage END throwing exception: {}", rce.getMessage());
private boolean processInBody(Exchange exchange, Map<String, Object> properties) { final String inBodyProperty = endpoint.getInBody(); if (inBodyProperty != null) { Object value = exchange.getIn().getBody(); try { value = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo( FacebookEndpointConfiguration.class.getDeclaredField(inBodyProperty).getType(), exchange, value); } catch (Exception e) { exchange.setException(new RuntimeCamelException(String.format( "Error converting value %s to property %s: %s", value, inBodyProperty, e.getMessage()), e)); return false; } LOG.debug("Property [{}] has message body value {}", inBodyProperty, value); properties.put(inBodyProperty, value); } return true; }
@Override public Exchange call() throws Exception { if (client == null) { throw new RuntimeCamelException("Beanstalk client not initialized"); exchange.getIn().setHeader(Headers.JOB_ID, job.getJobId()); exchange.getIn().setBody(job.getData(), byte[].class); for (String key : STATS_KEY_STR) { if (jobStats.containsKey(key)) { exchange.getIn().setHeader(Headers.PREFIX + key, jobStats.get(key).trim());
exchange.getIn().getHeaders().putAll(jmsHeaders); return exchange.getIn().getBody(); } else { return objectMessage.getObject(); throw new RuntimeCamelException("Failed to extract body due to: " + e + ". Message: " + message, e);
Message message = exchange.getOut(); message.setBody(body); message.setHeader(name, value); message.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode); message.setHeader(Exchange.HTTP_RESPONSE_TEXT, method.getStatusText()); throw new RuntimeCamelException(e); } finally { method.releaseConnection();
public void publish() throws IOException { AMQP.BasicProperties properties; byte[] body; try { // To maintain backwards compatibility try the TypeConverter (The DefaultTypeConverter seems to only work on Strings) body = camelExchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, camelExchange, message.getBody()); properties = endpoint.getMessageConverter().buildProperties(camelExchange).build(); } catch (NoTypeConversionAvailableException | TypeConversionException e) { if (message.getBody() instanceof Serializable) { // Add the header so the reply processor knows to de-serialize it message.getHeaders().put(RabbitMQEndpoint.SERIALIZE_HEADER, true); properties = endpoint.getMessageConverter().buildProperties(camelExchange).build(); body = serializeBodyFrom(message); } else if (message.getBody() == null) { properties = endpoint.getMessageConverter().buildProperties(camelExchange).build(); body = null; } else { LOG.warn("Cannot convert {} to byte[]", message.getBody()); throw new RuntimeCamelException(e); } } publishToRabbitMQ(properties, body); }
@SuppressWarnings("unchecked") private void doPut(Message in, Message out) { Map<Object, Object> map = in.getBody(Map.class); if (map != null) { cache.putAll(map); return; } Object cacheKey = in.getHeader(IgniteConstants.IGNITE_CACHE_KEY); if (cacheKey == null) { throw new RuntimeCamelException("Cache PUT operation requires the cache key in the CamelIgniteCacheKey header, " + "or a payload of type Map."); } cache.put(cacheKey, in.getBody()); IgniteHelper.maybePropagateIncomingBody(endpoint, in, out); }
private Message getInMessage(final Exchange exchange) { final Message in = exchange.getIn(); if (in == null) { throw new RuntimeCamelException("Unexpected exchange: in is null!"); } return in; }
@Override public Object evaluate(Exchange exchange) { // must use getAttachments to ensure attachments is initial populated if (exchange.getIn().getAttachments().isEmpty()) { return null; } try { List<Message> answer = new ArrayList<>(); Message inMessage = exchange.getIn(); for (Map.Entry<String, Attachment> entry : inMessage.getAttachmentObjects().entrySet()) { Message attachmentMessage; if (extractAttachments) { attachmentMessage = extractAttachment(inMessage, entry.getKey()); } else { attachmentMessage = splitAttachment(inMessage, entry.getKey(), entry.getValue()); } if (attachmentMessage != null) { answer.add(attachmentMessage); } } return answer; } catch (Exception e) { throw new RuntimeCamelException("Unable to split attachments from MimeMultipart message", e); } }
@Override public void customize(ComponentProxyComponent component, Map<String, Object> options) { final List<Processor> beforeConsumers = new ArrayList<>(); beforeConsumers.add(e -> e.getIn().removeHeader(Exchange.HTTP_URI)); if (outputDataShape != null && outputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA && outputDataShape.getSpecification() != null) { try { final JsonNode schema = READER.readTree(outputDataShape.getSpecification()); if (Optional.of(SCHEMA_ID).equals(SimpleJsonSchemaInspector.getId(schema))) { Set<String> properties = SimpleJsonSchemaInspector.getProperties(schema); // check that the schema contains the right properties if (!properties.contains("parameters")) { throw new IllegalArgumentException("JsonSchema does not define parameters property"); } if (!properties.contains("body")) { throw new IllegalArgumentException("JsonSchema does not define body property"); } beforeConsumers.add(new HttpRequestWrapperProcessor(schema)); } } catch (IOException e) { throw new RuntimeCamelException(e); } } component.setBeforeConsumer(Pipeline.newInstance(camelContext, beforeConsumers)); // Unconditionally we remove output in 7.1 release component.setAfterConsumer(this::removeOutput); }
@Override public void customize(ComponentProxyComponent component, Map<String, Object> options) { final List<Processor> beforeConsumers = new ArrayList<>(2); if (outputDataShape != null && outputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA && outputDataShape.getSpecification() != null) { try { final JsonNode schema = READER.readTree(outputDataShape.getSpecification()); Set<String> properties = SimpleJsonSchemaInspector.getProperties(schema); Set<String> extraneousProperties = new HashSet<>(properties); extraneousProperties.removeAll(Arrays.asList("parameters", "body")); if (!properties.isEmpty() && extraneousProperties.isEmpty()) { beforeConsumers.add(new HttpRequestWrapperProcessor(schema)); } } catch (IOException e) { throw new RuntimeCamelException(e); } } // removes all non Syndesis.* headers, this is so the headers that might // influence HTTP components in the flow after this connector don't // interpret them, for instance the `Host` header is particularly // troublesome beforeConsumers.add((e) -> e.getIn().removeHeaders("*", "Syndesis.*")); component.setBeforeConsumer(Pipeline.newInstance(context, beforeConsumers)); }
HazelcastMQMessage mqMsg = new HazelcastMQMessage(); Map<String, Object> camelHeaders = camelMsg.getHeaders(); Object camelBody = camelMsg.getBody(); if (camelBody instanceof String) { mqMsg.setBody((String) camelBody); throw new RuntimeCamelException(format( "Unsupported message body type: %s", camelBody.getClass().getName()));
private byte[] serializeBodyFrom(final Message msg) throws IOException { try (ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(b)) { o.writeObject(msg.getBody()); return b.toByteArray(); } catch (NotSerializableException nse) { LOG.warn("Cannot send object {} via RabbitMQ because it contains non-serializable objects.", msg.getBody().getClass()); throw new RuntimeCamelException(nse); } } }
@Override public ZooKeeperServiceRegistryConfiguration copy() { try { return (ZooKeeperServiceRegistryConfiguration)super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeCamelException(e); } } }