Hi Andriy
Indeed - as I mentioned I reverted the changes to the parser
Cheers, Sergey

On 03/12/14 12:38, Andrey Redko wrote:
Hi guys,

Thanks a lot for adding OSGi support. One question though: I think we
should hide the environment discovery (OSGi/non-OSGI) inside the
ClasspathScanner class.
ClasspathScanner, when instantiated, can figure out if it runs in OSGi
and create the right classpath scanner delegate (so
JAXRSServerFactoryBeanDefiniti__onParser will stay unchanged).
Thanks.

Best Regards,
     Andriy Redko



On Wed, Dec 3, 2014 at 6:03 AM, Sergey Beryozkin <[email protected]
<mailto:[email protected]>> wrote:

    Hi Freeman

    Thanks for this effort, I did a minor update to avoid updating all
    of ClasspathScanner client code (JAX-RS server & client for now -
    but possibly JAXWS Spring parsers in the future too).
    Dan may likely have more comments but for now I have a couple of
    questions,
    - is FrameworkUtil.getBundle useful ? That returns a CXF bundle, right ?
    - should this Spring DM code be pushed to a dedicated SpringOsgiUtil
    to minimize the risk of some JVMs failing with some eager resolution
    class loading exceptions in non-OSGI cases ?

    Cheers, Sergey


    On 03/12/14 05:06, [email protected] <mailto:[email protected]> wrote:

        Repository: cxf
        Updated Branches:
            refs/heads/master 76c4df1bc -> 0de0309f2


        [CXF-6131]JAX-RS resource spring auto-discovery doesn't work in OSGi


        Project: http://git-wip-us.apache.org/__repos/asf/cxf/repo
        <http://git-wip-us.apache.org/repos/asf/cxf/repo>
        Commit:
        http://git-wip-us.apache.org/__repos/asf/cxf/commit/0de0309f
        <http://git-wip-us.apache.org/repos/asf/cxf/commit/0de0309f>
        Tree: http://git-wip-us.apache.org/__repos/asf/cxf/tree/0de0309f
        <http://git-wip-us.apache.org/repos/asf/cxf/tree/0de0309f>
        Diff: http://git-wip-us.apache.org/__repos/asf/cxf/diff/0de0309f
        <http://git-wip-us.apache.org/repos/asf/cxf/diff/0de0309f>

        Branch: refs/heads/master
        Commit: 0de0309f28e1543660c763c158f435__3d6d2189be
        Parents: 76c4df1
        Author: Freeman Fang <[email protected]
        <mailto:[email protected]>>
        Authored: Wed Dec 3 13:06:42 2014 +0800
        Committer: Freeman Fang <[email protected]
        <mailto:[email protected]>>
        Committed: Wed Dec 3 13:06:42 2014 +0800

        
------------------------------__------------------------------__----------
           core/pom.xml                                    | 20
        ++++++++++++++++++-
           .../org/apache/cxf/bus/osgi/__CXFActivator.java   | 13
        ++++++++++++
           .../cxf/common/util/__SpringClasspathScanner.java | 21
        ++++++++++++++++++--
           parent/pom.xml                                  | 11 ++++++++++
           .../__JAXRSServerFactoryBeanDefiniti__onParser.java | 12
        +++++++++--
           5 files changed, 72 insertions(+), 5 deletions(-)
        
------------------------------__------------------------------__----------


        
http://git-wip-us.apache.org/__repos/asf/cxf/blob/0de0309f/__core/pom.xml
        <http://git-wip-us.apache.org/repos/asf/cxf/blob/0de0309f/core/pom.xml>
        
------------------------------__------------------------------__----------
        diff --git a/core/pom.xml b/core/pom.xml
        index 83ec6f8..d7e8f7a 100644
        --- a/core/pom.xml
        +++ b/core/pom.xml
        @@ -44,7 +44,13 @@

        org.slf4j*;resolution:=__optional;version="${cxf.osgi.__slf4j.version}",
                       org.apache.log4j*;resolution:=__optional,

        
net.sf.cglib*;resolution:=__optional;version="${cxf.cglib.__osgi.version}",
        -
        
org.springframework*;__resolution:=optional;version="__${cxf.osgi.spring.version}",
        + org.springframework.osgi.io
        
<http://org.springframework.osgi.io>;__resolution:=optional;version="__${cxf.osgi.spring.osgi.__version}",
        +
        
org.springframework.osgi.util;__resolution:=optional;version="__${cxf.osgi.spring.osgi.__version}",
        +
        
org.springframework.aop*;__resolution:=optional;version="__${cxf.osgi.spring.version}",
        +
        
org.springframework.beans*;__resolution:=optional;version="__${cxf.osgi.spring.version}",
        +
        
org.springframework.context*;__resolution:=optional;version="__${cxf.osgi.spring.version}",
        +
        
org.springframework.core*;__resolution:=optional;version="__${cxf.osgi.spring.version}",
        +
        
org.springframework.util*;__resolution:=optional;version="__${cxf.osgi.spring.version}",

        
org.objectweb.asm*;resolution:__=optional;version="${cxf.osgi.__asm.version}",

        javax.activation;version="${__cxf.osgi.javax.activation.__version}",

        javax.annotation;version="${__cxf.osgi.javax.annotation.__version}",
        @@ -205,6 +211,18 @@
                       <optional>true</optional>
                       <scope>provided</scope>
                   </dependency>
        +        <dependency>
        +            <groupId>org.springframework.__osgi</groupId>
        +            <artifactId>spring-osgi-io</__artifactId>
        +            <optional>true</optional>
        +            <scope>provided</scope>
        +        </dependency>
        +        <dependency>
        +            <groupId>org.springframework.__osgi</groupId>
        +            <artifactId>spring-osgi-core</__artifactId>
        +            <optional>true</optional>
        +            <scope>provided</scope>
        +        </dependency>
               </dependencies>
               <build>
                   <plugins>

        
http://git-wip-us.apache.org/__repos/asf/cxf/blob/0de0309f/__core/src/main/java/org/apache/__cxf/bus/osgi/CXFActivator.java
        
<http://git-wip-us.apache.org/repos/asf/cxf/blob/0de0309f/core/src/main/java/org/apache/cxf/bus/osgi/CXFActivator.java>
        
------------------------------__------------------------------__----------
        diff --git
        a/core/src/main/java/org/__apache/cxf/bus/osgi/__CXFActivator.java
        b/core/src/main/java/org/__apache/cxf/bus/osgi/__CXFActivator.java
        index 3fed8a8..cb9cce1 100644
        ---
        a/core/src/main/java/org/__apache/cxf/bus/osgi/__CXFActivator.java
        +++
        b/core/src/main/java/org/__apache/cxf/bus/osgi/__CXFActivator.java
        @@ -45,14 +45,23 @@ import org.osgi.util.tracker.__ServiceTracker;
            * - Blueprint namespaces
            */
           public class CXFActivator implements BundleActivator {
        +
        +    /*
        +     * a flag to tell if run the CXF in OSGi cont
        +     */
        +    private static boolean inOSGi;
        +
               private List<Extension> extensions;
               private ManagedWorkQueueList workQueues = new
        ManagedWorkQueueList();
               private ServiceTracker configAdminTracker;
               private CXFExtensionBundleListener cxfBundleListener;
               private ServiceRegistration workQueueServiceRegistration;
        +
        +

               /** {@inheritDoc}*/
               public void start(BundleContext context) throws Exception {
        +        inOSGi = true;
                   cxfBundleListener = new
        CXFExtensionBundleListener(__context.getBundle().__getBundleId());
                   context.addBundleListener(__cxfBundleListener);
                   cxfBundleListener.__registerExistingBundles(__context);
        @@ -123,5 +132,9 @@ public class CXFActivator implements
        BundleActivator {
                   configAdminTracker.close();
                   ExtensionRegistry.__removeExtensions(extensions);
               }
        +
        +    public static boolean isInOSGi() {
        +        return inOSGi;
        +    }

           }

        
http://git-wip-us.apache.org/__repos/asf/cxf/blob/0de0309f/__core/src/main/java/org/apache/__cxf/common/util/__SpringClasspathScanner.java
        
<http://git-wip-us.apache.org/repos/asf/cxf/blob/0de0309f/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 769d1f0..ce4dd7f 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
        @@ -28,7 +28,10 @@ import java.util.HashSet;
           import java.util.List;
           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
        <http://org.springframework.core.io>.__Resource;
           import org.springframework.core.io
        
<http://org.springframework.core.io>.__support.__PathMatchingResourcePatternRes__olver;
           import org.springframework.core.io
        
<http://org.springframework.core.io>.__support.__ResourcePatternResolver;
        @@ -36,6 +39,8 @@ 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
        
<http://org.springframework.osgi.io>.__OsgiBundleResourcePatternResol__ver;
        +import org.springframework.osgi.util.__BundleDelegatingClassLoader;
           import org.springframework.util.__ClassUtils;

           class SpringClasspathScanner extends ClasspathScanner {
        @@ -156,8 +161,20 @@ class SpringClasspathScanner extends
        ClasspathScanner {
               }

               private ResourcePatternResolver getResolver(ClassLoader
        loader) {
        -        return loader != null
        -            ? new PathMatchingResourcePatternRes__olver(loader)
        : new PathMatchingResourcePatternRes__olver();
        +        if (CXFActivator.isInOSGi()) {
        +            //in OSGi should use spring-dm
        OsgiBundleResourcePatternResol__ver
        +            // which can handle bundle url
        +            Bundle bundle = null;
        +            if (loader instanceof BundleDelegatingClassLoader) {
        +                bundle =
        ((BundleDelegatingClassLoader)__loader).getBundle();
        +            } else {
        +                bundle =
        FrameworkUtil.getBundle(__SpringClasspathScanner.class);
        +            }
        +            return new OsgiBundleResourcePatternResol__ver(bundle);
        +        } else {
        +            return loader != null
        +                ? new
        PathMatchingResourcePatternRes__olver(loader) : new
        PathMatchingResourcePatternRes__olver();
        +        }
               }

               private boolean shouldSkip(final String classname) {

        
http://git-wip-us.apache.org/__repos/asf/cxf/blob/0de0309f/__parent/pom.xml
        
<http://git-wip-us.apache.org/repos/asf/cxf/blob/0de0309f/parent/pom.xml>
        
------------------------------__------------------------------__----------
        diff --git a/parent/pom.xml b/parent/pom.xml
        index cc4cbaa..7122127 100644
        --- a/parent/pom.xml
        +++ b/parent/pom.xml
        @@ -56,6 +56,7 @@
                   <cxf.osgi.symbolic.name
        
<http://cxf.osgi.symbolic.name>>${__project.groupId}.${project.__artifactId}</cxf.osgi.__symbolic.name
        <http://cxf.osgi.symbolic.name>>
                   <cxf.osgi.dynamic.import />

        <cxf.osgi.spring.version>[3.1,__5)</cxf.osgi.spring.version>
        +
        
<cxf.osgi.spring.osgi.version>__[1.2.0,2)</cxf.osgi.spring.__osgi.version>

        
<cxf.osgi.commons.lang.__version>[2.4,3)</cxf.osgi.__commons.lang.version>

        <cxf.osgi.slf4j.version>[1.5,__2)</cxf.osgi.slf4j.version>

        
<cxf.osgi.javax.annotation.__version>[0.0,2)</cxf.osgi.__javax.annotation.version>
        @@ -1296,6 +1297,16 @@
                           </exclusions>
                       </dependency>
                       <dependency>
        +                <groupId>org.springframework.__osgi</groupId>
        +                <artifactId>spring-osgi-io</__artifactId>
        +                <version>${cxf.spring.osgi.__version}</version>
        +            </dependency>
        +            <dependency>
        +                 <groupId>org.springframework.__osgi</groupId>
        +                 <artifactId>spring-osgi-core</__artifactId>
        +                 <version>${cxf.spring.osgi.__version}</version>
        +            </dependency>
        +            <dependency>
                           <groupId>commons-codec</__groupId>
                           <artifactId>commons-codec</__artifactId>
                           <version>${cxf.commons-codec.__version}</version>

        
http://git-wip-us.apache.org/__repos/asf/cxf/blob/0de0309f/__rt/frontend/jaxrs/src/main/__java/org/apache/cxf/jaxrs/__spring/__JAXRSServerFactoryBeanDefiniti__onParser.java
        
<http://git-wip-us.apache.org/repos/asf/cxf/blob/0de0309f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java>
        
------------------------------__------------------------------__----------
        diff --git
        
a/rt/frontend/jaxrs/src/main/__java/org/apache/cxf/jaxrs/__spring/__JAXRSServerFactoryBeanDefiniti__onParser.java
        
b/rt/frontend/jaxrs/src/main/__java/org/apache/cxf/jaxrs/__spring/__JAXRSServerFactoryBeanDefiniti__onParser.java
        index 40b6286..e17bd1a 100644
        ---
        
a/rt/frontend/jaxrs/src/main/__java/org/apache/cxf/jaxrs/__spring/__JAXRSServerFactoryBeanDefiniti__onParser.java
        +++
        
b/rt/frontend/jaxrs/src/main/__java/org/apache/cxf/jaxrs/__spring/__JAXRSServerFactoryBeanDefiniti__onParser.java
        @@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.spring;
           import java.io.IOException;
           import java.lang.annotation.__Annotation;
           import java.util.ArrayList;
        +import java.util.Arrays;
           import java.util.Collection;
           import java.util.List;
           import java.util.Map;
        @@ -31,6 +32,7 @@ import javax.xml.namespace.QName;

           import org.w3c.dom.Element;

        +import org.apache.cxf.bus.osgi.__CXFActivator;
           import
        org.apache.cxf.bus.spring.__BusWiringBeanFactoryPostProces__sor;
           import org.apache.cxf.common.util.__ClasspathScanner;
           import org.apache.cxf.common.util.__StringUtils;
        @@ -192,8 +194,14 @@ public class
        JAXRSServerFactoryBeanDefiniti__onParser extends
        AbstractBeanDefiniti

                       try {
                           if (basePackages != null) {
        -                    final Map< Class< ? extends Annotation >,
        Collection< Class< ? > > > classes =
        -
        ClasspathScanner.findClasses(__basePackages, Provider.class,
        Path.class);
        +                    //if run CXF in OSGi, we should pass in the
        classloader associated with
        +                    //the bundle which has JAXRS resources
        under a certain basePackages
        +                    ClassLoader loader =
        Thread.currentThread().__getContextClassLoader();
        +                    final Map< Class< ? extends Annotation >,
        Collection< Class< ? > > > classes =
        +                        CXFActivator.isInOSGi()
        +                            ? ClasspathScanner.findClasses(
        +                                  basePackages,
        Arrays.asList(Provider.class, Path.class), loader)
        +                            :
        ClasspathScanner.findClasses(__basePackages, Provider.class,
        Path.class);


        this.setProviders(createBeans(__classes.get(Provider.class)));

        this.setServiceBeans(__createBeans(classes.get(Path.__class)));



    --



Reply via email to