本文整理汇总了Java中javax.jms.JMSException类的典型用法代码示例。如果您正苦于以下问题:Java JMSException类的具体用法?Java JMSException怎么用?Java JMSException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JMSException类属于javax.jms包,在下文中一共展示了JMSException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFailedCreateConsumerConnectionStillWorks
import javax.jms.JMSException; //导入依赖的package包/类
@Test
public void testFailedCreateConsumerConnectionStillWorks() throws JMSException {
Connection connection = pooledConnFact.createConnection("guest", "password");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(name.getMethodName());
try {
session.createConsumer(queue);
fail("Should fail to create consumer");
} catch (JMSSecurityException ex) {
LOG.info("Caught expected security error");
}
queue = session.createQueue("GUESTS." + name.getMethodName());
MessageProducer producer = session.createProducer(queue);
producer.close();
connection.close();
}
示例2: populateMessageProperties
import javax.jms.JMSException; //导入依赖的package包/类
/**
* Add any properties (name/value pairs) to the message as string properties
* @param message properties will be added here
* @param props the set of additional properties to be added to message.
* NOTE: If values other than strings need to be added to Messages this
* method can be refactored to support.
*/
private void populateMessageProperties(Message message, Properties props){
if(props == null || message == null){
return;
}
Set<String> propNames = props.stringPropertyNames();
try{
for(String propName : propNames){
String value = props.getProperty(propName);
if(value != null){
message.setStringProperty(propName, value);
}
}
}catch(JMSException jmse){
log.error("Problem added properties to Message", jmse);
}
}
示例3: doTestCreateMessageProducer
import javax.jms.JMSException; //导入依赖的package包/类
private void doTestCreateMessageProducer(boolean useAnonymousProducers) throws JMSException {
cf.setUseAnonymousProducers(useAnonymousProducers);
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue1 = session.createTemporaryQueue();
Queue queue2 = session.createTemporaryQueue();
JmsPoolMessageProducer producer1 = (JmsPoolMessageProducer) session.createProducer(queue1);
JmsPoolMessageProducer producer2 = (JmsPoolMessageProducer) session.createProducer(queue2);
if (useAnonymousProducers) {
assertSame(producer1.getMessageProducer(), producer2.getMessageProducer());
} else {
assertNotSame(producer1.getMessageProducer(), producer2.getMessageProducer());
}
connection.close();
}
示例4: doSendBinaryMessage
import javax.jms.JMSException; //导入依赖的package包/类
private void doSendBinaryMessage( final Session session, final Destination destination,
final byte[] bytes,
final Map<String, ?> properties ) throws JMSException {
try {
BytesMessage message = session.createBytesMessage();
message.writeBytes(bytes);
if (properties != null) {
// Note: Setting any properties (including JMS fields) using
// setObjectProperty might not be supported by all providers
// Tested with: ActiveMQ
for (final Entry<String, ?> property : properties.entrySet()) {
message.setObjectProperty(property.getKey(), property.getValue());
}
}
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
} finally {
releaseSession(false);
}
}
示例5: createTopicConsumer
import javax.jms.JMSException; //导入依赖的package包/类
public MessageConsumer createTopicConsumer(String selector) throws JMSException {
if (isQueue) {
throw new IllegalArgumentException("Only for topic, not queue");
}
String consumerId = "consumer-" + UUID.randomUUID();
topicConnection = startConnection(consumerId);
Session session = topicConnection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(destinationName);
if (isDurable) {
if (selector != null) {
return session.createDurableSubscriber(topic, consumerId, selector, true);
} else {
return session.createDurableSubscriber(topic, consumerId);
}
} else {
if (selector != null) {
return session.createConsumer(topic, selector);
} else {
return session.createConsumer(topic);
}
}
}
示例6: publishMessage
import javax.jms.JMSException; //导入依赖的package包/类
/**
*
* @throws JMSException
*/
public void publishMessage(CmsWorkOrderSimpleBase cmsWoSimpleBase, String type, String id)
throws JMSException {
if (isPubEnabled) {
long t1 = System.currentTimeMillis();
cmsWoSimpleBase = CmsUtil.maskSecuredFields(cmsWoSimpleBase, type);
String payload = gson.toJson(cmsWoSimpleBase);
Map<String, String> headers = new HashMap<>(2);
headers.put("type", getType(type));
headers.put("msgId", id);
MessageData data = new MessageData(payload, headers);
searchPublisher.publish(data);
if (cmsWoSimpleBase instanceof CmsWorkOrderSimple) {
logger.info("WO published to search stream queue for RfcId: "
+ ((CmsWorkOrderSimple) cmsWoSimpleBase).getRfcId() + " took " + (
System.currentTimeMillis() - t1));
} else if (cmsWoSimpleBase instanceof CmsActionOrderSimple) {
logger.info("AO published to search stream queue for procedureId/actionId: "
+ ((CmsActionOrderSimple) cmsWoSimpleBase).getProcedureId() + "/"
+ ((CmsActionOrderSimple) cmsWoSimpleBase).getActionId() + " took " + (
System.currentTimeMillis() - t1));
}
} else {
logger.warn(">>>WOPublisher is disabled<IS_SEARCH_ENABLED>"+ isPubEnabled);
}
}
示例7: createManagedConnection
import javax.jms.JMSException; //导入依赖的package包/类
private ManagedConnection createManagedConnection() {
final ManagedConnection connection;
final ConnectionFactory connectionFactory = getConnectionFactory();
try {
if (!StringUtils.isNullOrEmpty(this.username)) {
connection = ManagedConnection.create(connectionFactory.createConnection(this.username,
this.password));
} else {
connection = ManagedConnection.create(connectionFactory.createConnection());
}
} catch (JMSException e) {
throw new JmsMessageException("Error creating JMS connection from connection factory '"
+ defaultConnectionFactoryName + "'", e);
}
return connection;
}
示例8: isValidRequestResponse
import javax.jms.JMSException; //导入依赖的package包/类
/**
* Since we use a request/response communication style with the client,
* we must ensure that tha appropriate fields are set.
*/
private boolean isValidRequestResponse(Message incoming) {
try {
if (incoming.getJMSCorrelationID() == null) {
getLogger().warn("JMSCorrelationID is not set! Will not process request");
return false;
}
if (incoming.getJMSReplyTo() == null) {
getLogger().warn("JMSReplyTo is not set! Will not process request");
return false;
}
} catch (JMSException e) {
getLogger().warn(
"Failed to read JMSCorrelationID/JMSReplyTo. " +
"Will not process request. Exception message = {}", e.getMessage());
return false;
}
return true;
}
示例9: createConsumer
import javax.jms.JMSException; //导入依赖的package包/类
@Override
public JMSConsumer createConsumer(Destination destination, String selector, boolean noLocal) {
try {
return startIfNeeded(new JMSConsumerImpl(this, getSession().createConsumer(destination, selector, noLocal)));
} catch (JMSException jmse) {
throw Utils.convertToRuntimeException(jmse);
}
}
示例10: sendMessage
import javax.jms.JMSException; //导入依赖的package包/类
public void sendMessage(MessageContext messageContext,
Destination destination, Message message) throws JMSException {
String destinationName = destination.toString();
if (destination instanceof Topic) {
messageHandler.sendMessageToTopic(messageContext, destinationName,
message);
} else {
messageHandler.sendMessageToQueue(messageContext, destinationName,
message);
}
}
示例11: fail_on_get_property
import javax.jms.JMSException; //导入依赖的package包/类
@Test
public void fail_on_get_property() throws Exception {
when(message.getPropertyNames()).thenReturn(Collections.enumeration(asList("1", "2", "3")));
when(message.getStringProperty("1")).thenReturn("1");
when(message.getStringProperty("2")).thenThrow(JMSException.class);
propagator.copyFromMessage(message);
verify(message).getStringProperty(eq("1"));
verify(message).getStringProperty(eq("2"));
verify(message, never()).getStringProperty(eq("3"));
Assert.assertThat(current().containsKey("1"), is(true));
Assert.assertThat(current().entrySet().size(), is(1));
}
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:13,代码来源:AbstractPreservesMessagePropertiesTest.java
示例12: createQueueSession
import javax.jms.JMSException; //导入依赖的package包/类
@Override
public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException {
checkClosedOrFailed();
ensureConnected();
int ackMode = getSessionAcknowledgeMode(transacted, acknowledgeMode);
MockJMSQueueSession result = new MockJMSQueueSession(getNextSessionId(), ackMode, this);
addSession(result);
if (started.get()) {
result.start();
}
return result;
}
示例13: convergeIfNeeded
import javax.jms.JMSException; //导入依赖的package包/类
@Override
@Transactional
public void convergeIfNeeded(CmsActionOrderSimple ao) throws JMSException {
long procId = ao.getProcedureId();
long ciId = ao.getCiId();
String logPrefix = "procedure " + procId + " ci " + ciId;
int step = ao.getExecOrder();
if (canConverge(ao.getProcedureId(), ao.getCiId(), step)) {
//send a jms message to controller.workflow queue to proceed to next step
logger.info("procedure " + procId + " ciId " + ciId + ": inductor response converging to next step");
sendMessageToProceed(PROCEDURE.getName(), procId);
}
logger.info(logPrefix + " inductor response processing finished");
}
示例14: newJMSException
import javax.jms.JMSException; //导入依赖的package包/类
public static JMSException newJMSException(Throwable t) {
if (t instanceof JMSException) {
return (JMSException) t;
}
JMSException se = new JMSException(t.getMessage());
return (JMSException) se.initCause(t);
}
示例15: setBytes
import javax.jms.JMSException; //导入依赖的package包/类
@Override
public void setBytes(String name, byte[] value, int offset, int length) throws JMSException {
// Fail early to avoid unnecessary array copy.
checkKeyNameIsValid(name);
byte[] clone = null;
if (value != null) {
clone = new byte[length];
System.arraycopy(value, offset, clone, 0, length);
}
put(name, clone);
}