Search in sources :

Example 1 with UrlResource

use of org.hotswap.agent.util.spring.io.resource.UrlResource in project HotswapAgent by HotswapProjects.

the class PathMatchingResourcePatternResolver method resolveRootDirResource.

/**
 * Resolve the specified resource for path matching.
 * <p>
 * The default implementation detects an Equinox OSGi "bundleresource:" /
 * "bundleentry:" URL and resolves it into a standard jar file URL that can
 * be traversed using Spring's standard jar file traversal algorithm.
 *
 * @param original
 *            the resource to resolve
 * @return the resolved resource (may be identical to the passed-in
 *         resource)
 * @throws IOException
 *             in case of resolution failure
 */
protected Resource resolveRootDirResource(Resource original) throws IOException {
    URL url = original.getURL();
    if (url != null && url.getProtocol().startsWith("bundle")) {
        if (equinoxResolveMethod != null) {
            return new UrlResource((URL) ReflectionUtils.invokeMethod(equinoxResolveMethod, null, url));
        }
        if (url.getProtocol().equals("bundle")) {
            try {
                // Try felix OSGi
                Class<?> bundleWiringClass = ClassUtils.forName("org.apache.felix.framework.BundleWiringImpl", null);
                URL convertedURL = (URL) ReflectionHelper.invoke(null, bundleWiringClass, "convertToLocalUrl", new Class[] { URL.class }, url);
                return new UrlResource(convertedURL);
            } catch (ClassNotFoundException e) {
                logger.trace("org.apache.felix.framework.BundleWiringImpl class not found for {}", url);
            } catch (Exception e) {
                logger.error("Felix BundleWiring.convertToLocalUrl(URL) failed for URL {}", url, e);
            }
        }
    }
    return original;
}
Also used : UrlResource(org.hotswap.agent.util.spring.io.resource.UrlResource) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ZipException(java.util.zip.ZipException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ZipException (java.util.zip.ZipException)1 UrlResource (org.hotswap.agent.util.spring.io.resource.UrlResource)1