Search in sources :

Example 1 with JMSSecurityException

use of jakarta.jms.JMSSecurityException in project openmq by eclipse-ee4j.

the class DirectSession method _createAndAddConsumer.

/**
 * Create a consumerId with the jmsservice and return a MessageConsumer object that can be returned by the JMS API
 * method.
 * <p>
 * This method is used by the methods implementing jakarta.jms.Session, jakarta.jms.QueueSession, and
 * jakarta.jms.TopicSession<br>
 * A successfully created DirectConsumer is added to the table of Consumer objects maintained by this DirectSession.<br>
 * A successfully created durable DirectConsumer is added to the table of durable Consumer objects maintained by the
 * DirectConnection of this DirectSession.
 *
 * @param methodName The JMS API method that was called.
 * @param destination The JMS Destination object identifying the destination on which the consumer is to be created.
 * @param selector The JMS Message selector to be used.
 * @param subscriptionName if dest is Topic and if either durable true or share true, the subscription name
 * @param durable if dest is Topic, if true, this is a durable subscription
 * @param share if dest is Topic, if true, this is a shared subscription
 * @param jmsshare if dest is Topic, if true and share true, this is a JMS 2.0 Shared Subscription if false and share
 * true, this is a MQ Shared Subscription
 *
 * MQ Shared Subscription: messages will be shared with other consumers in the same group that have the same
 * clientId+DurableName for Shared Durable Subscriptions
 * <p>
 * OR
 * <p>
 * clientId+TopicName+Selector for Shared Non-Durable Sunscriptions
 *
 * @param noLocal If {@code true} then this consumer does not want to messages produced on it'sconnection to be
 * delivered to it.
 *
 * @return The DirectConsumer object to be returned by the JMS API method.
 *
 * @throws JMSException if any JMS error occurred.
 */
private DirectConsumer _createAndAddConsumer(String methodName, Destination destination, String selector, String subscriptionName, boolean durable, boolean share, boolean jmsshare, boolean noLocal) throws JMSException {
    JMSServiceReply reply;
    long consumerId = 0L;
    com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
    if (_logFINE) {
        _loggerJS.fine(_lgrMID_INF + "sessionId=" + this.sessionId + ":" + methodName + ":Destination=" + destination + ":Selector=" + selector + ":subscriptionName=" + subscriptionName + ":durable=" + durable + ":share=" + share + ":jmsshare=" + jmsshare + ":noLocal=" + noLocal);
    }
    this._checkIfClosed(methodName);
    jmsservice_dest = this._checkDestinationForConsumer(destination);
    String duraname = (durable ? subscriptionName : null);
    DirectConsumer consumer = new DirectConsumer(this, jmsservice, destination, jmsservice_dest, noLocal, selector, duraname);
    try {
        // adjusted for JMS 2.0
        reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, subscriptionName, durable, share, jmsshare, this.getConnection()._getClientID(), noLocal);
        /*
             * reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, durableName,
             * this.getConnection()._getClientID(), noLocal, //XXX:tharakan:using false for shared temporarily false, false);
             */
        try {
            // Set consumerId right away
            consumerId = reply.getJMQConsumerID();
            consumer._setConsumerId(consumerId);
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQConsumerID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJS.severe(exerrmsg);
            throw jmse;
        }
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        String failure_cause;
        JMSException jmsse = null;
        String exerrmsg = "createConsumer on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
        switch(status) {
            case FORBIDDEN:
                failure_cause = "client forbidden to receive messages from this destination.";
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
                break;
            case NOT_FOUND:
                failure_cause = "destination not found and cannot be auto-created.";
                break;
            case CONFLICT:
                failure_cause = "destination limit for number of consumers exceeded.";
                break;
            case BAD_REQUEST:
                failure_cause = "invalid selector=" + selector;
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new InvalidSelectorException(exerrmsg);
                break;
            case PRECONDITION_FAILED:
                if (jse.getCause() != null && jse.getCause() instanceof BrokerException) {
                    failure_cause = jse.getCause().getMessage();
                    exerrmsg = exerrmsg + failure_cause;
                    jmsse = new IllegalStateException(exerrmsg, ((BrokerException) jse.getCause()).getErrorCode());
                    break;
                }
            default:
                failure_cause = "unknown JMSService server error.";
        }
        _loggerJS.severe(exerrmsg);
        if (jmsse == null) {
            exerrmsg = exerrmsg + failure_cause;
            jmsse = new JMSException(exerrmsg);
        }
        jmsse.initCause(jse);
        throw jmsse;
    }
    this.addConsumer(consumer);
    if (subscriptionName != null && durable) {
        this.dc.addDurableConsumer(consumer);
    }
    if (destination instanceof TemporaryDestination) {
        this.dc._incrementTemporaryDestinationUsage((TemporaryDestination) destination);
    }
    return consumer;
}
Also used : IllegalStateException(com.sun.messaging.jms.IllegalStateException) InvalidSelectorException(jakarta.jms.InvalidSelectorException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Example 2 with JMSSecurityException

use of jakarta.jms.JMSSecurityException in project openmq by eclipse-ee4j.

the class LocalBrokerRunner method start.

protected synchronized void start() throws Exception {
    _loggerL.entering(_className, "start()");
    boolean already_running = false;
    String running_varhome = null;
    if (this.startingRMIRegistry) {
        // Condition this on the AppServer making MQ starting an RMI Registry
        // Else if we use an existsing broker that was uses AppServer's RMI
        // Registry, no asadmin command will work as the stubs will not
        // have been bound by the MQ broker into the new App Server Registry
        _loggerL.fine(_lgrMID_INF + "Looking for Broker Running at:" + this.brokerURL);
        try {
            jmsadmin.pingProvider();
            _loggerL.info(_lgrMID_INF + "Detected Broker Running at:" + this.brokerURL);
            already_running = true;
        } catch (Exception e) {
            already_running = false;
        }
        if (already_running) {
            this.startedByAS = false;
            try {
                jmsadmin.connectToProvider();
                running_varhome = jmsadmin.getProviderVarHome();
            } catch (Exception e) {
            // can't get the varhome directory
            // will fall through to assume not startedbyAS and fail start
            }
            _loggerL.info(_lgrMID_INF + "Detected Broker VAR directory=" + running_varhome);
            if (running_varhome != null && !("".equals(running_varhome)) && (running_varhome.equals(this.brokerVarDir))) {
                // Ok to connect to the broker; This was started by us
                this.startedByAS = true;
            // Ok to attempt to connect and use it
            } else {
                // This broker cannot be used by AS since it has a different
                // varhome directory than the one AS is asking the broker to use
                // Using it could cause problems
                // Therefore we need to abort the start and report a failure
                String excerrmsg = _lgrMID_EXC + "start:Broker running " + "at:" + this.brokerURL + " has a different var directory of:" + running_varhome + ":Failing ra.start()";
                this._loggerL.severe(excerrmsg);
                throw new Exception(excerrmsg);
            }
        } else {
            // broker not running at the designated port; attempt to start one
            jmsadmin.startProvider(brokerBinDir, brokerArgs, brokerInstanceName);
            this.startedByAS = true;
        }
    } else {
        jmsadmin.startProvider(brokerBinDir, brokerArgs, brokerInstanceName);
        this.startedByAS = true;
    }
    // Now try to connect to the provider
    boolean ready = false;
    long firstPingTime = java.lang.System.currentTimeMillis();
    while (true) {
        try {
            // Wait a sec before attempting connection
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
            }
            // jmsadmin.pingProvider();
            if (!already_running) {
                jmsadmin.connectToProvider();
            }
            ready = true;
            break;
        } catch (JMSSecurityException jmsse) {
            // Here because the auth info is incorrect and the broker was able to be started.
            // i.e. they did not use adminPassFile to prevent broker startup with wrong auth
            // Attempt to shut down broker with the default admin/admin username/password
            // And then trow an Exception back to ra.start()
            Exception startEx = new Exception(_lgrMID_EXC + "start:Unable to ping Broker due to authentication error for user " + adminUsername + " : shutting down broker.");
            startEx.initCause(jmsse);
            try {
                tjmsadmin.connectToProvider();
                tjmsadmin.shutdownProvider();
            } catch (Exception spe) {
                _loggerL.warning(_lgrMID_EXC + "start:Exception on LOCAL broker shutdown after connect auth failure:msg=" + spe.getMessage());
            // spe.printStackTrace();
            }
            throw startEx;
        } catch (Exception e) {
            if (java.lang.System.currentTimeMillis() - firstPingTime >= brokerStartTimeout) {
                // Couldn't connect to broker, we've tried for long enough, assume broker is not running and throw an exception
                // note that even if the broker were running we couldn't shut it down here since we can't connect to it
                _loggerL.severe(_lgrMID_EXC + "start:Ping broker failed " + (java.lang.System.currentTimeMillis() - firstPingTime) + " millis after broker start performed. Failing ra.start()");
                _loggerL.warning(_lgrMID_EXC + "start:Aborting:Check Broker Log File at:" + brokerLogFilename);
                break;
            } else {
            // couldn't connect to local broker, perhaps it hasn't started yet, try again
            }
        }
    }
    if (!ready) {
        throw new RuntimeException(_lgrMID_EXC + "start:Aborted:Unable to ping Broker within " + brokerStartTimeout + " millis (startTimeOut)");
    }
}
Also used : JMSSecurityException(jakarta.jms.JMSSecurityException) JMSSecurityException(jakarta.jms.JMSSecurityException)

Example 3 with JMSSecurityException

use of jakarta.jms.JMSSecurityException in project openmq by eclipse-ee4j.

the class JMSBridge method openConnection.

public static Connection openConnection(Object cf, int maximumAttempts, long attemptInterval, String username, String password, String logstr, Object caller, EventListener l, Logger logger, boolean doReconnect) throws Exception {
    if (l.hasEventOccurred()) {
        throw new JMSException("" + l.occurredEvent());
    }
    int maxAttempts = maximumAttempts;
    Connection conn = null;
    int attempts = 0;
    Exception ee = null;
    int invalidClientIDExceptionCnt = 0;
    do {
        if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedException(_jbr.getKString(_jbr.X_OPENCONNECTION_INTERRUPTED, cf.toString(), caller.toString()));
        }
        if (attempts > 0 && attemptInterval > 0) {
            Thread.sleep(attemptInterval);
        }
        try {
            String[] param = { (username == null ? "" : "[" + username + "]"), cf.toString(), caller.toString() };
            if (cf instanceof XAConnectionFactory) {
                logger.log(Level.INFO, _jbr.getString(_jbr.I_CREATING_XA_CONN, param));
                if (username == null) {
                    conn = ((XAConnectionFactory) cf).createXAConnection();
                } else {
                    conn = ((XAConnectionFactory) cf).createXAConnection(username, password);
                }
            } else {
                logger.log(Level.INFO, _jbr.getString(_jbr.I_CREATING_CONN, param));
                if (username == null) {
                    conn = ((ConnectionFactory) cf).createConnection();
                } else {
                    conn = ((ConnectionFactory) cf).createConnection(username, password);
                }
            }
            return conn;
        } catch (JMSException e) {
            attempts++;
            ee = e;
            Exception le = e.getLinkedException();
            if (e instanceof InvalidClientIDException) {
                invalidClientIDExceptionCnt++;
            }
            if (e instanceof JMSSecurityException || le instanceof JMSSecurityException || (e instanceof InvalidClientIDException && invalidClientIDExceptionCnt > 1)) {
                String[] eparam = { logstr, caller.toString(), attempts + "(" + attemptInterval + ")" };
                _logger.log(Level.SEVERE, _jbr.getKString(_jbr.W_EXCEPTION_CREATING_CONN, eparam), e);
                throw e;
            }
            String[] eparam = { logstr, caller.toString(), attempts + "(" + attemptInterval + "): " + e.getMessage() + (le == null ? "" : " - " + le.getMessage()) };
            _logger.log(Level.WARNING, _jbr.getKString(_jbr.W_EXCEPTION_CREATING_CONN, eparam));
            if (!doReconnect && (maxAttempts > 1 || maxAttempts < 0)) {
                throw new ProviderConnectException("Failed to connect to " + cf + ": " + e.getMessage() + (le == null ? "" : " - " + le.getMessage()));
            }
        }
    } while ((maxAttempts < 0 || attempts < maxAttempts) && !l.hasEventOccurred());
    if (l.hasEventOccurred()) {
        throw new JMSException("" + l.occurredEvent());
    }
    throw ee;
}
Also used : InvalidClientIDException(jakarta.jms.InvalidClientIDException) JMSSecurityException(jakarta.jms.JMSSecurityException) XAConnection(jakarta.jms.XAConnection) Connection(jakarta.jms.Connection) XAConnectionFactory(jakarta.jms.XAConnectionFactory) JMSException(jakarta.jms.JMSException) JMSException(jakarta.jms.JMSException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) InvalidClientIDException(jakarta.jms.InvalidClientIDException) JMSSecurityException(jakarta.jms.JMSSecurityException)

Example 4 with JMSSecurityException

use of jakarta.jms.JMSSecurityException in project openmq by eclipse-ee4j.

the class DirectSession method _createProducerId.

/**
 * Create a producer with the jmsservice and return a producerId.
 * <p>
 * Used by createAndAddProducer in DirectSession as well as _createAndAddProducerId method in DirectProducer when a JMS
 * message is produced using a DirectProducer that was created using an unspeificed JMS Destination (i.e. null)
 *
 * @param destination The com.sun.messaging.jmsservice.Destination object identifying the destination on which the
 * producer is to be created.
 *
 * @return The producerId to be used by the DirectProducer object that is returned by the JMS API method
 *
 * @throws JMSException if any JMS server error occurred
 */
protected long _createProducerId(com.sun.messaging.jmq.jmsservice.Destination destination) throws JMSException {
    JMSServiceReply reply;
    long producerId = 0L;
    try {
        reply = jmsservice.addProducer(this.connectionId, this.sessionId, destination);
        try {
            producerId = reply.getJMQProducerID();
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQProducerID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJS.severe(exerrmsg);
            throw jmse;
        }
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        String failure_cause;
        String exerrmsg = "createProducer on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
        JMSException jmsse = null;
        switch(status) {
            case FORBIDDEN:
                failure_cause = "client forbidden to send messages to this destination.";
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
                break;
            case NOT_FOUND:
                failure_cause = "destination not found and cannot be auto-created.";
                break;
            case CONFLICT:
                failure_cause = "destination limit for number of producers exceeded.";
                break;
            default:
                failure_cause = "unkown JMSService server error.";
        }
        _loggerJS.severe(exerrmsg);
        if (jmsse == null) {
            jmsse = new JMSException(exerrmsg + failure_cause);
        }
        jmsse.initCause(jse);
        throw jmsse;
    }
    return producerId;
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Example 5 with JMSSecurityException

use of jakarta.jms.JMSSecurityException in project openmq by eclipse-ee4j.

the class DirectSession method _createAndAddBrowser.

/**
 * Create a Browser with the jmsservice and return a consumerId. Used by the methods implementing jakarta.jms.Session,
 * jakarta.jms.QueueSession, and jakarta.jms.TopicSession
 *
 * @param methodName The JMS API method that was called.
 * @param destination The JMS Destination object identifying the destination on which the browser is to be created.
 * @param selector The JMS Message selector to be used.
 *
 * @return The DirectQueueBrowser object to be returned by the JMS API method.
 *
 * @throws JMSException if any JMS error occurred.
 */
private DirectQueueBrowser _createAndAddBrowser(String methodName, Queue destination, String selector) throws JMSException {
    JMSServiceReply reply;
    long consumerId = 0L;
    DirectQueueBrowser browser = null;
    com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
    if (_logFINE) {
        _loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName + ":Destination=" + destination + ":selector=" + selector);
    }
    this._checkIfClosed(methodName);
    jmsservice_dest = this._checkDestinationForConsumer(destination);
    try {
        reply = jmsservice.addBrowser(connectionId, sessionId, jmsservice_dest, selector);
        try {
            // Must get a consumerId from the addBrowser method
            consumerId = reply.getJMQConsumerID();
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + methodName + "JMSServiceException:Missing JMQConsumerID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJS.severe(exerrmsg);
            throw jmse;
        }
        browser = new DirectQueueBrowser(this, jmsservice, consumerId, destination, jmsservice_dest, selector);
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        String failure_cause;
        JMSException jmsse = null;
        String exerrmsg = "createBrowser on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
        switch(status) {
            case FORBIDDEN:
                failure_cause = "client forbidden to browse messages from this destination.";
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
                break;
            case NOT_FOUND:
                failure_cause = "destination not found and cannot be auto-created.";
                break;
            case CONFLICT:
                failure_cause = "destination limit for number of consumers exceeded.";
                break;
            case BAD_REQUEST:
                failure_cause = "invalid selector=" + selector;
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new InvalidSelectorException(exerrmsg);
                break;
            default:
                failure_cause = "unkown JMSService server error.";
        }
        _loggerJS.severe(exerrmsg);
        if (jmsse == null) {
            exerrmsg = exerrmsg + failure_cause;
            jmsse = new JMSException(exerrmsg);
        }
        jmsse.initCause(jse);
        throw jmsse;
    }
    this.addBrowser(browser);
    return browser;
}
Also used : InvalidSelectorException(jakarta.jms.InvalidSelectorException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Aggregations

JMSSecurityException (jakarta.jms.JMSSecurityException)6 JMSException (jakarta.jms.JMSException)5 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)4 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)4 InvalidSelectorException (jakarta.jms.InvalidSelectorException)2 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 IllegalStateException (com.sun.messaging.jms.IllegalStateException)1 Connection (jakarta.jms.Connection)1 InvalidClientIDException (jakarta.jms.InvalidClientIDException)1 XAConnection (jakarta.jms.XAConnection)1 XAConnectionFactory (jakarta.jms.XAConnectionFactory)1 IOException (java.io.IOException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1