示例#1
0
 private void saslAuthPlain(String username, String password)
     throws MessagingException, AuthenticationFailedException, IOException {
   byte[] data = ("\000" + username + "\000" + password).getBytes();
   data = new Base64().encode(data);
   try {
     executeSimpleCommand("AUTH PLAIN " + new String(data), true);
   } catch (MessagingException me) {
     if (me.getMessage().length() > 1 && me.getMessage().charAt(1) == '3') {
       throw new AuthenticationFailedException("AUTH PLAIN failed (" + me.getMessage() + ")");
     }
     throw me;
   }
 }
示例#2
0
 private void saslAuthLogin(String username, String password)
     throws MessagingException, AuthenticationFailedException, IOException {
   try {
     executeSimpleCommand("AUTH LOGIN");
     executeSimpleCommand(new String(Base64.encodeBase64(username.getBytes())), true);
     executeSimpleCommand(new String(Base64.encodeBase64(password.getBytes())), true);
   } catch (MessagingException me) {
     if (me.getMessage().length() > 1 && me.getMessage().charAt(1) == '3') {
       throw new AuthenticationFailedException("AUTH LOGIN failed (" + me.getMessage() + ")");
     }
     throw me;
   }
 }
  /** Creates topics and queues and starts listeners */
  private void createDestinations() throws MessagingException {
    try {
      // Create Destinations based on properties
      Enumeration<?> propertyNames = m_connectionProperties.keys();
      while (propertyNames.hasMoreElements()) {
        String propertyName = (String) propertyNames.nextElement();
        if (propertyName.startsWith("topic.")) {
          String destinationName = m_connectionProperties.getProperty(propertyName);
          m_jmsManager.createDestination(destinationName, DestinationType.Topic);
        } else if (propertyName.startsWith("queue.")) {
          String destinationName = m_connectionProperties.getProperty(propertyName);
          m_jmsManager.createDestination(destinationName, DestinationType.Queue);
        }
      }

      // Get destination list
      List<Destination> destinations = m_jmsManager.getDestinations();

      // If there are no Destinations, throw an exception
      if (destinations.size() == 0) {
        throw new MessagingException(
            "No destinations available for "
                + "subscription, make sure that there is at least one topic "
                + "or queue specified in the connection properties.");
      }

      // Subscribe
      for (Destination destination : destinations) {
        if (m_durable && destination instanceof Topic) {
          m_jmsManager.listenDurable((Topic) destination, m_messageSelector, this, null);
        } else {
          m_jmsManager.listen(destination, m_messageSelector, this);
        }
      }
    } catch (MessagingException me) {
      logger.error(
          "MessagingException encountered attempting to start "
              + "Messaging Client: "
              + m_clientId
              + ". Exception message: "
              + me.getMessage(),
          me);
      throw me;
    }
  }
 /**
  * Stops the MessagingClient, shuts down connections. If the unsubscribe parameter is set to true,
  * all durable subscriptions will be removed.
  *
  * @param unsubscribe
  */
 public void stop(boolean unsubscribe) throws MessagingException {
   try {
     if (unsubscribe) {
       m_jmsManager.unsubscribeAllDurable();
     }
     m_jmsManager.close();
     m_jmsManager = null;
     m_connected = false;
   } catch (MessagingException me) {
     logger.error(
         "Messaging Exception encountered attempting to stop "
             + "Messaging Client: "
             + m_clientId
             + ". Exception message: "
             + me.getMessage(),
         me);
     throw me;
   }
 }