Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-4642

regression: SpringSslContext no longer supports classpath:filename syntax for referencing files

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.6.0, 5.7.0, 5.8.0
    • 5.9.0
    • Broker
    • Patch Available
    • Regression

    Description

      Previously keyStore and trustStore were Spring resources rather than strings. This meant the spring standard classpath:location syntax could be used to specify the file, eg:

      <bean id="sslContext" class="org.apache.activemq.spring.SpringSslContext">
      <property name="keyStore" value="classpath:key.ks" />
      <property name="keyStorePassword" value="password" />
      <property name="trustStore" value="classpath:trust.ts" />
      <property name="trustStorePassword" value="password" />
      </bean>

      The change for AMQ-3268 means that this no longer works instead throwing the exception:

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sslContext': Invocation of init method failed; nested exception is java.net.MalformedURLException: unknown protocol: classpath
      at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
      Caused by: java.net.MalformedURLException: unknown protocol: classpath

      The reason is in org.apache.activemq.spring.Utils:
      public static Resource resourceFromString(String uri) throws MalformedURLException {
      Resource resource;
      File file = new File(uri);
      if (file.exists())

      { resource = new FileSystemResource(uri); }

      else if (ResourceUtils.isUrl(uri))

      { resource = new UrlResource(uri); }

      else

      { resource = new ClassPathResource(uri); }

      return resource;
      }

      The ResourceUtils.isUrl has explicit code to return true if the uri startsWith classpath, however UrlResource doesn't handle this.
      A fix may be to change the line to be
      resource = new UrlResource(ResourceUtils.getURL(uri));

      ResourceUtils will then handle the classpath url, resolve it and return a valid url. An alternative fix would be for this code to do an explicit check for classpath: itself and if it is found pass the substring into ClassPathResource.

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              tswindells Thomas Swindells
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: