[infinispan-issues] [JBoss JIRA] (ISPN-7313) AbstractFileLookup.lookupFileStrict broken on Windows
Stefan Engel (JIRA)
issues at jboss.org
Wed Dec 14 07:34:00 EST 2016
[ https://issues.jboss.org/browse/ISPN-7313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13338427#comment-13338427 ]
Stefan Engel commented on ISPN-7313:
------------------------------------
Possible fix is to use an {{URLConnection}} instead of {{ClassLoader.getResourceAsStream()}}.
This is a 'works for me' solution. Proper handling should then either wrap the exceptions in {{FileNotFoundException}} or change exception handling in {{AbstractFileLookup.getConfiguratuonBuilderHolder()}}.
{code}
public InputStream lookupFileStrict(URI uri, ClassLoader cl) throws FileNotFoundException {
InputStream stream = null;
try {
URL url = new URL(uri.toString());
URLConnection connection = url.openConnection();
if (!(connection instanceof HttpURLConnection)) {
stream = connection.getInputStream();
} else {
throw new IllegalArgumentException("URL of type 'http' not supported");
}
} catch (IOException e) {
throw new IllegalStateException("Something went wrong", e);
}
return stream;
}
{code}
> AbstractFileLookup.lookupFileStrict broken on Windows
> -----------------------------------------------------
>
> Key: ISPN-7313
> URL: https://issues.jboss.org/browse/ISPN-7313
> Project: Infinispan
> Issue Type: Bug
> Components: Core
> Affects Versions: 9.0.0.Alpha4, 9.0.0.Beta1, 8.2.5.Final
> Environment: Using Infinispan as JCache provider in Spring Boot (v1.3.5) application on Windows (either IDE (Eclipse) or fat jar).
> Reporter: Stefan Engel
>
> The fix in ISPN-5949 breaks Windows compatibility.
> infinispan.xml is configured in application.properties
> {noformat}
> spring.cache.jcache.config=classpath:spring/infinispan.xml
> {noformat}
> When using Infinispan in a Spring Boot application (fat jar or Eclipse IDE) the following exception is thrown:
> {noformat}
> Caused by: org.infinispan.commons.CacheConfigurationException:
> com.ctc.wstx.exc.WstxIOException: Stream closed
> at org.infinispan.configuration.parsing.ParserRegistry.parse(ParserRegistry.java:119)
> at org.infinispan.jcache.embedded.JCacheManager.getConfigurationBuilderHolder(JCacheManager.java:100)
> at org.infinispan.jcache.embedded.JCacheManager.<init>(JCacheManager.java:56)
> at org.infinispan.jcache.embedded.JCachingProvider.createCacheManager(JCachingProvider.java:46)
> at org.infinispan.jcache.AbstractJCachingProvider.getCacheManager(AbstractJCachingProvider.java:67)
> at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.createCacheManager(JCacheCacheConfiguration.java:101)
> ...
> {noformat}
> When {{AbstractFileLookup.lookupFileStrict()}} is called in {{JCacheManager.getConfigurationHolder()}} the URI used for infinispan.xml looks something like this:
> * fat jar
> {noformat}
> jar:file:/C:/projects/myapp/myservice-0.0.1.jar!/spring/infinispan.xml
> {noformat}
> * running app from within IDE
> {noformat}
> file:/C:/projects/workspace/myservice/target/classes/spring/infinispan.xml
> {noformat}
> The problem ist now twofold:
> # First this nasty 'C:' in the Windows path breaks the parsing code in {{AbstractFileLookup.lookupFileStrict()}}, as {{lastIndexOf(':')}} cuts the drive letter from the path and not just 'jar:file:' as intended. The resulting {{fileName}} cannot be resolved and {{cl.getResourceAsStream(fileName)}} returns {{null}}.
> {code}
> public InputStream lookupFileStrict(URI uri, ClassLoader cl) throws FileNotFoundException {
> //in case we don't have only file schema, but {{jar:file}} schema too, we have to get rid of all schemas
> int startIndex = uri.toString().lastIndexOf(':');
> String fileName = uri.toString().substring(startIndex + 1);
> return cl.getResourceAsStream(fileName);
> }
> {code}
> # This method gets called too when running from within an IDE (at least Eclipse with Maven integration). But in this case Spring JCacheCacheConfiguration magic (createCachemanager() - configLocation.getURI()) resolves this path to a full path as seen above (not a classpath relative to {{/target/classes}}). As this path ist not on the classpath, {{cl.getResourceAsStream(fileName)}} returns {{null}}.
> In both cases {{lookupFileStrict}} returns {{null}} as {{InputStream}} which in turn leads to the exception mentioned above.
> The old code of {{lookupFileStrict()}}
> {code}
> return new FileInputStream(new File(uri));
> {code}
> works fine from within the IDE, but is broken for a fat jar (ISPN-5949).
> I am currently trying to find a workaround for this. But as far as I can see, the current behaviour (fix or no fix) is going to a problem when developing/running Infinispan enabled applications on Windows.
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
More information about the infinispan-issues
mailing list