You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/09/07 13:24:35 UTC

[cxf] branch master updated: Add a systest for passing the service bean to the CXFNonSpringJaxrsServlet

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

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 00bbd66  Add a systest for passing the service bean to the CXFNonSpringJaxrsServlet
00bbd66 is described below

commit 00bbd66cfe7e70f344e2b4940fef63bf345e5435
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Sep 7 14:24:12 2018 +0100

    Add a systest for passing the service bean to the CXFNonSpringJaxrsServlet
---
 .../jaxrs/servlet/CXFNonSpringJaxrsServlet.java    | 22 ++++++-
 .../jaxrs/JAXRSNonSpringJaxrsServletTest.java      | 53 ++++++++++++++++
 .../jaxrs/NonSpringJaxrsServletBookServer.java     | 72 ++++++++++++++++++++++
 3 files changed, 145 insertions(+), 2 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
index a382add..75a4493 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
@@ -417,9 +417,9 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
         if (scope == null) {
             scope = (String)app.getProperties().get(SERVICE_SCOPE_PARAM);
         }
-        return SERVICE_SCOPE_SINGLETON.equals(scope);    
+        return SERVICE_SCOPE_SINGLETON.equals(scope);
     }
-    
+
     protected Object createSingletonInstance(Class<?> cls, Map<String, List<String>> props, ServletConfig sc)
         throws ServletException {
         Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
@@ -517,6 +517,12 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
             setExtensions(bean, servletConfig);
             setDocLocation(bean, servletConfig);
             setSchemasLocations(bean, servletConfig);
+
+            List<?> providers = getProviders(servletConfig, splitChar);
+            bean.setProviders(providers);
+            List<? extends Feature> features = getFeatures(servletConfig, splitChar);
+            bean.setFeatures(features);
+
             bean.setBus(getBus());
             bean.setApplicationInfo(providerApp);
             bean.create();
@@ -538,6 +544,18 @@ public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
                                           getStaticSubResolutionValue(servletConfig),
                                           isAppResourceLifecycleASingleton(app, servletConfig),
                                           getBus());
+        String splitChar = getParameterSplitChar(servletConfig);
+        setAllInterceptors(bean, servletConfig, splitChar);
+        setInvoker(bean, servletConfig);
+        setExtensions(bean, servletConfig);
+        setDocLocation(bean, servletConfig);
+        setSchemasLocations(bean, servletConfig);
+
+        List<?> providers = getProviders(servletConfig, splitChar);
+        bean.setProviders(providers);
+        List<? extends Feature> features = getFeatures(servletConfig, splitChar);
+        bean.setFeatures(features);
+
         bean.setBus(getBus());
         bean.setApplication(getApplication());
         bean.create();
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSNonSpringJaxrsServletTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSNonSpringJaxrsServletTest.java
new file mode 100644
index 0000000..aff70bc
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSNonSpringJaxrsServletTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.systest.jaxrs;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * A test for launching the JAX-RS service using CXFNonSpringJaxrsServlet
+ */
+public class JAXRSNonSpringJaxrsServletTest extends AbstractBusClientServerTestBase {
+    public static final String PORT = NonSpringJaxrsServletBookServer.PORT;
+    public static final String PORT2 = allocatePort(JAXRSNonSpringJaxrsServletTest.class);
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly",
+                   launchServer(NonSpringJaxrsServletBookServer.class, true));
+        createStaticBus();
+    }
+
+    @Test
+    public void testGetBookRoot() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/;JSESSIONID=xxx";
+        WebClient wc = WebClient.create(address);
+        Book book = wc.get(Book.class);
+        assertEquals(124L, book.getId());
+        assertEquals("root", book.getName());
+    }
+
+}
\ No newline at end of file
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NonSpringJaxrsServletBookServer.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NonSpringJaxrsServletBookServer.java
new file mode 100644
index 0000000..7ff828e
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/NonSpringJaxrsServletBookServer.java
@@ -0,0 +1,72 @@
+/**
+ * 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.systest.jaxrs;
+
+import org.apache.cxf.ext.logging.LoggingInInterceptor;
+import org.apache.cxf.ext.logging.LoggingOutInterceptor;
+import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+public class NonSpringJaxrsServletBookServer extends AbstractBusTestServerBase {
+    public static final String PORT = allocatePort(NonSpringJaxrsServletBookServer.class);
+    private org.eclipse.jetty.server.Server server;
+
+    protected void run() {
+        server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
+
+        final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet(new BookStore()));
+        final ServletContextHandler context = new ServletContextHandler();
+        context.setContextPath("/");
+        context.addServlet(servletHolder, "/*");
+        //servletHolder.setInitParameter("jaxrs.serviceClasses", BookStore.class.getName());
+        servletHolder.setInitParameter("jaxrs.outInterceptors", LoggingOutInterceptor.class.getName());
+        servletHolder.setInitParameter("jaxrs.inInterceptors", LoggingInInterceptor.class.getName());
+
+        server.setHandler(context);
+        try {
+            server.start();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    public void tearDown() throws Exception {
+        if (server != null) {
+            server.stop();
+            server.destroy();
+            server = null;
+        }
+    }
+
+    public static void main(String[] args) {
+        try {
+            NonSpringJaxrsServletBookServer s = new NonSpringJaxrsServletBookServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}