@Test public void testContent() throws Exception { final String message = "Hello There!"; _message.setContent(message); Assert.assertEquals(message, _message.getContent()); // the following tests to make sure casting to same type works String content = _message.getContent(String.class); Assert.assertEquals(message, content); }
/** * Map from a camel exchange to a SwitchYard exchange. * @param camelExchange the camel exchange * @param syExchange the switchyard exchange * @param phase ExchangePhase.IN to target camelExchange.getIn(), ExchangePhase.OUT to * target camelExchange.getIn(). * @return the */ public static org.switchyard.Message mapCamelToSwitchYard( org.apache.camel.Exchange camelExchange, org.switchyard.Exchange syExchange, ExchangePhase phase) { // Associate the correct Camel message with the SY exchange org.switchyard.Message message = syExchange.createMessage(); org.apache.camel.Message camelMessage = mapCamelPropertiesToSwitchYard(camelExchange, message.getContext(), phase); message.setContent(camelMessage.getBody()); for (String attachmentName : camelMessage.getAttachmentNames()) { message.addAttachment(attachmentName, new HandlerDataSource(camelMessage.getAttachment(attachmentName))); } return message; }
/** * {@inheritDoc} */ @Override public Map<String, DataSource> getAttachmentMap() { return getMessage().getAttachmentMap(); }
@Test public void testRemoveAttachment() throws Exception { _message.addAttachment("attach1", new DummyDS("attach1", "text/xml")); Assert.assertNotNull(_message.getAttachment("attach1")); _message.removeAttachment("attach1"); Assert.assertNull(_message.getAttachment("attach1")); }
@Override public Throwable getCause() { if (Throwable.class.isAssignableFrom(_faultMessage.getContent().getClass())) { return _faultMessage.getContent(Throwable.class); } else { return super.getCause(); } } }
exchange.setUnitOfWork(uow); uow.start(); exchange.getIn().setBody(message.getContent()); copyProperties(message.getContext(), exchange); message.setContent(exchange.getIn().getBody(QNameUtil.toJavaMessageType(getTo()))); } else { message.setContent(exchange.getIn().getBody());
/** * Maps a SwitchYard exchange to a Camel exchange. Keep in mind that the camel message created * during mapping is *not* associate with the exchange. You need to call setIn() or setOut() * with the returned reference depending on your use case. * @param syExchange switchyard exchange * @param camelExchange camel exchange * @return mapped camel message */ public static DefaultMessage mapSwitchYardToCamel( org.switchyard.Exchange syExchange, org.apache.camel.Exchange camelExchange) { DefaultMessage camelMessage = new SwitchYardMessage(); camelMessage.setBody(syExchange.getMessage().getContent()); mapSwitchYardPropertiesToCamel(syExchange.getContext(), camelExchange, camelMessage); for (String attachmentName : syExchange.getMessage().getAttachmentMap().keySet()) { camelMessage.addAttachment(attachmentName, new DataHandler(syExchange.getMessage().getAttachment(attachmentName))); } return camelMessage; }
/** * {@inheritDoc} */ @Override public Message setContent(Object content) { return getMessage().setContent(content); }
message.setContent(content); message.addAttachment(entry.getKey(), entry.getValue().getDataSource());
/** * {@inheritDoc} */ @Override public Context getContext() { return getMessage().getContext(); }
/** * {@inheritDoc} */ @Override public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception { Message sourceMessage = exchange.getMessage(); getContextMapper().mapTo(exchange.getContext(), target); org.apache.camel.Message targetMessage = target.getMessage(); if (!sourceMessage.getAttachmentMap().isEmpty()) { for (Entry<String, DataSource> entry : sourceMessage.getAttachmentMap().entrySet()) { targetMessage.addAttachment(entry.getKey(), new DataHandler(entry.getValue())); } } ServiceOperation operation = exchange.getContract().getProviderOperation(); target.getMessage().getExchange().setProperty(OPERATION_NAME, operation.getName()); target.getMessage().getExchange().setProperty(FAULT_TYPE, operation.getFaultType()); target.getMessage().getExchange().setProperty(SERVICE_NAME, exchange.getProvider().getName()); targetMessage.setBody(sourceMessage.getContent()); return target; } }
@Override public void handleMessage(final Exchange exchange) throws HandlerException { _messages.offer(exchange); if (_behavior == null || exchange.getContract().getProviderOperation().getExchangePattern().equals(ExchangePattern.IN_ONLY)) { return; } switch (_behavior) { case FORWARD_IN_TO_OUT : exchange.send(exchange.getMessage().copy()); break; case FORWARD_IN_TO_FAULT : exchange.sendFault(exchange.getMessage().copy()); break; case REPLY_WITH_OUT : exchange.send(exchange.createMessage().setContent(_replyContent)); break; case REPLY_WITH_FAULT : exchange.sendFault(exchange.createMessage().setContent(_replyContent)); break; } }
@Test public void testGetAttachmentMap() throws Exception { _message.addAttachment("attach1", new DummyDS("attach1", "text/xml")); _message.addAttachment("attach2", new DummyDS("attach1", "text/xml")); Map<String, DataSource> attachments = _message.getAttachmentMap(); // make sure the attachments we added are in the map Assert.assertTrue(attachments.containsKey("attach1")); Assert.assertTrue(attachments.containsKey("attach2")); // make sure that modifications to the map are not reflected in the message // (i.e.) the returned map is not a direct reference attachments.remove("attach1"); Assert.assertNotNull(_message.getAttachment("attach1")); }
Message invokeMsg = exchange.getMessage().copy(); exchange.getContext().mergeInto(invokeMsg.getContext()); replyHandler.waitForOut(); if (ex.getMessage() != null) { Message replyMsg = ex.getMessage().copy(); ex.getContext().mergeInto(replyMsg.getContext()); if (ExchangeState.FAULT.equals(ex.getState())) { exchange.sendFault(replyMsg);
@Test public void testAddAttachment() throws Exception { _message.addAttachment("attach1", new DummyDS("attach1", "text/xml")); Assert.assertNotNull(_message.getAttachment("attach1")); }
private void addAttachments(Message message) { for (Map.Entry<String, DataSource> entry : _attachments.entrySet()) { message.addAttachment(entry.getKey(), entry.getValue()); } }
/** * {@inheritDoc} */ @Override public Message copy() { return getMessage().copy(); }
@Override public Throwable getCause() { if (Throwable.class.isAssignableFrom(_faultMessage.getContent().getClass())) { return _faultMessage.getContent(Throwable.class); } else { return super.getCause(); } } }
Message msg = exchange.createMessage().setContent(input); msg.getContext().setProperty(Exchange.CONTENT_TYPE, typeName); msg.setContent(input); Object content = invokerHandler.getFaults().poll().getMessage().getContent(); Assert.assertTrue(content instanceof HandlerException);
if (message.getContent() == null) { throw SOAPMessages.MESSAGES.unableToCreateSOAPBodyDueToNullMessageContent(); if (message.getContent() instanceof SOAPMessage) { return new SOAPBindingData((SOAPMessage)message.getContent()); Node messageNode = message.getContent(Node.class); if (messageNode != null) { Node messageNodeImport = soapMessage.getSOAPBody().getOwnerDocument().importNode(messageNode, true); for (String name : message.getAttachmentMap().keySet()) { AttachmentPart apResponse = soapMessage.createAttachmentPart(); apResponse.setDataHandler(new DataHandler(message.getAttachment(name))); apResponse.setContentId("<" + name + ">"); soapMessage.addAttachmentPart(apResponse); && exchange.getMessage().getContent() instanceof Exception) { throw exchange.getMessage().getContent(Exception.class);