}
}
private boolean internalDeliver(javax.jms.Message message) throws CourierException, JmsConnectionFailureException, IllegalStateException {
if (_isReceiver) {
throw new CourierException("This is a read-only Courier");
}
if (null == message) {
return false;
}
synchronized(this) {
if (_messageProducer == null) {
try {
createMessageProducer();
} catch (final NamingContextException nce) {
throw new CourierServiceBindException("Unexpected exception attempting to access naming context pool", nce) ;
}
}
}
synchronized(this) {
if (_messageProducer != null) {
try {
for (KeyValuePair kvp : _messageProperties) {
String key = kvp.getKey();
if(message.getStringProperty(key) == null) {
message.setStringProperty(key, kvp.getValue());
}
}
} catch (final JMSException e) {
throw new CourierTransportException("Caught exception initialising properties! ",e);
}
try {
_messageProducer.send(message);
return true;
}
catch (final JmsConnectionFailureException jcfe) {
throw jcfe ;
}
catch (final IllegalStateException ise) {
throw ise ;
}
catch (JMSException e) {
if (!jmsConnectRetry(e))
throw new CourierTransportException("Caught exception during delivery and could not reconnect! ",e);
try {
_messageProducer.send(message);
return true;
} catch (final JMSException e2) {
throw new CourierTransportException("Caught exception during delivery having successfully recovered! ",e2);
} catch (Exception e2) {
throw new CourierException(e2);
}
}
catch (Exception e) {
throw new CourierException(e);
}
}
}
return false;
} // ________________________________