/**
   * Get the JMS destination specified by the given URL from the context
   *
   * @param context the Context to lookup
   * @param url URL
   * @return the JMS destination, or null if it does not exist
   */
  private Destination getDestination(Context context, String url) {
    String destinationName = JMSUtils.getDestination(url);
    if (log.isDebugEnabled()) {
      log.debug(
          "Lookup the JMS destination "
              + destinationName
              + " of type "
              + destinationType
              + " extracted from the URL "
              + JMSUtils.maskURLPasswordAndCredentials(url));
    }

    try {
      return JMSUtils.lookupDestination(context, destinationName, destinationType);
    } catch (NamingException e) {
      handleException(
          "Couldn't locate the JMS destination "
              + destinationName
              + " of type "
              + destinationType
              + " extracted from the URL "
              + JMSUtils.maskURLPasswordAndCredentials(url),
          e);
    }

    // never executes but keeps the compiler happy
    return null;
  }
  /**
   * Get the JMS reply destination specified by the given URL from the context
   *
   * @param context the Context to lookup
   * @param url URL
   * @return the JMS destination, or null if it does not exist
   */
  private Destination getReplyDestination(Context context, String url) {
    String replyDestinationName = properties.get(JMSConstants.PARAM_REPLY_DESTINATION);
    if (log.isDebugEnabled()) {
      log.debug(
          "Lookup the JMS destination "
              + replyDestinationName
              + " of type "
              + replyDestinationType
              + " extracted from the URL "
              + JMSUtils.maskURLPasswordAndCredentials(url));
    }

    try {
      return JMSUtils.lookupDestination(context, replyDestinationName, replyDestinationType);
    } catch (NamingException e) {
      handleException(
          "Couldn't locate the JMS destination "
              + replyDestinationName
              + " of type "
              + replyDestinationType
              + " extracted from the URL "
              + JMSUtils.maskURLPasswordAndCredentials(url),
          e);
    }

    // never executes but keeps the compiler happy
    return null;
  }
Esempio n. 3
0
  private boolean checkJMSConnection(ServiceTaskManager stm) {

    Connection connection = null;
    Hashtable<String, String> jmsProperties = stm.getJmsProperties();
    try {
      ConnectionFactory jmsConFactory = null;
      try {
        jmsConFactory =
            JMSUtils.lookup(
                new InitialContext(stm.getJmsProperties()),
                ConnectionFactory.class,
                stm.getConnFactoryJNDIName());
      } catch (NamingException e) {
        log.error(
            "Error looking up connection factory : "
                + stm.getConnFactoryJNDIName()
                + "using JNDI properties : "
                + jmsProperties,
            e);
      }
      connection =
          JMSUtils.createConnection(
              jmsConFactory,
              jmsProperties.get(JMSConstants.PARAM_JMS_USERNAME),
              jmsProperties.get(JMSConstants.PARAM_JMS_PASSWORD),
              stm.isJmsSpec11(),
              null,
              false,
              "");
    } catch (JMSException ignore) {
    } // we silently ignore this as a JMSException can be expected when connection is not available

    return (connection != null);
  }
  /** Testing the masking of sensitive info in axis2.xml configs */
  public void testMaskConfigs() {

    Hashtable<String, String> paramsTable = new Hashtable<String, String>();
    paramsTable.put(JMSConstants.CONTENT_TYPE_PARAM, "topic");
    paramsTable.put(JMSConstants.CONTENT_TYPE_PARAM, "text/xml");
    paramsTable.put(JMSConstants.PARAM_JMS_USERNAME, "username");

    // when no security params
    Hashtable<String, String> newParamsTable =
        JMSUtils.maskAxis2ConfigSensitiveParameters(paramsTable);
    Assert.assertSame(
        "Axis2 configs masking when no security params exist", paramsTable, newParamsTable);

    paramsTable.put(JMSConstants.PARAM_JMS_PASSWORD, "password");
    paramsTable.put(JMSConstants.PARAM_NAMING_SECURITY_CREDENTIALS, "Credentials");

    newParamsTable = JMSUtils.maskAxis2ConfigSensitiveParameters(paramsTable);
    Assert.assertFalse("Axis2 configs masking", newParamsTable.toString().contains("password"));
    Assert.assertFalse("Axis2 configs masking", newParamsTable.toString().contains("Credentials"));
  }
  /**
   * Get the referenced ConnectionFactory using the properties from the context
   *
   * @param context the context to use for lookup
   * @param props the properties which contains the JNDI name of the factory
   * @return the connection factory
   */
  private ConnectionFactory getConnectionFactory(Context context, Hashtable<String, String> props) {
    try {

      String conFacJndiName = props.get(JMSConstants.PARAM_CONFAC_JNDI_NAME);
      if (conFacJndiName != null) {
        return JMSUtils.lookup(context, ConnectionFactory.class, conFacJndiName);
      } else {
        handleException("Connection Factory JNDI name cannot be determined");
      }
    } catch (NamingException e) {
      handleException("Failed to look up connection factory from JNDI", e);
    }
    return null;
  }
  /**
   * Look up for the given destination
   *
   * @param replyDest the JNDI name to lookup Destination required
   * @return Destination for the JNDI name passed
   */
  public Destination getReplyDestination(String replyDest) {
    if (log.isDebugEnabled()) {
      log.debug("Lookup the JMS destination " + replyDest + " of type " + replyDestinationType);
    }

    try {
      return JMSUtils.lookupDestination(
          jmsConnectionFactory.getContext(), replyDest, replyDestinationType);
    } catch (NamingException e) {
      handleException(
          "Couldn't locate the JMS destination " + replyDest + " of type " + replyDestinationType,
          e);
    }

    // never executes but keeps the compiler happy
    return null;
  }
Esempio n. 7
0
  /**
   * Listen for JMS messages on behalf of the given service
   *
   * @param endpoint the jms endpoint which is connected with the service
   */
  @Override
  protected void startEndpoint(JMSEndpoint endpoint) throws AxisFault {
    ServiceTaskManager stm = endpoint.getServiceTaskManager();
    boolean connected = false;

    /* The following parameters are used when trying to connect with the JMS provider at the start up*/
    int r = 1;
    long retryDuration = 10000;
    double reconnectionProgressionFactor = 2.0;
    long maxReconnectDuration = 1000 * 60 * 60; // 1 hour

    // First we will check whether jms provider is started or not, as if not it will throw a
    // continuous error log
    // If jms provider not started we will wait for exponentially increasing time intervals, till
    // the provider is started
    while (!connected) {
      boolean jmsProviderStarted = checkJMSConnection(stm);
      if (jmsProviderStarted) {
        log.info(
            "Connection attempt: "
                + r
                + " for JMS Provider for service: "
                + stm.getServiceName()
                + " was successful!");
        connected = true;
        stm.start();

        for (int i = 0; i < 3; i++) {
          // Check the consumer count rather than the active task count. Reason: if the
          // destination is of type topic, then the transport is only ready to receive
          // messages if at least one consumer exists. This is of not much importance,
          // except for automated tests.
          if (stm.getConsumerCount() > 0) {
            log.info(
                "Started to listen on destination : "
                    + stm.getDestinationJNDIName()
                    + " of type "
                    + JMSUtils.getDestinationTypeAsString(stm.getDestinationType())
                    + " for service "
                    + stm.getServiceName());
            return;
          }
          try {
            Thread.sleep(1000);
          } catch (InterruptedException ignore) {
          }
        }

        log.warn(
            "Polling tasks on destination : "
                + stm.getDestinationJNDIName()
                + " of type "
                + JMSUtils.getDestinationTypeAsString(stm.getDestinationType())
                + " for service "
                + stm.getServiceName()
                + " have not yet started after 3 seconds ..");
      } else {
        log.error(
            "Unable to continue server startup as it seems the JMS Provider is not yet started. Please start the JMS provider now.");
        retryDuration = (long) (retryDuration * reconnectionProgressionFactor);
        log.error(
            "Connection attempt : "
                + (r++)
                + " for JMS Provider failed. Next retry in "
                + (retryDuration / 1000)
                + " seconds");
        if (retryDuration > maxReconnectDuration) {
          retryDuration = maxReconnectDuration;
        }
        try {
          Thread.sleep(retryDuration);
        } catch (InterruptedException ignore) {
        }
      }
    }
  }
 /** Testing the URL masking to hide sensitive info. */
 public void testUrlMask() {
   String maskedUrl = JMSUtils.maskURLPasswordAndCredentials(url);
   Assert.assertFalse("URL masking test", maskedUrl.contains("secret"));
 }