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 2019/10/26 22:23:35 UTC

[cxf] branch 3.3.x-fixes updated (fe76246 -> d1dd2ad)

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

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


    from fe76246  CXF-8137 - Using SecurityConstants.VALIDATE_TOKEN with WSS4JInInterceptor no longer allows skipping validation of token
     new 3815898  CXF-8130: Since Spring 5.1.5 Release CXFServlet application listener dissapears by context refresh
     new d1dd2ad  Recording .gitmergeinfo Changes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmergeinfo                                      |   1 +
 .../apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java |   1 +
 .../apache/cxf/transport/servlet/CXFServlet.java   |  23 +++++
 .../systest/servlet/SpringServletContextTest.java  | 102 +++++++++++++++++++++
 .../cxf/systest/servlet/web-spring-context.xml     |   9 +-
 5 files changed, 132 insertions(+), 4 deletions(-)
 create mode 100644 systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
 copy distribution/src/main/release/samples/jax_rs/websocket_web/src/main/webapp/WEB-INF/web.xml => systests/transports/src/test/resources/org/apache/cxf/systest/servlet/web-spring-context.xml (84%)


[cxf] 02/02: Recording .gitmergeinfo Changes

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d1dd2addf2f819ba4ebb0048cf0176ce15050b84
Author: reta <dr...@gmail.com>
AuthorDate: Sat Oct 26 18:22:20 2019 -0400

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 56e226b..75c6cf7 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -42,6 +42,7 @@ M 3b119ca6630f1384b93cd718d0cd95ccabc81e91
 M 5aa0660a9fe324e5c8f36e47e270971d0e85b6f8
 M 9c462e9bd614d529f0a2fd86490243ea1c858651
 M aabf37788e571426e70250e7a62c7f4502e4d6e9
+M c1b729ea9f0c43e6560099dbc427751fe33ee088
 M d875ceee917237f5c344df989947aff025d45d4f
 M e1b81269089d6e7cb53e949a9fde629d37bce421
 M f3e2a52faec1210b1a45eaa36e3812ca03a4969d


[cxf] 01/02: CXF-8130: Since Spring 5.1.5 Release CXFServlet application listener dissapears by context refresh

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 38158988f675b4ad7056cee2bdb8cec081aefbb8
Author: reta <dr...@gmail.com>
AuthorDate: Sat Oct 26 13:49:47 2019 -0400

    CXF-8130: Since Spring 5.1.5 Release CXFServlet application listener dissapears by context refresh
    
    (cherry picked from commit a3849c89cb29e53b336e2e7c1f41752fcc136617)
---
 .../apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java |   1 +
 .../apache/cxf/transport/servlet/CXFServlet.java   |  23 +++++
 .../systest/servlet/SpringServletContextTest.java  | 102 +++++++++++++++++++++
 .../cxf/systest/servlet/web-spring-context.xml     |  43 +++++++++
 4 files changed, 169 insertions(+)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
index e60b9b0..7ffc5b1 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
@@ -144,6 +144,7 @@ public class AbstractJAXRSFactoryBean extends AbstractEndpointFactory {
 
         setTransportId(transportId);
 
+        //EndpointInfo ei = new EndpointInfo(service.getServiceInfos().get(0), transportId);
         EndpointInfo ei = new EndpointInfo();
         ei.setTransportId(transportId);
         ei.setName(serviceFactory.getService().getName());
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
index 6caa5c9..610fe20 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
@@ -20,6 +20,7 @@ package org.apache.cxf.transport.servlet;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Collection;
 
@@ -35,6 +36,7 @@ import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.core.io.Resource;
+import org.springframework.util.ReflectionUtils;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 import org.springframework.web.context.support.XmlWebApplicationContext;
 
@@ -85,6 +87,27 @@ public class CXFServlet extends CXFNonSpringServlet
     }
 
     protected void addListener(AbstractApplicationContext wac) {
+        /**
+         * The change in the way application listeners are maintained during the context refresh 
+         * since Spring Framework 5.1.5 (https://github.com/spring-projects/spring-framework/issues/22325). The
+         * CXF adds listener **after** the context has been refreshed, not much control we have over it, but
+         * it does matter now: the listeners registered after the context refresh disappear when 
+         * context is refreshed. The ugly hack here, to stay in the loop, is to add CXF servlet
+         * to "earlyApplicationListeners" set, only than it will be kept between refreshes.
+         */
+        try {
+            final Field f = ReflectionUtils.findField(wac.getClass(), "earlyApplicationListeners");
+            
+            if (f != null) {
+                Collection<Object> c = CastUtils.cast((Collection<?>)ReflectionUtil.setAccessible(f).get(wac));
+                if (c != null) {
+                    c.add(this);
+                }
+            }
+        } catch (SecurityException | IllegalAccessException e) {
+            //ignore.
+        }
+        
         try {
             //spring 2 vs spring 3 return type is different
             Method m = wac.getClass().getMethod("getApplicationListeners");
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
new file mode 100644
index 0000000..720a407
--- /dev/null
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
@@ -0,0 +1,102 @@
+/**
+ * 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.servlet;
+
+import java.util.Arrays;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletUnitClient;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusException;
+import org.apache.cxf.bus.spring.SpringBus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.DependsOn;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class SpringServletContextTest extends AbstractServletTest {
+    @Configuration
+    public static class AppConfig {
+        @Bean(destroyMethod = "shutdown")
+        public SpringBus cxf() {
+            return new SpringBus();
+        }
+        
+        @Bean @DependsOn("cxf")
+        public Server jaxRsServer() {
+            final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); 
+            factory.setServiceBeans(Arrays.asList(contextRestService()));
+            factory.setAddress("/services/context");
+            return factory.create();
+        }
+
+        @Bean
+        public ContextRestService contextRestService() {
+            return new ContextRestService();
+        }
+    }
+    
+    @Path("/") 
+    public static class ContextRestService {
+        @Autowired 
+        private ConfigurableApplicationContext context;
+        
+        @GET
+        @Path("/refresh")
+        public void refresh() {
+            context.refresh();
+        }
+    }
+    
+    @Override
+    protected String getConfiguration() {
+        return "/org/apache/cxf/systest/servlet/web-spring-context.xml";
+    }
+
+    @Override
+    protected Bus createBus() throws BusException {
+        // don't set up the bus, let the servlet do it
+        return null;
+    }
+
+    @Test
+    public void testContextRefresh() throws Exception {
+        ServletUnitClient client = newClient();
+        client.setExceptionsThrownOnErrorStatus(true);
+
+        for (int i = 0; i < 5; ++i) {
+            final WebRequest request = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/context/refresh");
+            final WebResponse response = client.getResponse(request);
+            assertThat(response.getResponseCode(), equalTo(204));
+        }
+    }
+}
\ No newline at end of file
diff --git a/systests/transports/src/test/resources/org/apache/cxf/systest/servlet/web-spring-context.xml b/systests/transports/src/test/resources/org/apache/cxf/systest/servlet/web-spring-context.xml
new file mode 100644
index 0000000..281bea6
--- /dev/null
+++ b/systests/transports/src/test/resources/org/apache/cxf/systest/servlet/web-spring-context.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!--
+        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.
+-->
+<web-app>
+    <context-param>
+        <param-name>contextClass</param-name>
+        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
+    </context-param>
+    <context-param>
+        <param-name>contextConfigLocation</param-name>
+        <param-value>org.apache.cxf.systest.servlet.SpringServletContextTest$AppConfig</param-value>
+    </context-param>
+    <listener>
+        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+    </listener>
+    <servlet>
+        <servlet-name>CXFServlet</servlet-name>
+        <display-name>CXF Servlet</display-name>
+        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>CXFServlet</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>