activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Timothy Bish (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AMQ-4642) regression: SpringSslContext no longer supports classpath:filename syntax for referencing files
Date Fri, 19 Jul 2013 13:28:48 GMT

    [ https://issues.apache.org/jira/browse/AMQ-4642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13713645#comment-13713645
] 

Timothy Bish commented on AMQ-4642:
-----------------------------------

You should create a test case to show the problem and submit a patch, that way you can know
your fix will remain into the future. 
                
> regression: SpringSslContext no longer supports classpath:filename syntax for referencing
files
> -----------------------------------------------------------------------------------------------
>
>                 Key: AMQ-4642
>                 URL: https://issues.apache.org/jira/browse/AMQ-4642
>             Project: ActiveMQ
>          Issue Type: Bug
>    Affects Versions: 5.6.0, 5.7.0, 5.8.0
>            Reporter: Thomas Swindells
>              Labels: easyfix
>
> 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.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message