Have a look please at the latest commit - that should work...
Cheers, Sergey
On 04/12/14 10:08, Sergey Beryozkin wrote:
Hi Freeman
Thanks, after looking at this code I've realized we can revert the
changes to CXFActivator too - those classes Spring Osgi deals with are
only making sense in OSGi so we can further polish the code - I'll play
a bit later on and let you know about the changes...
Cheers, Sergey
On 04/12/14 08:27, ff...@apache.org wrote:
Repository: cxf
Updated Branches:
refs/heads/master 2b2f97fe1 -> d50ffd09c
[CXF-6131]extract spring-osgi related stuff into an seperate class to
avoid possible JVMs failing with some eager resolution class loading
exceptions in non-OSGI
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d50ffd09
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d50ffd09
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d50ffd09
Branch: refs/heads/master
Commit: d50ffd09c30e606524fb6ed92119d85ccfa13491
Parents: 2b2f97f
Author: Freeman Fang <freeman.f...@gmail.com>
Authored: Thu Dec 4 16:27:32 2014 +0800
Committer: Freeman Fang <freeman.f...@gmail.com>
Committed: Thu Dec 4 16:27:32 2014 +0800
----------------------------------------------------------------------
.../cxf/common/util/SpringClasspathScanner.java | 33 ++++++--------
.../apache/cxf/common/util/SpringOsgiUtil.java | 48
++++++++++++++++++++
2 files changed, 63 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/d50ffd09/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
----------------------------------------------------------------------
diff --git
a/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
b/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
index de9369e..f36a645 100644
---
a/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
+++
b/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
@@ -30,8 +30,6 @@ import java.util.Map;
import org.apache.cxf.bus.osgi.CXFActivator;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.FrameworkUtil;
import org.springframework.core.io.Resource;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
@@ -39,17 +37,27 @@ import
org.springframework.core.type.AnnotationMetadata;
import
org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import
org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.osgi.io.OsgiBundleResourcePatternResolver;
-import org.springframework.osgi.util.BundleDelegatingClassLoader;
import org.springframework.util.ClassUtils;
class SpringClasspathScanner extends ClasspathScanner {
+
+ static final SpringOsgiUtil SPRING_OSGI_UTIL;
+
+ static {
+ SpringOsgiUtil springOsgiUtil = null;
+ try {
+ springOsgiUtil = new SpringOsgiUtil();
+ } catch (Throwable ex) {
+ springOsgiUtil = null;
+ }
+ SPRING_OSGI_UTIL = springOsgiUtil;
+ }
+
SpringClasspathScanner() throws Exception {
Class.forName("org.springframework.core.io.support.PathMatchingResourcePatternResolver");
Class.forName("org.springframework.core.type.classreading.CachingMetadataReaderFactory");
}
-
protected Map< Class< ? extends Annotation >, Collection< Class<
? > > > findClassesInternal(
Collection< String > basePackages,
List<Class< ? extends Annotation > > annotations,
@@ -161,19 +169,8 @@ class SpringClasspathScanner extends
ClasspathScanner {
}
private ResourcePatternResolver getResolver(ClassLoader loader) {
- if (CXFActivator.isInOSGi()) {
- //in OSGi should use spring-dm
OsgiBundleResourcePatternResolver
- // which can handle bundle url
- Bundle bundle = null;
- if (loader == null) {
- loader = Thread.currentThread().getContextClassLoader();
- }
- if (loader instanceof BundleDelegatingClassLoader) {
- bundle =
((BundleDelegatingClassLoader)loader).getBundle();
- } else {
- bundle =
FrameworkUtil.getBundle(SpringClasspathScanner.class);
- }
- return new OsgiBundleResourcePatternResolver(bundle);
+ if (CXFActivator.isInOSGi() && SPRING_OSGI_UTIL != null) {
+ return SPRING_OSGI_UTIL.getResolver(loader);
} else {
return loader != null
? new PathMatchingResourcePatternResolver(loader) :
new PathMatchingResourcePatternResolver();
http://git-wip-us.apache.org/repos/asf/cxf/blob/d50ffd09/core/src/main/java/org/apache/cxf/common/util/SpringOsgiUtil.java
----------------------------------------------------------------------
diff --git
a/core/src/main/java/org/apache/cxf/common/util/SpringOsgiUtil.java
b/core/src/main/java/org/apache/cxf/common/util/SpringOsgiUtil.java
new file mode 100644
index 0000000..f7b6381
--- /dev/null
+++ b/core/src/main/java/org/apache/cxf/common/util/SpringOsgiUtil.java
@@ -0,0 +1,48 @@
+/**
+ * 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.common.util;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.osgi.io.OsgiBundleResourcePatternResolver;
+import org.springframework.osgi.util.BundleDelegatingClassLoader;
+
+public class SpringOsgiUtil {
+
+ SpringOsgiUtil() throws Exception {
+
Class.forName("org.springframework.osgi.io.OsgiBundleResourcePatternResolver");
+
Class.forName("org.springframework.osgi.util.BundleDelegatingClassLoader");
+ }
+
+ public ResourcePatternResolver getResolver(ClassLoader loader) {
+ //in OSGi should use spring-dm OsgiBundleResourcePatternResolver
+ // which can handle bundle url
+ Bundle bundle = null;
+ if (loader == null) {
+ loader = Thread.currentThread().getContextClassLoader();
+ }
+ if (loader instanceof BundleDelegatingClassLoader) {
+ bundle = ((BundleDelegatingClassLoader)loader).getBundle();
+ } else {
+ bundle =
FrameworkUtil.getBundle(SpringClasspathScanner.class);
+ }
+ return new OsgiBundleResourcePatternResolver(bundle);
+ }
+}