Author: alessio.soldano(a)jboss.com
Date: 2012-12-19 02:47:36 -0500 (Wed, 19 Dec 2012)
New Revision: 17132
Modified:
common/trunk/src/main/java/org/jboss/ws/common/Loggers.java
common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java
common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java
common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java
common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java
common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java
Log:
[JBWS-3551] Impl failsafe methods
Modified: common/trunk/src/main/java/org/jboss/ws/common/Loggers.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/Loggers.java 2012-12-19 07:40:24 UTC
(rev 17131)
+++ common/trunk/src/main/java/org/jboss/ws/common/Loggers.java 2012-12-19 07:47:36 UTC
(rev 17132)
@@ -214,4 +214,12 @@
@LogMessage(level = TRACE)
@Message(id = 22114, value = "%s doesn't work on %s")
void aspectDoesNotWorkOnDeployment(Class<?> aspect, Class<?>
deployment);
+
+ @LogMessage(level = TRACE)
+ @Message(id = 22115, value = "Cannot get URL for %s")
+ void cannotGetURLFor(String path);
+
+ @LogMessage(level = TRACE)
+ @Message(id = 22116, value = "Could not find %s in the additional
metadatafiles")
+ void cannotFindInAdditionalMetaData(String resourcePath);
}
Modified: common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java 2012-12-19
07:40:24 UTC (rev 17131)
+++ common/trunk/src/main/java/org/jboss/ws/common/ResourceLoaderAdapter.java 2012-12-19
07:47:36 UTC (rev 17132)
@@ -68,7 +68,7 @@
this.loader = loader;
}
- public UnifiedVirtualFile findChild(String resourcePath) throws IOException
+ private UnifiedVirtualFile findChild(String resourcePath, boolean
throwExceptionIfNotFound) throws IOException
{
URL resourceURL = null;
if (resourcePath != null)
@@ -113,11 +113,38 @@
}
if (resourceURL == null)
- throw MESSAGES.cannotGetURLFor(resourcePath);
+ {
+ if (throwExceptionIfNotFound)
+ {
+ throw MESSAGES.cannotGetURLFor(resourcePath);
+ }
+ else
+ {
+ if (ROOT_LOGGER.isTraceEnabled()) ROOT_LOGGER.cannotGetURLFor(resourcePath);
+ return null;
+ }
+ }
return new ResourceLoaderAdapter(loader, resourceURL);
}
+ public UnifiedVirtualFile findChild(String child) throws IOException
+ {
+ return findChild(child, true);
+ }
+
+ public UnifiedVirtualFile findChildFailSafe(String child)
+ {
+ try
+ {
+ return findChild(child, false);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
public URL toURL()
{
if (null == this.resourceURL)
Modified:
common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java 2012-12-19
07:40:24 UTC (rev 17131)
+++
common/trunk/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java 2012-12-19
07:47:36 UTC (rev 17132)
@@ -63,9 +63,11 @@
try
{
// META-INF first
- UnifiedVirtualFile vfs =
archive.getRootFile().findChild(META_INF_JAXB_INTROS_XML);
- url = vfs.toURL();
- introsConfigStream = url.openStream();
+ UnifiedVirtualFile vfs =
archive.getRootFile().findChildFailSafe(META_INF_JAXB_INTROS_XML);
+ if (vfs != null) {
+ url = vfs.toURL();
+ introsConfigStream = url.openStream();
+ }
} catch (Exception e) {}
if(null == introsConfigStream)
@@ -73,9 +75,11 @@
try
{
// WEB-INF second
- UnifiedVirtualFile vfs =
archive.getRootFile().findChild(WEB_INF_JAXB_INTROS_XML);
- url = vfs.toURL();
- introsConfigStream = url.openStream();
+ UnifiedVirtualFile vfs =
archive.getRootFile().findChildFailSafe(WEB_INF_JAXB_INTROS_XML);
+ if (vfs != null) {
+ url = vfs.toURL();
+ introsConfigStream = url.openStream();
+ }
} catch (Exception e) {
return;
}
Modified:
common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java 2012-12-19
07:40:24 UTC (rev 17131)
+++
common/trunk/src/main/java/org/jboss/ws/common/deployment/ResourceResolverImpl.java 2012-12-19
07:47:36 UTC (rev 17132)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -124,4 +124,78 @@
return resourceURL;
}
+ public URL resolveFailSafe(String resourcePath)
+ {
+ final boolean traceEnabled = ROOT_LOGGER.isTraceEnabled();
+ URL resourceURL = null;
+ if (resourcePath != null && resourcePath.length() > 0)
+ {
+ if (resourcePath.startsWith("/"))
+ resourcePath = resourcePath.substring(1);
+
+ try
+ {
+ // assign an absolute URL
+ resourceURL = new URL(resourcePath);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ if (resourceURL == null && rootFile != null)
+ {
+ UnifiedVirtualFile vfResource = rootFile.findChildFailSafe(resourcePath);
+ if (vfResource == null)
+ {
+ if (metadataFiles == null || metadataFiles.isEmpty())
+ {
+ if (traceEnabled) ROOT_LOGGER.cannotGetRootResourceFrom(resourcePath,
rootFile, null);
+ }
+ else
+ {
+ if (traceEnabled)
ROOT_LOGGER.cannotGetRootFileTryingWithAdditionalMetaData(resourcePath);
+ }
+ }
+ else
+ {
+ resourceURL = vfResource.toURL();
+ }
+ }
+ //scan additional metadata files (for instance originally attached to a
VFSDeploymentUnit)
+ if (resourceURL == null && metadataFiles != null &&
!metadataFiles.isEmpty())
+ {
+ UnifiedVirtualFile vfResource = null;
+ for (Iterator<UnifiedVirtualFile> it = metadataFiles.iterator();
it.hasNext() && vfResource == null;)
+ {
+ UnifiedVirtualFile uvf = it.next();
+ URL wsdlUrl = uvf.toURL();
+ String wsdlPath = wsdlUrl.getPath();
+ if (wsdlPath.startsWith("/"))
+ wsdlPath = wsdlPath.substring(1);
+ if (resourcePath.equals(wsdlPath))
+ {
+ vfResource = uvf;
+ }
+ else
+ {
+ vfResource = uvf.findChildFailSafe(resourcePath);
+ if (traceEnabled && vfResource == null) {
+ ROOT_LOGGER.cannotGetRootResourceFrom(resourcePath, uvf, null);
+ }
+ }
+ }
+ if (vfResource == null)
+ {
+ if (traceEnabled)
ROOT_LOGGER.cannotFindInAdditionalMetaData(resourcePath);
+ }
+ else
+ {
+ resourceURL = vfResource.toURL();
+ }
+ }
+ }
+ return resourceURL;
+ }
+
}
Modified:
common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java
===================================================================
---
common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java 2012-12-19
07:40:24 UTC (rev 17131)
+++
common/trunk/src/test/java/org/jboss/test/ws/common/ResourceLoaderAdapterTestCase.java 2012-12-19
07:47:36 UTC (rev 17132)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.common;
+import java.io.IOException;
import java.util.List;
import junit.framework.TestCase;
@@ -85,4 +86,22 @@
assertNotNull(utils);
assertTrue(resourceLoaderAdapter.getChildren().size() == 0);
}
+
+ public void testFailSafeGetChild()
+ {
+ ClassLoader cl = UnifiedVirtualFile.class.getClassLoader();
+ ResourceLoaderAdapter ula = new ResourceLoaderAdapter(cl);
+ try {
+ ula.findChild("foo/bar/");
+ fail("IOException expected");
+ } catch (IOException e) {
+ //expected
+ }
+ try {
+ UnifiedVirtualFile uvf = ula.findChildFailSafe("foo/bar/");
+ assertNull(uvf);
+ } catch (Exception e) {
+ fail("Exception not expected, 'null' should have been returned
instead: " + e.getMessage());
+ }
+ }
}
Modified:
common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java
===================================================================
---
common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java 2012-12-19
07:40:24 UTC (rev 17131)
+++
common/trunk/src/test/java/org/jboss/test/ws/common/URLLoaderAdapterTestCase.java 2012-12-19
07:47:36 UTC (rev 17132)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.common;
+import java.io.IOException;
import java.net.URL;
import java.util.List;
@@ -90,6 +91,26 @@
assertTrue(urlLoaderAdapter.getChildren().size() == 0);
}
+ public void testFailSafeGetChild() throws Exception
+ {
+ ClassLoader cl = UnifiedVirtualFile.class.getClassLoader();
+ URL rootURL = getJarUrl(cl.getResource("org/jboss/wsf/spi/deployment"));
+ assertNotNull(rootURL);
+ URLLoaderAdapter ula = new URLLoaderAdapter(rootURL);
+ try {
+ ula.findChild("foo/bar/");
+ fail("IOException expected");
+ } catch (IOException e) {
+ //expected
+ }
+ try {
+ UnifiedVirtualFile uvf = ula.findChildFailSafe("foo/bar/");
+ assertNull(uvf);
+ } catch (Exception e) {
+ fail("Exception not expected, 'null' should have been returned
instead: " + e.getMessage());
+ }
+ }
+
private static URL getJarUrl(URL url) throws Exception
{
String urlString = url.toExternalForm();