You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2017/10/08 02:45:08 UTC

[cxf] branch 3.1.x-fixes updated: Merge pull request #313 from johnament/CXF-7493

This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new f150b0d  Merge pull request #313 from johnament/CXF-7493
f150b0d is described below

commit f150b0dd5f047bb46bc2c08d4914fedd88b6e827
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Wed Sep 20 20:01:51 2017 -0400

    Merge pull request #313 from johnament/CXF-7493
    
    [CXF-7493] Add a default ClassUnwrapper for CDI integration.
---
 .../main/java/org/apache/cxf/cdi/CdiBusBean.java   |  7 +++
 .../java/org/apache/cxf/cdi/CdiClassUnwrapper.java | 40 +++++++++++++++++
 .../cdi/base/AbstractCdiSingleAppTest.java         | 18 ++++++++
 .../cxf/systests/cdi/base/BookStoreByIds.java      | 51 ++++++++++++++++++++++
 .../systest/jaxrs/BookStoreCustomApplication.java  |  6 ++-
 5 files changed, 120 insertions(+), 2 deletions(-)

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 fe111a5..776a798 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
@@ -28,6 +28,8 @@ import javax.enterprise.inject.spi.InjectionTarget;
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.CXFBusFactory;
 import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.common.util.ClassUnwrapper;
+import org.apache.cxf.common.util.SystemPropertyAction;
 
 final class CdiBusBean extends AbstractCXFBean< ExtensionManagerBus > {
     static final String CXF = "cxf";
@@ -63,6 +65,11 @@ final class CdiBusBean extends AbstractCXFBean< ExtensionManagerBus > {
     @Override
     public ExtensionManagerBus create(final CreationalContext< ExtensionManagerBus > ctx) {
         final ExtensionManagerBus instance = injectionTarget.produce(ctx);
+
+        if ("true".equals(SystemPropertyAction.getProperty("org.apache.cxf.cdi.unwrap.proxies", "true"))) {
+            instance.setProperty(ClassUnwrapper.class.getName(), new CdiClassUnwrapper());
+        }
+        
         CXFBusFactory.possiblySetDefaultBus(instance);
         instance.initialize();
         
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiClassUnwrapper.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiClassUnwrapper.java
new file mode 100644
index 0000000..c32e669
--- /dev/null
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiClassUnwrapper.java
@@ -0,0 +1,40 @@
+/**
+ * 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.util.regex.Pattern;
+
+import org.apache.cxf.common.util.ClassUnwrapper;
+
+class CdiClassUnwrapper implements ClassUnwrapper {
+    private static final Pattern PROXY_PATTERN = Pattern.compile(".+\\$\\$.+Proxy");
+
+    CdiClassUnwrapper() {
+
+    }
+
+    @Override
+    public Class<?> getRealClass(Object o) {
+        Class<?> clazz = o.getClass();
+        if (PROXY_PATTERN.matcher(clazz.getSimpleName()).matches()) {
+            return clazz.getSuperclass();
+        }
+        return clazz;
+    }
+}
diff --git a/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/AbstractCdiSingleAppTest.java b/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/AbstractCdiSingleAppTest.java
index 0dd6ce4..070a950 100644
--- a/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/AbstractCdiSingleAppTest.java
+++ b/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/AbstractCdiSingleAppTest.java
@@ -56,6 +56,24 @@ public abstract class AbstractCdiSingleAppTest extends AbstractBusClientServerTe
     }
 
     @Test
+    public void testResponseHasBeenReceivedWhenQueringBooksById() {
+        final String id = UUID.randomUUID().toString();
+
+        Response r = createWebClient(getBasePath() + "/books").post(
+                new Form()
+                        .param("id", id)
+                        .param("name", "Book " + id));
+        r.close();
+        r = createWebClient(getBasePath() + "/byIds")
+                .query("ids", "1234")
+                .query("ids", UUID.randomUUID().toString())
+                .query("ids", id)
+                .get();
+        r.close();
+        assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
+    }
+
+    @Test
     public void testAddAndQueryOneBook() {
         final String id = UUID.randomUUID().toString();
 
diff --git a/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/BookStoreByIds.java b/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/BookStoreByIds.java
new file mode 100644
index 0000000..2590525
--- /dev/null
+++ b/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/BookStoreByIds.java
@@ -0,0 +1,51 @@
+/**
+ * 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.systests.cdi.base;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+@ApplicationScoped
+@Path("/bookstore/byIds")
+public class BookStoreByIds {
+    @Inject
+    private BookStoreService service;
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public Collection< Book > getBooks(@QueryParam("ids") List< String > ids) {
+        final Collection<Book> books = new ArrayList<Book>();
+        
+        for (final String id: ids) {
+            final Book book = service.get(id);
+            if (book != null) {
+                books.add(book);
+            }
+        }
+        
+        return books;
+    }
+}
diff --git a/systests/cdi/cdi-owb/cdi-multiple-apps-owb/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java b/systests/cdi/cdi-owb/cdi-multiple-apps-owb/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
index 4438aaf..64a6405 100644
--- a/systests/cdi/cdi-owb/cdi-multiple-apps-owb/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
+++ b/systests/cdi/cdi-owb/cdi-multiple-apps-owb/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreCustomApplication.java
@@ -18,8 +18,9 @@
  */
 package org.apache.cxf.systest.jaxrs;
 
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.ws.rs.ApplicationPath;
@@ -30,6 +31,7 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 import org.apache.cxf.jaxrs.validation.JAXRSBeanValidationFeature;
 import org.apache.cxf.jaxrs.validation.ValidationExceptionMapper;
 import org.apache.cxf.systests.cdi.base.BookStore;
+import org.apache.cxf.systests.cdi.base.BookStoreByIds;
 
 @ApplicationPath("/v2")
 public class BookStoreCustomApplication extends Application {
@@ -44,6 +46,6 @@ public class BookStoreCustomApplication extends Application {
 
     @Override
     public Set<Class<?>> getClasses() {
-        return Collections.<Class<?>>singleton(BookStore.class);
+        return new LinkedHashSet<>(Arrays.asList(BookStore.class, BookStoreByIds.class));
     }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <co...@cxf.apache.org>'].