Search in sources :

Example 21 with JMSServiceException

use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.

the class DirectConnectionFactory method _createConnectionId.

// ///////////////////////////////////////////////////////////////////////
// end jakarta.jms.TopicConnectionFactory
// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
// MQ methods
// ///////////////////////////////////////////////////////////////////////
/**
 * Create a connection with the jmsservice and return a connectionId. Used by the methods implementing
 * jakarta.jms.Connection, jakarta.jms.QueueConnection, and jakarta.jms.TopicConnection
 *
 * @param username The username that should be used to authenticate the creation of the connection with the jmsservice
 * @param password The password that should be used to authenticate the creation of the connection with the jmsservice
 *
 * @return The connectionId to be used by the DirectConnection object that is returned by the JMS API method
 *
 * @throws JMSSecurityException if the specified user identity does not authenticate successfully with the JMS server
 * @throws JMSException if any JMS server error occurred
 */
private long _createConnectionId(String username, String password) throws JMSException {
    JMSServiceReply reply;
    long connectionId = 0L;
    if (this.jmsservice == null) {
        if (this.ra != null) {
            this.jmsservice = this.ra._getJMSService();
        }
        if (this.jmsservice == null) {
            // Ultimate fallback :)
            this.jmsservice = ResourceAdapter._getRAJMSService();
        }
    }
    assert (this.jmsservice != null);
    try {
        reply = jmsservice.createConnection(username, password);
        try {
            connectionId = reply.getJMQConnectionID();
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQConnectionID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJF.severe(exerrmsg);
            throw jmse;
        }
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        JMSException jmsse;
        String failure_cause;
        boolean security_exception = true;
        switch(status) {
            case INVALID_LOGIN:
                failure_cause = "authentication failure.";
                break;
            case FORBIDDEN:
                failure_cause = "authorization failure.";
                break;
            default:
                failure_cause = "unkown JMSService server error.";
                security_exception = false;
        }
        String exerrmsg = "createConnection on JMSService:" + jmsservice.getJMSServiceID() + " failed for username:" + username + " due to " + failure_cause;
        _loggerJF.severe(exerrmsg);
        jmsse = (security_exception ? new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode()) : new JMSException(exerrmsg, jse.getJMSServiceReply().getErrorCode()));
        jmsse.initCause(jse);
        throw jmsse;
    }
    return connectionId;
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Aggregations

JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)21 JMSException (jakarta.jms.JMSException)15 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)14 JMSSecurityException (jakarta.jms.JMSSecurityException)6 Status (com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)5 XAException (javax.transaction.xa.XAException)5 InvalidSelectorException (jakarta.jms.InvalidSelectorException)4 JMSPacket (com.sun.messaging.jmq.io.JMSPacket)3 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 IllegalStateException (com.sun.messaging.jms.IllegalStateException)3 InvalidDestinationException (jakarta.jms.InvalidDestinationException)3 StompDestination (com.sun.messaging.bridge.api.StompDestination)2 ConsumerClosedNoDeliveryException (com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException)2 Destination (com.sun.messaging.jmq.jmsservice.Destination)2 XidImpl (com.sun.messaging.jmq.util.XidImpl)2 Message (jakarta.jms.Message)2 MessageFormatException (jakarta.jms.MessageFormatException)2 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)1 Packet (com.sun.messaging.jmq.io.Packet)1