You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by rm...@apache.org on 2020/09/22 15:54:55 UTC
[aries-jax-rs-whiteboard] branch master updated: [ARIES-2002] test
for unproxying of getSingletons
This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new a1d59be [ARIES-2002] test for unproxying of getSingletons
a1d59be is described below
commit a1d59beeb65264322846d25093f1a0b32fa2188c
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Tue Sep 22 17:50:18 2020 +0200
[ARIES-2002] test for unproxying of getSingletons
---
.../internal/cxf/CxfJaxrsServiceRegistrator.java | 5 +-
.../cxf/CxfJaxrsServiceRegistratorTest.java | 65 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java
index 22dfc88..760a94a 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java
@@ -30,7 +30,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -46,7 +45,6 @@ import javax.ws.rs.core.Application;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Provider;
-import javax.ws.rs.ext.RuntimeDelegate;
import org.apache.aries.component.dsl.CachingServiceReference;
import org.apache.aries.component.dsl.OSGi;
@@ -269,6 +267,9 @@ public class CxfJaxrsServiceRegistrator {
bean.getProperties(true).putAll(appProps);
}
bean.setApplication(app);
+ if (_bus != null) {
+ bean.setBus(_bus);
+ }
if (JAXRSServerFactoryBean.class.isAssignableFrom(endpointType)) {
return endpointType.cast(bean);
diff --git a/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistratorTest.java b/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistratorTest.java
new file mode 100644
index 0000000..3013cdd
--- /dev/null
+++ b/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistratorTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.aries.jax.rs.whiteboard.internal.cxf;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.junit.Test;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import java.util.Set;
+
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.singleton;
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CxfJaxrsServiceRegistratorTest {
+ @Test
+ public void unproxy() {
+ final JAXRSServerFactoryBean bean = new CxfJaxrsServiceRegistrator(
+ null, null, emptyMap(), null
+ ).createEndpoint(new Application() {
+ @Override
+ public Set<Object> getSingletons() {
+ return singleton(new MyResource$$Proxy());
+ }
+ }, JAXRSServerFactoryBean.class);
+ bean.setStart(false);
+ bean.create();
+ assertEquals(singletonList(MyResource.class), bean.getResourceClasses());
+ final ClassResourceInfo cri = bean.getServiceFactory().getClassResourceInfo().iterator().next();
+ assertEquals(MyResource.class, cri.getServiceClass());
+ assertEquals(MyResource.class, cri.getResourceClass());
+ assertTrue(SingletonResourceProvider.class.isInstance(cri.getResourceProvider()));
+ }
+
+ @Path("my")
+ public static class MyResource {
+ @GET
+ public String get() {
+ return "";
+ }
+ }
+
+ public static class MyResource$$Proxy extends MyResource {
+ }
+}