cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6986] Creating a default CDI application if none has been discovered, patch from John Ament applied, This closes #182
Date Fri, 21 Oct 2016 15:13:41 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 8967ec568 -> f573af6e8


[CXF-6986] Creating a default CDI application if none has been discovered, patch from John
Ament applied, This closes #182


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f573af6e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f573af6e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f573af6e

Branch: refs/heads/3.1.x-fixes
Commit: f573af6e8abe03e5dbe7944c97508f46cf4a3de6
Parents: 8967ec5
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Oct 21 16:11:30 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Oct 21 16:12:48 2016 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/cdi/AbstractCXFBean.java     | 69 ++++++++++++++++++++
 .../java/org/apache/cxf/cdi/CdiBusBean.java     | 42 +-----------
 .../org/apache/cxf/cdi/DefaultApplication.java  | 26 ++++++++
 .../apache/cxf/cdi/DefaultApplicationBean.java  | 68 +++++++++++++++++++
 .../cxf/cdi/JAXRSCdiResourceExtension.java      |  5 +-
 parent/pom.xml                                  |  2 +-
 systests/cdi/pom.xml                            |  9 +--
 .../jaxrs/BookStoreCustomApplication.java       | 11 ++--
 8 files changed, 177 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/integration/cdi/src/main/java/org/apache/cxf/cdi/AbstractCXFBean.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/AbstractCXFBean.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/AbstractCXFBean.java
new file mode 100644
index 0000000..4c59c93
--- /dev/null
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/AbstractCXFBean.java
@@ -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.cdi;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.AnnotationLiteral;
+
+abstract class AbstractCXFBean<T> implements Bean<T> {
+    @Override
+    public Set<Annotation> getQualifiers() {
+        Set<Annotation> qualifiers = new HashSet<>();
+        qualifiers.add(new AnnotationLiteral<Default>() {
+        });
+        qualifiers.add(new AnnotationLiteral<Any>() {
+        });
+        return qualifiers;
+    }
+
+    @Override
+    public Set<Type> getTypes() {
+        final Set< Type > types = new HashSet<>();
+        types.add(Object.class);
+        return types;
+    }
+
+    @Override
+    public Class<? extends Annotation> getScope() {
+        return ApplicationScoped.class;
+    }
+
+    @Override
+    public boolean isAlternative() {
+        return false;
+    }
+
+    @Override
+    public boolean isNullable() {
+        return false;
+    }
+
+    @Override
+    public Set< Class< ? extends Annotation > > getStereotypes() {
+        return Collections.emptySet();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiBusBean.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiBusBean.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiBusBean.java
index faf350f..fe111a5 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiBusBean.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiBusBean.java
@@ -18,26 +18,18 @@
  */
 package org.apache.cxf.cdi;
 
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.Set;
 
-import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Default;
-import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.util.AnnotationLiteral;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.CXFBusFactory;
 import org.apache.cxf.bus.extension.ExtensionManagerBus;
 
-public final class CdiBusBean implements Bean< ExtensionManagerBus > {
+final class CdiBusBean extends AbstractCXFBean< ExtensionManagerBus > {
     static final String CXF = "cxf";
     
     private final InjectionTarget<ExtensionManagerBus> injectionTarget;
@@ -61,44 +53,14 @@ public final class CdiBusBean implements Bean< ExtensionManagerBus
> {
         return CXF;
     }
 
-    @SuppressWarnings("serial")
-    @Override
-    public Set< Annotation > getQualifiers() {
-        Set<Annotation> qualifiers = new HashSet<Annotation>();
-        qualifiers.add(new AnnotationLiteral< Default >() { });
-        qualifiers.add(new AnnotationLiteral< Any >() { });
-        return qualifiers;
-    }
-
     @Override
     public Set<Type> getTypes() {
-        final Set< Type > types = new HashSet< Type >();
+        final Set< Type > types = super.getTypes();
         types.add(Bus.class);
-        types.add(Object.class);
         return types;
     }
     
     @Override
-    public Class<? extends Annotation> getScope() {
-        return ApplicationScoped.class;
-    }
-
-    @Override
-    public boolean isAlternative() {
-        return false;
-    }
-
-    @Override
-    public boolean isNullable() {
-        return false;
-    }
-    
-    @Override
-    public Set< Class< ? extends Annotation > > getStereotypes() {
-        return Collections.< Class< ? extends Annotation > >emptySet();
-    }
-
-    @Override
     public ExtensionManagerBus create(final CreationalContext< ExtensionManagerBus >
ctx) {
         final ExtensionManagerBus instance = injectionTarget.produce(ctx);
         CXFBusFactory.possiblySetDefaultBus(instance);

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplication.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplication.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplication.java
new file mode 100644
index 0000000..69a6077
--- /dev/null
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplication.java
@@ -0,0 +1,26 @@
+/**
+ * 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.cdi;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/")
+public class DefaultApplication extends Application {
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplicationBean.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplicationBean.java
b/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplicationBean.java
new file mode 100644
index 0000000..af83bbe
--- /dev/null
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/DefaultApplicationBean.java
@@ -0,0 +1,68 @@
+/**
+ * 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.cdi;
+
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Vetoed;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.ws.rs.core.Application;
+
+@Vetoed
+class DefaultApplicationBean extends AbstractCXFBean<DefaultApplication> {
+    private final DefaultApplication application = new DefaultApplication();
+
+    @Override
+    public Class<?> getBeanClass() {
+        return DefaultApplication.class;
+    }
+
+    @Override
+    public Set<InjectionPoint> getInjectionPoints() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public DefaultApplication create(CreationalContext<DefaultApplication> creationalContext)
{
+        return application;
+    }
+
+    @Override
+    public void destroy(DefaultApplication defaultApplication,
+                        CreationalContext<DefaultApplication> creationalContext) {
+
+    }
+
+    @Override
+    public Set<Type> getTypes() {
+        final Set<Type> types = super.getTypes();
+        types.add(DefaultApplication.class);
+        types.add(Application.class);
+        return types;
+    }
+
+    @Override
+    public String getName() {
+        return DefaultApplication.class.getName();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
index 0b1d926..cc1ac73 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
@@ -118,8 +118,11 @@ public class JAXRSCdiResourceExtension implements Extension {
                 beanManager.createInjectionTarget(busAnnotatedType);
             event.addBean(new CdiBusBean(busInjectionTarget));
         }
+        if (applicationBeans.isEmpty()) {
+            event.addBean(new DefaultApplicationBean());
+        }
     }
-
+    
     /**
      * Create the JAXRSServerFactoryBean from the application and all discovered service
and provider instances.
      * @param application application instance

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 011722a..20c1458 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -168,7 +168,7 @@
         <cxf.validation.api.package.version>[1.0.0,2)</cxf.validation.api.package.version>
         <cxf.cdi.api.version>1.1</cxf.cdi.api.version>
         <cxf.json.api.version>1.0</cxf.json.api.version>
-        <cxf.jboss.weld.version>2.3.3.Final</cxf.jboss.weld.version>
+        <cxf.jboss.weld.version>2.4.0.Final</cxf.jboss.weld.version>
         <cxf.jboss.logging.version>3.3.0.Final</cxf.jboss.logging.version>
         <cxf.osgi.validation.api.version>1.1.0</cxf.osgi.validation.api.version>
         <cxf.hibernate.validator.version>5.2.2.Final</cxf.hibernate.validator.version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/systests/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/systests/cdi/pom.xml b/systests/cdi/pom.xml
index 0b14c62..6b2018a 100644
--- a/systests/cdi/pom.xml
+++ b/systests/cdi/pom.xml
@@ -56,14 +56,7 @@
             <groupId>org.jboss.weld</groupId>
             <artifactId>weld-core</artifactId>
             <version>${cxf.jboss.weld.version}</version>
-        </dependency>                
-        <!--
-          <dependency>
-            <groupId>org.apache.bval</groupId>
-            <artifactId>bval-jsr</artifactId>
-            <version>1.1.0-alpha-SNAPSHOT</version>
-          </dependency>
-        -->
+        </dependency>
         <dependency>
             <groupId>javax.el</groupId>
             <artifactId>javax.el-api</artifactId>

http://git-wip-us.apache.org/repos/asf/cxf/blob/f573af6e/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
----------------------------------------------------------------------
diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
index 5756344..0b64081 100644
--- a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
+++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
@@ -19,13 +19,13 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
 
 import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.core.Application;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-import com.google.common.collect.Sets;
 
 import org.apache.cxf.jaxrs.validation.JAXRSBeanValidationFeature;
 import org.apache.cxf.jaxrs.validation.ValidationExceptionMapper;
@@ -35,10 +35,11 @@ import org.apache.cxf.systest.jaxrs.cdi.BookStore;
 public class BookStoreCustomApplication extends Application {
     @Override
     public Set< Object > getSingletons() {
-        return Sets.newHashSet(
-            new JacksonJsonProvider(),
-            new ValidationExceptionMapper(),
-            new JAXRSBeanValidationFeature());
+        Set<Object> singletons = new HashSet<>();
+        singletons.add(new JacksonJsonProvider());
+        singletons.add(new ValidationExceptionMapper());
+        singletons.add(new JAXRSBeanValidationFeature());
+        return singletons;
     }
 
     @Override


Mime
View raw message