本文整理了Java中org.switchyard.Message
类的一些代码示例,展示了Message
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message
类的具体详情如下:
包路径:org.switchyard.Message
类名称:Message
[英]A Message represents an individual input or output of a service, the content of which is interpreted by service implementation logic. A Message does not carry context specific to a service invocation, which means that it can be copied and reused across service invocations.
There are two distinct parts to a message:
代码示例来源:origin: jboss-switchyard/core
@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);
}
代码示例来源:origin: org.switchyard.components/switchyard-component-camel-switchyard
/**
* 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;
}
代码示例来源:origin: org.switchyard.components/switchyard-component-bean
/**
* {@inheritDoc}
*/
@Override
public Map<String, DataSource> getAttachmentMap() {
return getMessage().getAttachmentMap();
}
代码示例来源:origin: jboss-switchyard/core
@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"));
}
代码示例来源:origin: org.switchyard/switchyard-test
@Override
public Throwable getCause() {
if (Throwable.class.isAssignableFrom(_faultMessage.getContent().getClass())) {
return _faultMessage.getContent(Throwable.class);
} else {
return super.getCause();
}
}
}
代码示例来源:origin: org.switchyard/switchyard-transform
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());
代码示例来源:origin: org.switchyard.components/switchyard-component-camel-switchyard
/**
* 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;
}
代码示例来源:origin: org.switchyard.components/switchyard-component-bean
/**
* {@inheritDoc}
*/
@Override
public Message setContent(Object content) {
return getMessage().setContent(content);
}
代码示例来源:origin: org.switchyard.components/switchyard-component-common-camel
message.setContent(content);
message.addAttachment(entry.getKey(), entry.getValue().getDataSource());
代码示例来源:origin: org.switchyard.components/switchyard-component-bean
/**
* {@inheritDoc}
*/
@Override
public Context getContext() {
return getMessage().getContext();
}
代码示例来源:origin: org.switchyard.components/switchyard-component-common-camel
/**
* {@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;
}
}
代码示例来源:origin: org.switchyard/switchyard-test
@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;
}
}
代码示例来源:origin: jboss-switchyard/core
@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"));
}
代码示例来源:origin: org.switchyard.components/switchyard-component-sca
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);
代码示例来源:origin: jboss-switchyard/core
@Test
public void testAddAttachment() throws Exception {
_message.addAttachment("attach1", new DummyDS("attach1", "text/xml"));
Assert.assertNotNull(_message.getAttachment("attach1"));
}
代码示例来源:origin: org.switchyard/switchyard-test
private void addAttachments(Message message) {
for (Map.Entry<String, DataSource> entry : _attachments.entrySet()) {
message.addAttachment(entry.getKey(), entry.getValue());
}
}
代码示例来源:origin: org.switchyard.components/switchyard-component-bean
/**
* {@inheritDoc}
*/
@Override
public Message copy() {
return getMessage().copy();
}
代码示例来源:origin: jboss-switchyard/core
@Override
public Throwable getCause() {
if (Throwable.class.isAssignableFrom(_faultMessage.getContent().getClass())) {
return _faultMessage.getContent(Throwable.class);
} else {
return super.getCause();
}
}
}
代码示例来源:origin: jboss-switchyard/core
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);
代码示例来源:origin: org.switchyard.components/switchyard-component-soap
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);
内容来源于网络,如有侵权,请联系作者删除!