本文整理了Java中javax.jms.Message.getJMSType()
方法的一些代码示例,展示了Message.getJMSType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getJMSType()
方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:getJMSType
[英]Gets the message type identifier supplied by the client when the message was sent.
[中]获取发送消息时客户端提供的消息类型标识符。
代码示例来源:origin: log4j/log4j
public void onMessage(javax.jms.Message message) {
LoggingEvent event;
Logger remoteLogger;
try {
if(message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
event = (LoggingEvent) objectMessage.getObject();
remoteLogger = Logger.getLogger(event.getLoggerName());
remoteLogger.callAppenders(event);
} else {
logger.warn("Received message is of type "+message.getJMSType()
+", was expecting ObjectMessage.");
}
} catch(JMSException jmse) {
logger.error("Exception thrown while processing incoming message.",
jmse);
}
}
代码示例来源:origin: log4j/log4j
sbuf.append(m.getJMSType());
代码示例来源:origin: spring-projects/spring-framework
String type = jmsMessage.getJMSType();
if (type != null) {
headers.put(JmsHeaders.TYPE, type);
代码示例来源:origin: apache/rocketmq-externals
public static byte[] getContentFromJms(javax.jms.Message jmsMessage) throws Exception {
byte[] content;
if (jmsMessage instanceof TextMessage) {
if (StringUtils.isEmpty(((TextMessage) jmsMessage).getText())) {
throw new IllegalArgumentException("Message body length is zero");
}
content = MsgConvertUtil.string2Bytes(((TextMessage) jmsMessage).getText(),
Charsets.UTF_8.toString());
}
else if (jmsMessage instanceof ObjectMessage) {
if (((ObjectMessage) jmsMessage).getObject() == null) {
throw new IllegalArgumentException("Message body length is zero");
}
content = MsgConvertUtil.objectSerialize(((ObjectMessage) jmsMessage).getObject());
}
else if (jmsMessage instanceof BytesMessage) {
JmsBytesMessage bytesMessage = (JmsBytesMessage) jmsMessage;
if (bytesMessage.getBodyLength() == 0) {
throw new IllegalArgumentException("Message body length is zero");
}
content = bytesMessage.getData();
}
else {
throw new IllegalArgumentException("Unknown message type " + jmsMessage.getJMSType());
}
return content;
}
代码示例来源:origin: apache/nifi
private Map<String, String> extractMessageHeaders(final Message message) throws JMSException {
final Map<String, String> messageHeaders = new HashMap<>();
messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration()));
messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority()));
messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered()));
messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID());
messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID());
messageHeaders.put(JmsHeaders.TYPE, message.getJMSType());
String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO);
if (replyToDestinationName != null) {
messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName);
}
String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION);
if (destinationName != null) {
messageHeaders.put(JmsHeaders.DESTINATION, destinationName);
}
return messageHeaders;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void jmsTypeMappedFromHeader() throws JMSException {
String jmsType = "testing";
Message<String> message = initBuilder()
.setHeader(JmsHeaders.TYPE, jmsType).build();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNotNull(jmsMessage.getJMSType());
assertEquals(jmsType, jmsMessage.getJMSType());
}
代码示例来源:origin: apache/nifi
attributes.put(ATTRIBUTE_PREFIX + JMS_REPLY_TO, message.getJMSReplyTo().toString());
if (message.getJMSType() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_TYPE, message.getJMSType());
代码示例来源:origin: spring-projects/spring-framework
@Test
public void jmsTypeIgnoredIfIncorrectType() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.TYPE, 123).build();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void attemptToWriteDisallowedTypePropertyIsNotFatal() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.TYPE, "someType")
.setHeader("foo", "bar")
.build();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSType(String type) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSType());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源:origin: wildfly/wildfly
setJMSExpiration(foreign.getJMSExpiration());
setJMSPriority(foreign.getJMSPriority());
setJMSType(foreign.getJMSType());
代码示例来源:origin: spring-projects/spring-framework
@Test
public void buildMessageWithStandardMessage() throws JMSException {
Destination replyTo = new Destination() {};
Message<String> result = MessageBuilder.withPayload("Response")
.setHeader("foo", "bar")
.setHeader(JmsHeaders.TYPE, "msg_type")
.setHeader(JmsHeaders.REPLY_TO, replyTo)
.build();
Session session = mock(Session.class);
given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
javax.jms.Message replyMessage = listener.buildMessage(session, result);
verify(session).createTextMessage("Response");
assertNotNull("reply should never be null", replyMessage);
assertEquals("Response", ((TextMessage) replyMessage).getText());
assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo"));
assertEquals("type header not copied", "msg_type", replyMessage.getJMSType());
assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo());
}
代码示例来源:origin: apache/activemq
/**
* Copies the standard JMS and user defined properties from the givem
* message to the specified message
*
* @param fromMessage the message to take the properties from
* @param toMessage the message to add the properties to
* @throws JMSException
*/
public static void copyProperties(Message fromMessage, Message toMessage) throws JMSException {
toMessage.setJMSMessageID(fromMessage.getJMSMessageID());
toMessage.setJMSCorrelationID(fromMessage.getJMSCorrelationID());
toMessage.setJMSReplyTo(transformDestination(fromMessage.getJMSReplyTo()));
toMessage.setJMSDestination(transformDestination(fromMessage.getJMSDestination()));
toMessage.setJMSDeliveryMode(fromMessage.getJMSDeliveryMode());
toMessage.setJMSRedelivered(fromMessage.getJMSRedelivered());
toMessage.setJMSType(fromMessage.getJMSType());
toMessage.setJMSExpiration(fromMessage.getJMSExpiration());
toMessage.setJMSPriority(fromMessage.getJMSPriority());
toMessage.setJMSTimestamp(fromMessage.getJMSTimestamp());
Enumeration propertyNames = fromMessage.getPropertyNames();
while (propertyNames.hasMoreElements()) {
String name = propertyNames.nextElement().toString();
Object obj = fromMessage.getObjectProperty(name);
toMessage.setObjectProperty(name, obj);
}
}
}
代码示例来源:origin: apache/log4j
public void onMessage(javax.jms.Message message) {
LoggingEvent event;
Logger remoteLogger;
try {
if(message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
event = (LoggingEvent) objectMessage.getObject();
remoteLogger = Logger.getLogger(event.getLoggerName());
remoteLogger.callAppenders(event);
} else {
logger.warn("Received message is of type "+message.getJMSType()
+", was expecting ObjectMessage.");
}
} catch(JMSException jmse) {
logger.error("Exception thrown while processing incoming message.",
jmse);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public void onMessage(javax.jms.Message message) {
ILoggingEvent event;
try {
if (message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
event = (ILoggingEvent) objectMessage.getObject();
Logger log = (Logger) LoggerFactory.getLogger(event.getLoggerName());
log.callAppenders(event);
} else {
logger.warn("Received message is of type " + message.getJMSType()
+ ", was expecting ObjectMessage.");
}
} catch (JMSException jmse) {
logger.error("Exception thrown while processing incoming message.", jmse);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public void onMessage(javax.jms.Message message) {
ILoggingEvent event;
try {
if (message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
event = (ILoggingEvent) objectMessage.getObject();
Logger log = (Logger) LoggerFactory.getLogger(event.getLoggerName());
log.callAppenders(event);
} else {
logger.warn("Received message is of type " + message.getJMSType()
+ ", was expecting ObjectMessage.");
}
} catch (JMSException jmse) {
logger.error("Exception thrown while processing incoming message.", jmse);
}
}
代码示例来源:origin: apache/log4j
sbuf.append(m.getJMSType());
代码示例来源:origin: spring-projects/spring-integration
String type = jmsMessage.getJMSType();
if (type != null) {
headers.put(JmsHeaders.TYPE, type);
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testJmsTypeMappedFromHeader() throws JMSException {
String jmsType = "testing";
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.TYPE, jmsType).build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNotNull(jmsMessage.getJMSType());
assertEquals(jmsType, jmsMessage.getJMSType());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testJmsTypeIgnoredIfIncorrectType() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.TYPE, new Integer(123)).build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSType());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToWriteDisallowedTypePropertyIsNotFatal() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.TYPE, "someType")
.setHeader("foo", "bar")
.build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSType(String type) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSType());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
内容来源于网络,如有侵权,请联系作者删除!