本文整理了Java中javax.jms.Message.getStringProperty()
方法的一些代码示例,展示了Message.getStringProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getStringProperty()
方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:getStringProperty
[英]Returns the value of the String property with the specified name.
[中]返回具有指定名称的字符串属性的值。
代码示例来源:origin: openzipkin/brave
@Override public String get(Message carrier, String key) {
try {
return carrier.getStringProperty(key);
} catch (JMSException e) {
// don't crash on wonky exceptions!
return null;
}
}
代码示例来源:origin: apache/hive
/**
* Method to return HCatEventMessage contained in the JMS message.
* @param message The JMS Message instance
* @return The contained HCatEventMessage
*/
public static HCatEventMessage getMessage(Message message) {
try {
String messageBody = ((TextMessage)message).getText();
String eventType = message.getStringProperty(HCatConstants.HCAT_EVENT);
String messageVersion = message.getStringProperty(HCatConstants.HCAT_MESSAGE_VERSION);
String messageFormat = message.getStringProperty(HCatConstants.HCAT_MESSAGE_FORMAT);
if (StringUtils.isEmpty(messageBody) || StringUtils.isEmpty(eventType))
throw new IllegalArgumentException("Could not extract HCatEventMessage. " +
"EventType and/or MessageBody is null/empty.");
return MessageFactory.getDeserializer(messageFormat, messageVersion).getHCatEventMessage(eventType, messageBody);
}
catch (JMSException exception) {
throw new IllegalArgumentException("Could not extract HCatEventMessage. ", exception);
}
}
代码示例来源:origin: spring-projects/spring-framework
String typeId = message.getStringProperty(this.typeIdPropertyName);
if (typeId == null) {
throw new MessageConversionException(
代码示例来源:origin: apache/flume
while (propertyNames.hasMoreElements()) {
String name = propertyNames.nextElement().toString();
String value = message.getStringProperty(name);
headers.put(name, value);
代码示例来源:origin: apache/activemq
@SuppressWarnings("unchecked")
protected List<String> assertReceivedObjectMessageWithListBody(Message message) throws JMSException {
assertNotNull("Should have received a message!", message);
assertEquals("foo header", "abc", message.getStringProperty("foo"));
assertTrue("Should be an object message but was: " + message, message instanceof ObjectMessage);
ObjectMessage objectMessage = (ObjectMessage)message;
List<String> body = (List<String>)objectMessage.getObject();
LOG.info("Received body: " + body);
assertEquals("Size of list should be 1", 1, body.size());
assertEquals("element 0 of list", "First", body.get(0));
return body;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.REPLY_TO, new Destination() {})
.setHeader("foo", "bar")
.build();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSReplyTo(Destination replyTo) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void attemptToWriteDisallowedCorrelationIdNumberPropertyIsNotFatal() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.CORRELATION_ID, 123)
.setHeader("foo", "bar")
.build();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSCorrelationID(String correlationId) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSCorrelationID());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void attemptToWriteDisallowedCorrelationIdStringPropertyIsNotFatal() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.CORRELATION_ID, "abc")
.setHeader("foo", "bar")
.build();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSCorrelationID(String correlationId) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSCorrelationID());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源: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: spring-projects/spring-integration
@Override
public void onMessage(javax.jms.Message message) {
String correlation = null;
try {
if (logger.isTraceEnabled()) {
logger.trace(this.getComponentName() + " Received " + message);
}
if (this.correlationKey == null ||
this.correlationKey.equals("JMSCorrelationID") ||
this.correlationKey.equals("JMSCorrelationID*")) {
correlation = message.getJMSCorrelationID();
}
else {
correlation = message.getStringProperty(this.correlationKey);
}
Assert.state(correlation != null, "Message with no correlationId received");
if (isAsync()) {
onMessageAsync(message, correlation);
}
else {
onMessageSync(message, correlation);
}
}
catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to consume reply with correlationId " + correlation, e);
}
}
}
代码示例来源:origin: spring-projects/spring-integration
private void copyCorrelationIdFromRequestToReply(javax.jms.Message requestMessage, javax.jms.Message replyMessage)
throws JMSException {
if (this.correlationKey != null) {
if (this.correlationKey.equals("JMSCorrelationID")) {
replyMessage.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
}
else {
String value = requestMessage.getStringProperty(this.correlationKey);
if (value != null) {
replyMessage.setStringProperty(this.correlationKey, value);
}
else if (this.logger.isWarnEnabled()) {
this.logger.warn("No property value available on request Message for correlationKey '"
+ this.correlationKey + "'");
}
}
}
else if (replyMessage.getJMSCorrelationID() == null) {
replyMessage.setJMSCorrelationID(requestMessage.getJMSMessageID());
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToWriteDisallowedCorrelationIdNumberPropertyIsNotFatal() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.CORRELATION_ID, new Integer(123))
.setHeader("foo", "bar")
.build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSCorrelationID(String correlationId) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSCorrelationID());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToWriteDisallowedCorrelationIdStringPropertyIsNotFatal() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.CORRELATION_ID, "abc")
.setHeader("foo", "bar")
.build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSCorrelationID(String correlationId) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSCorrelationID());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源: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"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.REPLY_TO, new StubDestination())
.setHeader("foo", "bar")
.build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSReplyTo(Destination replyTo) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源:origin: apache/oozie
@Override
public void setProperties(Message message) throws JMSException {
super.setProperties(message);
setEventStatus(EventStatus.valueOf(message.getStringProperty(JMSHeaderConstants.EVENT_STATUS)));
setAppName(message.getStringProperty(JMSHeaderConstants.APP_NAME));
setUser(message.getStringProperty(JMSHeaderConstants.USER));
}
}
代码示例来源:origin: apache/oozie
/**
* Set the JMS selector properties for message object
* @param message the message
* @throws JMSException in case of a JMS error occurs
*/
@JsonIgnore
public void setProperties(Message message) throws JMSException {
setAppType(AppType.valueOf(message.getStringProperty(JMSHeaderConstants.APP_TYPE)));
setMessageType(MessageType.valueOf(message.getStringProperty(JMSHeaderConstants.MESSAGE_TYPE)));
}
代码示例来源:origin: apache/activemq-artemis
@SuppressWarnings("unchecked")
protected List<String> assertReceivedObjectMessageWithListBody(Message message) throws JMSException {
assertNotNull("Should have received a message!", message);
assertEquals("foo header", "abc", message.getStringProperty("foo"));
assertTrue("Should be an object message but was: " + message, message instanceof ObjectMessage);
ObjectMessage objectMessage = (ObjectMessage) message;
List<String> body = (List<String>) objectMessage.getObject();
System.out.println("Received body: " + body);
assertEquals("Size of list should be 1", 1, body.size());
assertEquals("element 0 of list", "First", body.get(0));
return body;
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testJMSXDeliveryCountConversion() throws Exception {
Message m1 = queueProducerSession.createMessage();
queueProducer.send(m1);
Message m2 = queueConsumer.receive(2000);
int count = m2.getIntProperty("JMSXDeliveryCount");
ProxyAssertSupport.assertEquals(String.valueOf(count), m2.getStringProperty("JMSXDeliveryCount"));
ProxyAssertSupport.assertEquals(count, m2.getLongProperty("JMSXDeliveryCount"));
}
}
内容来源于网络,如有侵权,请联系作者删除!