Search in sources :

Example 11 with ResourceException

use of jakarta.resource.ResourceException 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?)
}
Also used : InvalidPropertyException(jakarta.resource.spi.InvalidPropertyException) NamingException(javax.naming.NamingException) ResourceException(jakarta.resource.ResourceException) NotSupportedException(jakarta.resource.NotSupportedException)

Example 12 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class EndpointConsumer method stopDirectMessageConsumer.

/**
 * Stop the Direct MessageConsumer
 */
protected void stopDirectMessageConsumer() throws Exception {
    stopping = true;
    synchronized (this) {
        if (this.msgConsumer != null) {
            try {
                if (this.msgListener != null) {
                    this.ds._stop();
                    msgListener.waitForAllOnMessageRunners();
                    msgListener.releaseOnMessageRunners();
                // this.ds._close(); //Will be done by dc.close
                }
            } catch (JMSException jmse) {
                ResourceException re = new ResourceException("MQRA:EC:Error on closing Direct MessageConsumer");
                re.initCause(jmse);
                throw re;
            }
        }
        if (this.dc != null) {
            try {
                this.dc.close();
            } catch (JMSException jmse) {
                ResourceException re = new ResourceException("MQRA:EC:Error closing DircetConnection");
                re.initCause(jmse);
                throw re;
            }
        }
    }
}
Also used : ResourceException(jakarta.resource.ResourceException)

Example 13 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class LocalTransaction method rollback.

/**
 * Rollback a local transaction
 */
@Override
public synchronized void rollback() throws ResourceException {
    // System.out.println("MQRA:LT:rollback()");
    try {
        if (!xac._isClosed()) {
            xac.getProtocolHandler().rollback(transactionID, null);
        } else {
            ResourceException re = new EISSystemException("MQRA:LT:rollbackTransaction exception:Connection is closed");
            throw re;
        }
    } catch (Exception ex) {
        ResourceException re = new EISSystemException("MQRA:LT:rollback exception:" + ex.getMessage());
        re.initCause(ex);
        throw re;
    } finally {
        mc.setLTActive(false);
        started = false;
        active = false;
    }
}
Also used : EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException) EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException)

Example 14 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class LocalTransaction method begin.

/**
 * Begin a local transaction
 */
@Override
public synchronized void begin() throws ResourceException {
    // System.out.println("MQRA:LT:begin()");
    try {
        if (!xac._isClosed()) {
            transactionID = xac.getProtocolHandler().startTransaction(transactionID, -1, null);
        } else {
            ResourceException re = new EISSystemException("MQRA:LT:startTransaction exception:Connection is closed");
            throw re;
        }
    // mc.getConnectionAdapter().getSessionAdapter().startLocalTransaction();
    } catch (Exception ex) {
        ResourceException re = new EISSystemException("MQRA:LT:startTransaction exception:" + ex.getMessage());
        re.initCause(ex);
        throw re;
    }
    started = true;
    active = true;
    mc.setLTActive(true);
}
Also used : EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException) EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException)

Aggregations

ResourceException (jakarta.resource.ResourceException)14 EISSystemException (jakarta.resource.spi.EISSystemException)6 NotSupportedException (jakarta.resource.NotSupportedException)4 JMSException (jakarta.jms.JMSException)2 NamingException (javax.naming.NamingException)2 JMSService (com.sun.messaging.jmq.jmsservice.JMSService)1 jakarta.jms (jakarta.jms)1 InvalidPropertyException (jakarta.resource.spi.InvalidPropertyException)1 ResourceAdapter (jakarta.resource.spi.ResourceAdapter)1 ResourceAdapterInternalException (jakarta.resource.spi.ResourceAdapterInternalException)1 UnavailableException (jakarta.resource.spi.UnavailableException)1 MessageEndpoint (jakarta.resource.spi.endpoint.MessageEndpoint)1