Issue Details (XML | Word | Printable)

Key: SMXCOMP-176
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Jean-Baptiste Onofré
Reporter: Jean-Baptiste Onofré
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ServiceMix Components

Support JarUrlConnection with regexp in the SU <classpath/>

Created: 20/Jan/09 06:40 AM   Updated: 06/Apr/09 12:31 PM
Return to search
Component/s: servicemix-common
Affects Version/s: 3.2.3
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File SM-1771-1.patch 2009-01-30 12:02 AM Jean-Baptiste Onofré 4 kB
Text File SM-1771-2.patch 2009-02-08 12:27 PM Jean-Baptiste Onofré 6 kB
Text File Licensed for inclusion in ASF works SM-1771-3.patch 2009-02-08 11:34 PM Jean-Baptiste Onofré 8 kB
Text File Licensed for inclusion in ASF works SM-1771-4.patch 2009-02-13 03:38 AM Jean-Baptiste Onofré 8 kB
Text File Licensed for inclusion in ASF works SMXCOMP-176.patch 2009-02-15 12:35 PM Jean-Baptiste Onofré 20 kB
Text File Licensed for inclusion in ASF works SMXCOMP-176_1.patch 2009-02-20 12:48 PM Jean-Baptiste Onofré 23 kB
Text File Licensed for inclusion in ASF works SMXCOMP-176_2.patch 2009-02-20 11:58 PM Jean-Baptiste Onofré 4 kB
Text File Licensed for inclusion in ASF works SMXCOMP-176_3.patch 2009-02-21 01:09 AM Jean-Baptiste Onofré 22 kB
Text File Licensed for inclusion in ASF works SMXCOMP-176_4.patch 2009-03-26 03:06 AM Jean-Baptiste Onofré 15 kB
Environment:
ServiceMix 3.3.1
JVM 1.5.0 Sun
Linux


 Description  « Hide
It's possible to extend the SU classloader using the <classpath/> tag.
Currently, the <location/> tag in classpath uses File and expects something like /path/to/my.jar.

We are going to extend this using JarUrlConnection inside the <location/> tag. Using JarUrlConnection, the user will be able to use classpath extension like :
jar:file:/path/to/my.ear!/my.jar
for example.

Moreover, we will add regexp supports for jar lookup. At the end, the user will be able to use something like that :
jar:file/path/to/my.ear!/my*.jar



 All   Comments   Work Log   Change History   Subversion Commits   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Jean-Baptiste Onofré added a comment - 20/Jan/09 06:41 AM
For information, the <classpath/> management class is in servicemix-common. It's the ClassLoaderXmlPreprocessor.

Guillaume Nodet added a comment - 20/Jan/09 08:29 AM
Not sure how feasible it is to use regexp on non file based urls.

Jean-Baptiste Onofré added a comment - 22/Jan/09 11:43 PM
Well, I have seen the <location/> usage in the getClassLoader(SpringApplicationContext applicationContext, XmlBeanDefinitionReader reader, Document document) method.

For the <location/>, a classpath List is created and populated with location element. After that, this classpath List is transformed into a URLs array.
This transformation is made using getResource(String location) method.
The issue is that in getResource(String location), a File is used :

URI uri = root.toURI().resolve(location); // where root is a File provided in the constructor
File file = new File(uri);

I'm going to patch the getResource(String location) method to detect if the location is a JarUrlConnection or a File and return a URL.
I think that I can take the location string and apply some regexp on it (I need to investigate deeper).


Jean-Baptiste Onofré added a comment - 22/Jan/09 11:48 PM
I have seen that getResource(String location) method is used to load a classpath.xml file (in the SU root) too.
This classpath.xml must be remain a File. So, I will make a little patch of the preprocess() method to let the classpath.xml as a File.

Jean-Baptiste Onofré added a comment - 30/Jan/09 12:02 AM
Step 1 : add the support of jar: and file: classpath entries.

The path contains the getResource() changes in the ClassLoaderXmlPreprocessor and a small unit test for different kind of provided URLs.

The patch root is servicemix-core.

I resume to better support (and try the regexp support as made in Commons VFS).


Jean-Baptiste Onofré added a comment - 08/Feb/09 12:27 PM
A new patch that use ZipFile/ZipEntry to use regexp and generate the matching URL.

Warning : this patch is work in progress (unit test fails). I need to work on it and so it's not intended for inclusion.


Jean-Baptiste Onofré added a comment - 08/Feb/09 11:34 PM
Correct the issue. Now parse the URI using StringBuffer/String. Get the ZipFile and looking into entries.
Add unit test with a ear file.
Need to complete with new unit tests.

Jean-Baptiste Onofré added a comment - 13/Feb/09 03:38 AM
This is the first real patch release.

It includes the support of :

  • file: based URL
  • jar:file: based URL
  • jar:file: based URL with regexp support.

Guillaume, could make a quick review on the patch and give me some feedback ?

Thanks,
Regards
JB


Jean-Baptiste Onofré added a comment - 14/Feb/09 09:36 AM
After dealing with Guillaume, the getResource() method should now return a list of URL.
Currently the getJarResource() supports regexp but returns only the first occurence that match. A more efficient way is to return the list of all URLs matching the regexp.

Jean-Baptiste Onofré added a comment - 15/Feb/09 12:35 PM
This patch now supports multi URLs.

Jean-Baptiste Onofré added a comment - 20/Feb/09 08:28 AM
I'm going to extend the patch to be able to use system properties.

Has we have the servicemix.home argument in the SMX startup (provided using -Dservicemix.home=), it can be interesting to use this property in the <location/> definition.

With it, we will be able to use notation like :
<classpath>
<location>${servicemix.home}/lib/ext/myjar.jar</location>
</classpath>


Jean-Baptiste Onofré added a comment - 20/Feb/09 12:48 PM
This patch contains :
  • renaming of the methods
  • adding replace method
  • use system properties to replace value in location

Jean-Baptiste Onofré added a comment - 20/Feb/09 11:58 PM
To avoid unit test failure after applying the patch (as the test.ear file shouldn't be created using the patch file), I have commented the unit test assert around the ear exploring.

This patch should be the final one. I build a complete SMX3 distribution and make "real" tests.


Jean-Baptiste Onofré added a comment - 21/Feb/09 12:43 AM
The last patch contains only the change on the unit test. We need to apply both SMXCOMP-176_1 and SMXCOMP-176_2 patches (in this order).

Jean-Baptiste Onofré added a comment - 21/Feb/09 01:09 AM
Here is the complete patch with the commented part of the unit test.

I build SMX3 using this to perform "real" tests.


Guillaume Nodet added a comment - 02/Mar/09 05:17 AM
Two comments:
  • I think the file:// pattern could be used with regexp too (imho this is a valid use case)
  • I would avoid using a JarFile and use a JarInputStream instead, this would make all jar:xxx urls work and not only jar:file:xxx urls

Jean-Baptiste Onofré added a comment - 23/Mar/09 06:17 AM
Thanks for your comment Guillaume, I will submit a new patch including this.

Jean-Baptiste Onofré added a comment - 26/Mar/09 03:06 AM
Patch containing the last Guillaume's comment.

Jean-Baptiste Onofré added a comment - 26/Mar/09 03:14 AM
Another tip from Guillaume, the replaceString method can be replaced by :

for (Enumeration e = properties.propertyNames(); e.hasMoreElements() {
String key = (String)e.nextElement();
String val = properties.getProperty(key);
Matcher matcher = Pattern.compile("\\$\\{([^}]+)
}").matcher(val);
while (matcher.find()) {
String rep = System.getProperty(matcher.group(1));
if (rep != null) { val = val.replace(matcher.group(0), rep); matcher.reset(val); }
}
properties.put(key, val);


Jean-Baptiste Onofré added a comment - 06/Apr/09 12:31 PM
Patch commited. It will be included in the next SMX3 release.