use of jakarta.resource.NotSupportedException in project openmq by eclipse-ee4j.
the class EndpointConsumer method _init.
protected void _init() throws ResourceException {
if (!this.ra.getInAppClientContainer()) {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
System.setProperty("imq.DaemonThreads", "true");
return null;
}
});
// System.setProperty("imq.DaemonThreads", "true");
}
// ask the activation spec whether this endpoint should use RADirect
// it will return true if the RA is configured to use RADirect and we haven't overridden addressList in the activation
// spec
useRADirect = this.aSpec.useRADirect();
Object cfObj = null;
String connectionFactoryLookup = aSpec.getConnectionFactoryLookup();
if (connectionFactoryLookup != null) {
try {
cfObj = Util.jndiLookup(connectionFactoryLookup);
} catch (NamingException e) {
String errorMessage = "MQRA:EC:Invalid connectionFactoryLookup " + connectionFactoryLookup + " configured in ActivationSpec of MDB for no JNDI name found";
throw new ResourceException(errorMessage, e);
}
}
// Configure connection factory
if (useRADirect) {
JMSService jmsservice = this.ra._getJMSService();
this.dcf = new com.sun.messaging.jms.ra.DirectConnectionFactory(jmsservice, null);
if (cfObj != null) {
DirectConnectionFactory cfd = (DirectConnectionFactory) cfObj;
ManagedConnectionFactory mcf = cfd.getMCF();
cfd.setMCF(mcf);
aSpec.setMCF(mcf);
}
this.username = this.aSpec.getUserName();
this.password = this.aSpec.getPassword();
} else {
xacf = new com.sun.messaging.XAConnectionFactory();
try {
if (cfObj != null) {
ConnectionFactoryAdapter cfa = (ConnectionFactoryAdapter) cfObj;
ManagedConnectionFactory mcf = cfa.getMCF();
aSpec.setMCF(mcf);
}
// get addressList from activation spec or (suitably adjusted) from the resource adapter
this.xacf.setProperty(ConnectionConfiguration.imqAddressList, aSpec._AddressList());
// get addressListBehavior from activation spec or resource adapter
xacf.setProperty(ConnectionConfiguration.imqAddressListBehavior, aSpec.getAddressListBehavior());
// get username from activation spec or resource adapter
this.xacf.setProperty(ConnectionConfiguration.imqDefaultUsername, aSpec.getUserName());
// get password from activation spec or resource adapter
this.xacf.setProperty(ConnectionConfiguration.imqDefaultPassword, aSpec.getPassword());
// get addressListIterations from activation spec or resource adapter
xacf.setProperty(ConnectionConfiguration.imqAddressListIterations, Integer.toString(aSpec.getAddressListIterations()));
// get reconnectAttempts from activation spec or resource adapter
this.xacf.setProperty(ConnectionConfiguration.imqReconnectAttempts, Integer.toString(aSpec.getReconnectAttempts()));
// get reconnectEnabled from activation spec
this.xacf.setProperty(ConnectionConfiguration.imqReconnectEnabled, Boolean.toString(aSpec.getReconnectEnabled()));
// get reconnectInterval from activation spec or resource adapter
this.xacf.setProperty(ConnectionConfiguration.imqReconnectInterval, Integer.toString(aSpec.getReconnectInterval()));
// configure xacf with any additional connection factory properties defined in the activation spec
setAdditionalConnectionFactoryProperties(aSpec.getOptions());
} catch (JMSException jmse) {
System.err.println("MQRA:EC:constr:Exception setting connection factory properties: " + jmse.getMessage());
}
}
this.onMessageMethod = this.ra._getOnMessageMethod();
this.exRedeliveryAttempts = this.aSpec.getEndpointExceptionRedeliveryAttempts();
this.exRedeliveryInterval = this.aSpec.getEndpointExceptionRedeliveryInterval();
this.mName = this.aSpec.getMdbName();
this.selector = this.aSpec.getMessageSelector();
this.subscriptionName = this.aSpec.getSubscriptionName();
String cId = this.aSpec.getClientId();
if ((cId != null) && !("".equals(cId)) && (cId.length() > 0)) {
this.clientId = cId;
} else {
this.clientId = null;
}
try {
this.isDeliveryTransacted = this.endpointFactory.isDeliveryTransacted(this.onMessageMethod);
} catch (NoSuchMethodException ex) {
// Assume delivery is non-transacted
// Fix to throw NotSupportedException on activation
// ex.printStackTrace();
}
setDestinationType();
if (this.destinationType == ClientConstants.DESTINATION_TYPE_TOPIC) {
// Will throw NotSupportedException if clientId not set properly
setIsDurable();
}
checkSubscriptionScopeAndClientId();
if (this.isDurable) {
if (this.clientId == null && aSpec.getSubscriptionScope() == null) {
// automatically generate client identifier
if (aSpec._getGroupName() != null) {
this.clientId = aSpec._getGroupName() + "{m:" + mName + "}";
} else {
this.clientId = "{m:" + mName + "}";
}
}
} else {
if ((aSpec._isNoAckDeliverySet()) && (this.destination instanceof com.sun.messaging.Topic) && (!this.isDeliveryTransacted)) {
this.noAckDelivery = true;
}
if (aSpec._isInClusteredContainerSet()) {
if (this.clientId == null && aSpec.getSubscriptionScope() == null) {
if ((mName == null) || ("".equals(mName))) {
throw new NotSupportedException("MQRA:EC:Error:Clustered Message Consumer requires" + " non-null clientID OR mdbName:clientID=" + this.clientId + ":mdbName=" + mName);
} else {
// set effective clientId from mName
if (aSpec._getGroupName() != null) {
this.clientId = aSpec._getGroupName() + "{m:" + mName + "}";
} else {
this.clientId = "{m:" + mName + "}";
}
}
}
}
}
if (this.useRADirect) {
this.createDirectMessageConsumer();
} else {
this.createRemoteMessageConsumer();
}
}
use of jakarta.resource.NotSupportedException in project openmq by eclipse-ee4j.
the class EndpointConsumer method checkSubscriptionScopeAndClientId.
protected void checkSubscriptionScopeAndClientId() throws NotSupportedException {
if (aSpec.getSubscriptionScope() != null) {
if (QUEUE.equals(aSpec.getDestinationType())) {
NotSupportedException nse = new NotSupportedException("MQRA:EC:Error:Bad parameter");
nse.initCause(new InvalidPropertyException(_lgrMID_EXC + "subscriptionScope must not be set if destinationType is " + QUEUE));
throw nse;
} else if (TOPIC.equals(aSpec.getDestinationType()) && clientId != null) {
NotSupportedException nse = new NotSupportedException("MQRA:EC:Error:Bad parameter");
nse.initCause(new InvalidPropertyException(_lgrMID_EXC + "clientId must not be set if subscriptionScope is set"));
throw nse;
}
}
}
use of jakarta.resource.NotSupportedException in project openmq by eclipse-ee4j.
the class EndpointConsumer method createRemoteMessageConsumer.
/**
* Creates a MessageConsumer associated with this EndpointConsumer after validating the passed in ActivationSpec
* parameter. The MessageConsumer delivers the messages to a MessageEndpoint manufactured using the
* MessageEndpointFactory passed in.
*/
private void createRemoteMessageConsumer() throws ResourceException {
try {
xac = (com.sun.messaging.jmq.jmsclient.XAConnectionImpl) xacf.createXAConnection();
if (// This should never happen
xac == null)
throw new ResourceException("MQRA:EC:Error:createRemoteMessageConsumer failed: cannot create XAConnection");
if ((aSpec._isInClusteredContainerSet())) {
xac.setRANamespaceUID(aSpec._getRAUID());
}
_loggerIM.fine("MQRA:EC:createRemoteMessageConsumer setting clientID to " + this.clientId);
if (this.clientId != null) {
xac.setClientID(this.clientId);
}
xac.setExceptionListener(this);
xac.setEventListener(this);
} catch (JMSException jmse) {
if (xac != null) {
try {
xac.close();
} catch (JMSException jmsecc) {
}
xac = null;
}
if (logRCFailures) {
jmse.printStackTrace();
}
throw new NotSupportedException("MQRA:EC:Error:createRemoteMessageConsumer failed:aborting due to:" + jmse.getMessage(), jmse);
}
// success
try {
if (this.isDurable) {
this.xas = (com.sun.messaging.jmq.jmsclient.XASessionImpl) xac.createSession(false, Session.CLIENT_ACKNOWLEDGE);
} else {
if (noAckDelivery) {
this.xas = (com.sun.messaging.jmq.jmsclient.XASessionImpl) xac.createSession(com.sun.messaging.jms.Session.NO_ACKNOWLEDGE);
} else {
this.xas = (com.sun.messaging.jmq.jmsclient.XASessionImpl) xac.createSession(false, Session.CLIENT_ACKNOWLEDGE);
}
}
xas._setRAEndpointSession();
if (aSpec.getSubscriptionScope() != null) {
subscriptionName = getSubscriptionName();
if (this.isDurable) {
msgConsumer = xas.createSharedDurableConsumer((Topic) destination, subscriptionName, aSpec.getMessageSelector());
} else {
msgConsumer = xas.createSharedConsumer((Topic) destination, subscriptionName, aSpec.getMessageSelector());
}
} else {
if (this.isDurable) {
msgConsumer = xas.createDurableSubscriber((Topic) destination, aSpec.getSubscriptionName(), aSpec.getMessageSelector(), false);
} else {
msgConsumer = xas.createConsumer(destination, aSpec.getMessageSelector());
// test to see if Queue is enabled for more than one consumer when InClustered true
if (destination instanceof jakarta.jms.Queue && aSpec._isInClusteredContainerSet()) {
// Fail activation if it is not
try {
msgConsumer2 = xas.createConsumer(destination, aSpec.getMessageSelector());
msgConsumer2.close();
msgConsumer2 = null;
} catch (JMSException jmse) {
try {
xac.close();
} catch (JMSException jmsecc) {
// System.out.println("MQRA:EC:closed xac on conn creation exception-"+jmsecc.getMessage());
}
xac = null;
throw new NotSupportedException("MQRA:EC:Error clustering multiple consumers on Queue:\n" + jmse.getMessage(), jmse);
}
}
}
}
msgListener = new MessageListener(this, this.endpointFactory, aSpec);
// System.out.println("MQRA:EC:Created msgListener");
// msgConsumer.setMessageListener(new MessageListener(this, epFactory, spec));
msgConsumer.setMessageListener(msgListener);
// System.out.println("MQRA:EC:Set msgListener");
// System.out.println("MQRA:EC:Starting Connection");
xac.start();
updateFactoryConsumerTables(this.endpointFactory);
} catch (JMSException jmse) {
if (xac != null) {
try {
xac.close();
} catch (JMSException jmsecc) {
// System.out.println("MQRA:EC:closed xac on conn creation exception-"+jmsecc.getMessage());
}
xac = null;
}
throw new NotSupportedException("MQRA:EC:Error creating Remote Message Consumer:\n" + jmse.getMessage(), jmse);
}
}
use of jakarta.resource.NotSupportedException in project openmq by eclipse-ee4j.
the class ResourceAdapter method endpointActivation.
/**
* Activate a message endpoint. Called by the Application Server when a message-driven bean is deployed.
*
* {@inheritDoc}
*/
@Override
public void endpointActivation(MessageEndpointFactory endpointFactory, jakarta.resource.spi.ActivationSpec spec) throws ResourceException {
Object[] params = new Object[2];
params[0] = endpointFactory;
params[1] = spec;
_loggerIM.entering(_className, "endpointActivation()", params);
if (!started) {
_loggerIM.logp(Level.SEVERE, _className, "endpointActivation()", _lgrMID_EXC + "MQJMSRA not started:Aborting:", params);
NotSupportedException nse = new NotSupportedException("MQJMSRA-endpointActivation:Error:RA not started:aborting");
_loggerIM.throwing(_className, "endpointActivation()", nse);
throw nse;
}
EndpointConsumer ec;
if ((System.getProperty("imq.jmsra.endpoint.concurrent", "false")).equals("true")) {
ec = new ConcurrentEndpointConsumer(this, endpointFactory, spec);
} else {
ec = new EndpointConsumer(this, endpointFactory, spec);
}
try {
ec.startMessageConsumer();
// }
if (_loggerIM.isLoggable(Level.FINER)) {
_loggerIM.finer(_lgrMID_INF + "endpointActivation:createMessageConsumer:DONE:" + "fID=" + ec.getFactoryID() + " cID=" + ec.getConsumerID());
}
} catch (Exception ex) {
_loggerIM.logp(Level.SEVERE, _className, "endpointActivation()", _lgrMID_EXC + ":Failed due to:" + ex.getMessage(), params);
NotSupportedException nse = new NotSupportedException("MQJMSRA-endpointActivation:Exception on createMessageConsumer:");
nse.initCause(ex);
_loggerIM.throwing(_className, "endpointActivation()", nse);
throw nse;
}
_loggerIM.exiting(_className, "endpointActivation()");
}
use of jakarta.resource.NotSupportedException in project openmq by eclipse-ee4j.
the class EndpointConsumer method setDestinationType.
/**
* Sets destinationType from the ActivationSpec instance passed in and validates related configs
*/
private void setDestinationType() throws ResourceException {
String destName = aSpec.getDestination();
String destinationLookup = aSpec.getDestinationLookup();
Object destObj = null;
if (destinationLookup != null) {
try {
destObj = Util.jndiLookup(destinationLookup);
} catch (NamingException e) {
String errorMessage = "MQRA:EC:Invalid destinationLookup " + destinationLookup + " configured in ActivationSpec of MDB for no JNDI name found";
throw new ResourceException(errorMessage, e);
}
if (destObj != null) {
if (destObj instanceof com.sun.messaging.Destination) {
destName = ((com.sun.messaging.Destination) destObj).getName();
} else {
String errorMessage = "MQRA:EC:Invalid destinationLookup " + destinationLookup + " configured in ActivationSpec of MDB, The JNDI object is required to be a Destination";
throw new NotSupportedException(errorMessage);
}
} else {
String errorMessage = "MQRA:EC:Invalid destinationLookup " + destinationLookup + " configured in ActivationSpec of MDB for JNDI object is null";
throw new NotSupportedException(errorMessage);
}
}
try {
if (destObj != null) {
if (destObj instanceof com.sun.messaging.Queue) {
if (aSpec._isDestTypeTopicSet())
throw new InvalidPropertyException("MQRA:EC:Inconsistent destinationType is set for destinationLookup " + destinationLookup);
this.destination = new com.sun.messaging.Queue(destName);
this.destinationType = ClientConstants.DESTINATION_TYPE_QUEUE;
} else {
if (destObj instanceof com.sun.messaging.Topic) {
if (aSpec._isDestTypeQueueSet())
throw new InvalidPropertyException("MQRA:EC:Inconsistent destinationType is set for destinationLookup " + destinationLookup);
this.destination = new com.sun.messaging.Topic(destName);
this.destinationType = ClientConstants.DESTINATION_TYPE_TOPIC;
}
}
} else if (aSpec._isDestTypeQueueSet()) {
this.destination = new com.sun.messaging.Queue(destName);
this.destinationType = ClientConstants.DESTINATION_TYPE_QUEUE;
} else {
// destinationType is TOPIC by default
this.destination = new com.sun.messaging.Topic(destName);
this.destinationType = ClientConstants.DESTINATION_TYPE_TOPIC;
}
} catch (JMSException jmse) {
String errorMessage;
if (destName == null) {
errorMessage = "MQRA:EC:No destination configured in ActivationSpec of MDB";
} else {
errorMessage = "MQRA:EC:Invalid destination " + destName + " configured in ActivationSpec of MDB";
}
NotSupportedException nse = new NotSupportedException(errorMessage);
nse.initCause(jmse);
throw nse;
}
// XXX:Does MDB Deployment need physical dest to exist?
// If so need Admin API to check
// XXX:Can MDB depoyment handle destname as resource-ref vs. physical dest name?
// If so, need to handle in ActivationSpec (how will AS handle this?)
}
Aggregations