You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2007/03/02 17:16:24 UTC
svn commit: r513825 - in /incubator/cxf/trunk/common/common/src:
main/java/org/apache/cxf/resource/ test/java/org/apache/cxf/resource/
test/java/org/apache/cxf/resource/resources/
Author: seanoc
Date: Fri Mar 2 08:16:23 2007
New Revision: 513825
URL: http://svn.apache.org/viewvc?view=rev&rev=513825
Log:
Modified to check if InputStream can be got from jar: URL before attempting to find the resource on the classpath.
Added a test for this.
Added:
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java (with props)
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/resources/
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/resources/helloworld.bpr (with props)
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java?view=diff&rev=513825&r1=513824&r2=513825
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java Fri Mar 2 08:16:23 2007
@@ -28,7 +28,6 @@
import java.net.URISyntaxException;
import java.net.URL;
-
import org.apache.cxf.common.classloader.ClassLoaderUtils;
/**
@@ -60,7 +59,6 @@
public URIResolver(String baseUriStr, String uriStr, Class calling) throws IOException {
this.calling = (calling != null) ? calling : getClass();
-
if (uriStr.startsWith("classpath:")) {
tryClasspath(uriStr);
} else if (baseUriStr != null && baseUriStr.startsWith("jar:")) {
@@ -185,12 +183,24 @@
}
private void tryJar(String uriStr) throws IOException {
+ System.out.println("tryjar");
int i = uriStr.indexOf('!');
if (i == -1) {
return;
}
- uriStr = uriStr.substring(i + 1);
- tryClasspath(uriStr);
+
+ URL url = new URL(uriStr);
+ is = url.openStream();
+ if (is != null) {
+ try {
+ uri = url.toURI();
+ } catch (URISyntaxException ex) {
+ // ignore
+ }
+ } else {
+ uriStr = uriStr.substring(i + 1);
+ tryClasspath(uriStr);
+ }
}
private void tryClasspath(String uriStr) throws IOException {
Added: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java?view=auto&rev=513825
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java (added)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java Fri Mar 2 08:16:23 2007
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.resource;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class URIResolverTest extends TestCase {
+
+ private URIResolver uriResolver;
+
+ private URL resourceURL = getClass().getResource("resources/helloworld.bpr");
+
+ public void setUp() throws Exception {
+ uriResolver = new URIResolver();
+ }
+
+ public void tearDown() throws Exception {
+
+ }
+
+ public void testJARProtocol() throws Exception {
+
+ byte[] barray = new byte[]{0};
+ byte[] barray2 = new byte[]{1};
+ String uriStr = "jar:" + resourceURL.toString() + "!/wsdl/hello_world.wsdl";
+
+ // Check standard Java API's work with "jar:"
+ URL jarURL = new URL(uriStr);
+ InputStream is = jarURL.openStream();
+ assertNotNull(is);
+ if (is != null) {
+ barray = new byte[is.available()];
+ is.read(barray);
+ is.close();
+ }
+
+ uriResolver.resolve("baseUriStr", uriStr, null);
+
+ InputStream is2 = uriResolver.getInputStream();
+ assertNotNull(is2);
+ if (is2 != null) {
+ barray2 = new byte[is2.available()];
+ is2.read(barray2);
+ is2.close();
+
+ }
+ assertEquals(new String(barray), new String(barray2));
+ }
+}
Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/resources/helloworld.bpr
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/resources/helloworld.bpr?view=auto&rev=513825
==============================================================================
Binary file - no diff available.
Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/resources/helloworld.bpr
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream