/** * Gets an Object context property. * @param exchange the exchange * @param message the message * @param name the name * @return the property */ protected Object getObject(Exchange exchange, Message message, String name) { Context context = message != null ? exchange.getContext(message) : exchange.getContext(); return context.getPropertyValue(name); }
@Override public ReferenceInvocation setProperty(String name, String value) { _exchange.getContext(_inMessage).setProperty(name, value); return this; }
@Override public ReferenceInvocation setProperty(String name, String value) { _exchange.getContext(_inMessage).setProperty(name, value); return this; }
@Override public Object getProperty(String name) { return _exchange.getContext().getPropertyValue(name); }
@SuppressWarnings("unchecked") private static Set<Policy> getPolicies(Exchange exchange, String propertyName) { Property intentsProperty = exchange.getContext().getProperty(propertyName, Scope.EXCHANGE); Set<Policy> intents = new HashSet<Policy>(); if (intentsProperty != null) { intents.addAll((Set<Policy>)intentsProperty.getValue()); } return intents; }
@SuppressWarnings("unchecked") private static Set<Policy> getPolicies(Exchange exchange, String propertyName) { Property intentsProperty = exchange.getContext().getProperty(propertyName, Scope.EXCHANGE); Set<Policy> intents = new HashSet<Policy>(); if (intentsProperty != null) { intents.addAll((Set<Policy>)intentsProperty.getValue()); } return intents; }
private static TransformSequence get(final Exchange exchange) { Property sequenceProperty = exchange.getContext().getProperty(TransformSequence.class.getName()); if (sequenceProperty != null) { return (TransformSequence)sequenceProperty.getValue(); } else { return null; } } }
private static TransformSequence get(final Exchange exchange) { Property sequenceProperty = exchange.getContext().getProperty(TransformSequence.class.getName()); if (sequenceProperty != null) { return (TransformSequence)sequenceProperty.getValue(); } else { return null; } } }
private void setContentType(Exchange exchange) { QName currentType = TransformSequence.getCurrentMessageType(exchange); if (currentType != null) { exchange.getContext().setProperty(Exchange.CONTENT_TYPE, currentType).addLabels(BehaviorLabel.TRANSIENT.label()); } else { // make sure no property is used for current scope Property p = exchange.getContext().getProperty(Exchange.CONTENT_TYPE); if (p != null) { exchange.getContext().removeProperty(p); } } }
private void setContentType(Exchange exchange) { QName currentType = TransformSequence.getCurrentMessageType(exchange); if (currentType != null) { exchange.getContext().setProperty(Exchange.CONTENT_TYPE, currentType).addLabels(BehaviorLabel.TRANSIENT.label()); } else { // make sure no property is used for current scope Property p = exchange.getContext().getProperty(Exchange.CONTENT_TYPE); if (p != null) { exchange.getContext().removeProperty(p); } } }
@Override public void recordMetrics(Exchange exchange) { final String gatewayName = exchange.getContext().getPropertyValue(ExchangeCompletionEvent.GATEWAY_NAME); if (gatewayName != null && _gateways.containsKey(gatewayName)) { _gateways.get(gatewayName).recordMetrics(exchange); } _promotedService.recordMetrics(exchange); } }
private void mapContext(Exchange exchange, Message camelMessage) throws Exception { Message camelMsg; if (_messageComposer != null) { camelMsg = getCamelMessage(); _messageComposer.getContextMapper().mapTo(exchange.getContext(), new CamelBindingData(camelMsg)); } else { ExchangeMapper.mapSwitchYardPropertiesToCamel(exchange.getContext(), _camelExchange, camelMessage); } } }
/** * Indicate that a given policy is required for the exchange. * @param exchange require policy on this exchange * @param policy the policy to require */ public static void require(Exchange exchange, Policy policy) { Set<Policy> required = getPolicies(exchange, REQUIRED_PROPERTY); required.add(policy); exchange.getContext().setProperty(REQUIRED_PROPERTY, required, Scope.EXCHANGE).addLabels(BehaviorLabel.TRANSIENT.label()); }
/** * Indicate that a given policy is satisfied for the exchange. * @param exchange assert policy on this exchange * @param policy the policy to assert */ public static void provide(Exchange exchange, Policy policy) { Set<Policy> provided = getPolicies(exchange, PROVIDED_PROPERTY); provided.add(policy); exchange.getContext().setProperty(PROVIDED_PROPERTY, provided, Scope.EXCHANGE).addLabels(BehaviorLabel.TRANSIENT.label()); }
/** * {@inheritDoc} */ @Override public Message compose(StreamableRecordBindingData source, Exchange exchange) throws Exception { final org.switchyard.Message message = exchange.createMessage(); getContextMapper().mapFrom(source, exchange.getContext(message)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); source.getRecord().write(baos); message.setContent(new ByteArrayInputStream(baos.toByteArray())); return message; }
/** * {@inheritDoc} */ @Override public org.switchyard.Message compose(MappedRecordBindingData source, Exchange exchange) throws Exception { final org.switchyard.Message message = exchange.createMessage(); getContextMapper().mapFrom(source, exchange.getContext(message)); Map<Object,Object> m = new HashMap<Object,Object>(); m.putAll(source.getRecord()); message.setContent(m); return message; }
/** * {@inheritDoc} */ @Override public HttpBindingData decompose(Exchange exchange, HttpBindingData target) throws Exception { Object content = exchange.getMessage().getContent(); if ((content instanceof String) && (content.equals(""))) { exchange.getContext().setProperty(HttpContextMapper.HTTP_RESPONSE_STATUS, 404).addLabels(new String[]{EndpointLabel.HTTP.label()}); } target = super.decompose(exchange, target); return target; }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public IndexedRecordBindingData decompose(Exchange exchange, IndexedRecordBindingData target) throws Exception { Message sourceMessage = exchange.getMessage(); getContextMapper().mapTo(exchange.getContext(), target); final List<?> content = sourceMessage.getContent(List.class); target.getRecord().addAll(content); return target; }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public MappedRecordBindingData decompose(Exchange exchange, MappedRecordBindingData target) throws Exception { Message sourceMessage = exchange.getMessage(); getContextMapper().mapTo(exchange.getContext(), target); final Map<?,?> content = sourceMessage.getContent(Map.class); target.getRecord().putAll(content); return target; }
/** * {@inheritDoc} */ @Override public StreamableRecordBindingData decompose(Exchange exchange, StreamableRecordBindingData target) throws Exception { Message sourceMessage = exchange.getMessage(); getContextMapper().mapTo(exchange.getContext(), target); final InputStream content = sourceMessage.getContent(InputStream.class); target.getRecord().read(content); return target; }