From 8b7126cd89dc74ac57b8a82d55d56d6577d505c9 Mon Sep 17 00:00:00 2001 From: James Carman Date: Mon, 17 Aug 2015 23:18:25 -0400 Subject: [PATCH 1/4] CXF-6547: HTTPTransportActivator Does Not Propagate Servlet Init Parameters --- .../http/osgi/HTTPTransportActivator.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java index c01afb4bf37..fb8edf01e30 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java @@ -19,11 +19,6 @@ package org.apache.cxf.transport.http.osgi; -import java.util.Dictionary; -import java.util.Properties; - -import javax.servlet.Servlet; - import org.apache.cxf.bus.blueprint.BlueprintNameSpaceHandlerFactory; import org.apache.cxf.bus.blueprint.NamespaceHandlerRegisterer; import org.apache.cxf.common.util.PropertyUtils; @@ -41,6 +36,10 @@ import org.osgi.service.cm.ManagedService; import org.osgi.service.cm.ManagedServiceFactory; +import javax.servlet.Servlet; +import java.util.Dictionary; +import java.util.Properties; + public class HTTPTransportActivator implements BundleActivator { private static final String CXF_CONFIG_SCOPE = "org.apache.cxf.osgi"; @@ -117,33 +116,34 @@ public void updated(Dictionary properties) throws ConfigurationException { getProp(properties, "org.apache.cxf.servlet.context", "/cxf")); sprops.put("servlet-name", getProp(properties, "org.apache.cxf.servlet.name", "cxf-osgi-transport-servlet")); - sprops.put("hide-service-list-page", + sprops.put("init.hide-service-list-page", getProp(properties, "org.apache.cxf.servlet.hide-service-list-page", "false")); - sprops.put("disable-address-updates", + sprops.put("init.disable-address-updates", getProp(properties, "org.apache.cxf.servlet.disable-address-updates", "true")); - sprops.put("base-address", + sprops.put("init.base-address", getProp(properties, "org.apache.cxf.servlet.base-address", "")); - sprops.put("service-list-path", + sprops.put("init.service-list-path", getProp(properties, "org.apache.cxf.servlet.service-list-path", "")); - sprops.put("static-resources-list", + sprops.put("init.static-resources-list", getProp(properties, "org.apache.cxf.servlet.static-resources-list", "")); - sprops.put("redirects-list", + sprops.put("init.redirects-list", getProp(properties, "org.apache.cxf.servlet.redirects-list", "")); - sprops.put("redirect-servlet-name", + sprops.put("init.redirect-servlet-name", getProp(properties, "org.apache.cxf.servlet.redirect-servlet-name", "")); - sprops.put("redirect-servlet-path", + sprops.put("init.redirect-servlet-path", getProp(properties, "org.apache.cxf.servlet.redirect-servlet-path", "")); - sprops.put("service-list-all-contexts", + sprops.put("init.service-list-all-contexts", getProp(properties, "org.apache.cxf.servlet.service-list-all-contexts", "")); - sprops.put("service-list-page-authenticate", + sprops.put("init.service-list-page-authenticate", getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate", "false")); - sprops.put("service-list-page-authenticate-realm", + sprops.put("init.service-list-page-authenticate-realm", getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf")); - sprops.put("use-x-forwarded-headers", + sprops.put("init.use-x-forwarded-headers", getProp(properties, "org.apache.cxf.servlet.use-x-forwarded-headers", "false")); if (serviceRegistration != null) { serviceRegistration.unregister(); } + serviceRegistration = context.registerService(Servlet.class.getName(), servlet, sprops); } From c074be36cf388a9febe7925153bc604c55f25bb4 Mon Sep 17 00:00:00 2001 From: James Carman Date: Tue, 18 Aug 2015 09:27:24 -0400 Subject: [PATCH 2/4] CXF-6547: HTTPTransportActivator Does Not Propagate Servlet Init Parameters - Trying the init-prefix = "" approach. --- .../http/osgi/HTTPTransportActivator.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java index fb8edf01e30..749b33c0b53 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java @@ -112,33 +112,35 @@ public void updated(Dictionary properties) throws ConfigurationException { properties = new Properties(); } Properties sprops = new Properties(); + sprops.put("init-prefix", ""); + sprops.put("alias", getProp(properties, "org.apache.cxf.servlet.context", "/cxf")); sprops.put("servlet-name", getProp(properties, "org.apache.cxf.servlet.name", "cxf-osgi-transport-servlet")); - sprops.put("init.hide-service-list-page", + sprops.put("hide-service-list-page", getProp(properties, "org.apache.cxf.servlet.hide-service-list-page", "false")); - sprops.put("init.disable-address-updates", + sprops.put("disable-address-updates", getProp(properties, "org.apache.cxf.servlet.disable-address-updates", "true")); - sprops.put("init.base-address", + sprops.put("base-address", getProp(properties, "org.apache.cxf.servlet.base-address", "")); - sprops.put("init.service-list-path", + sprops.put("service-list-path", getProp(properties, "org.apache.cxf.servlet.service-list-path", "")); - sprops.put("init.static-resources-list", + sprops.put("static-resources-list", getProp(properties, "org.apache.cxf.servlet.static-resources-list", "")); - sprops.put("init.redirects-list", + sprops.put("redirects-list", getProp(properties, "org.apache.cxf.servlet.redirects-list", "")); - sprops.put("init.redirect-servlet-name", + sprops.put("redirect-servlet-name", getProp(properties, "org.apache.cxf.servlet.redirect-servlet-name", "")); - sprops.put("init.redirect-servlet-path", + sprops.put("redirect-servlet-path", getProp(properties, "org.apache.cxf.servlet.redirect-servlet-path", "")); - sprops.put("init.service-list-all-contexts", + sprops.put("service-list-all-contexts", getProp(properties, "org.apache.cxf.servlet.service-list-all-contexts", "")); - sprops.put("init.service-list-page-authenticate", + sprops.put("service-list-page-authenticate", getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate", "false")); - sprops.put("init.service-list-page-authenticate-realm", + sprops.put("service-list-page-authenticate-realm", getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf")); - sprops.put("init.use-x-forwarded-headers", + sprops.put("use-x-forwarded-headers", getProp(properties, "org.apache.cxf.servlet.use-x-forwarded-headers", "false")); if (serviceRegistration != null) { serviceRegistration.unregister(); From 717c2c51032b2b36d38d6242c1ce2cac51e79c98 Mon Sep 17 00:00:00 2001 From: James Carman Date: Tue, 18 Aug 2015 09:29:53 -0400 Subject: [PATCH 3/4] CXF-6547: HTTPTransportActivator Does Not Propagate Servlet Init Parameters - Trying the init-prefix = "" approach. --- .../http/osgi/HTTPTransportActivator.java | 82 ++++++++++--------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java index 749b33c0b53..6973450f771 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java @@ -6,9 +6,9 @@ * 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 @@ -19,6 +19,11 @@ package org.apache.cxf.transport.http.osgi; +import java.util.Dictionary; +import java.util.Properties; + +import javax.servlet.Servlet; + import org.apache.cxf.bus.blueprint.BlueprintNameSpaceHandlerFactory; import org.apache.cxf.bus.blueprint.NamespaceHandlerRegisterer; import org.apache.cxf.common.util.PropertyUtils; @@ -36,33 +41,30 @@ import org.osgi.service.cm.ManagedService; import org.osgi.service.cm.ManagedServiceFactory; -import javax.servlet.Servlet; -import java.util.Dictionary; -import java.util.Properties; -public class HTTPTransportActivator - implements BundleActivator { +public class HTTPTransportActivator + implements BundleActivator { private static final String CXF_CONFIG_SCOPE = "org.apache.cxf.osgi"; private static final String DISABLE_DEFAULT_HTTP_TRANSPORT = CXF_CONFIG_SCOPE + ".http.transport.disable"; - + public void start(BundleContext context) throws Exception { - + ConfigAdminHttpConduitConfigurer conduitConfigurer = new ConfigAdminHttpConduitConfigurer(); - - registerService(context, ManagedServiceFactory.class, conduitConfigurer, - ConfigAdminHttpConduitConfigurer.FACTORY_PID); - registerService(context, HTTPConduitConfigurer.class, conduitConfigurer, - "org.apache.cxf.http.conduit-configurer"); - + + registerService(context, ManagedServiceFactory.class, conduitConfigurer, + ConfigAdminHttpConduitConfigurer.FACTORY_PID); + registerService(context, HTTPConduitConfigurer.class, conduitConfigurer, + "org.apache.cxf.http.conduit-configurer"); + if (PropertyUtils.isTrue(context.getProperty(DISABLE_DEFAULT_HTTP_TRANSPORT))) { //TODO: Review if it also makes sense to support "http.transport.disable" // directly in the CXF_CONFIG_SCOPE properties file return; } - + DestinationRegistry destinationRegistry = new DestinationRegistryImpl(); HTTPTransportFactory transportFactory = new HTTPTransportFactory(destinationRegistry); - Servlet servlet = new CXFNonSpringServlet(destinationRegistry , false); + Servlet servlet = new CXFNonSpringServlet(destinationRegistry, false); ServletConfigurer servletConfig = new ServletConfigurer(context, servlet); context.registerService(DestinationRegistry.class.getName(), destinationRegistry, null); @@ -70,33 +72,33 @@ public void start(BundleContext context) throws Exception { registerService(context, ManagedService.class, servletConfig, CXF_CONFIG_SCOPE); BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() { - + @Override public Object createNamespaceHandler() { return new HttpBPHandler(); } }; NamespaceHandlerRegisterer.register(context, factory, - "http://cxf.apache.org/transports/http/configuration"); + "http://cxf.apache.org/transports/http/configuration"); } private void registerService(BundleContext context, Class serviceInterface, - Object serviceObject, String servicePid) { + Object serviceObject, String servicePid) { Properties servProps = new Properties(); - servProps.put(Constants.SERVICE_PID, servicePid); + servProps.put(Constants.SERVICE_PID, servicePid); context.registerService(serviceInterface.getName(), serviceObject, servProps); } public void stop(BundleContext context) throws Exception { } - + class ServletConfigurer implements ManagedService { private ServiceRegistration reg; private BundleContext context; private Servlet servlet; private ServiceRegistration serviceRegistration; - + public ServletConfigurer(BundleContext context, Servlet servlet) { this.servlet = servlet; this.context = context; @@ -113,35 +115,35 @@ public void updated(Dictionary properties) throws ConfigurationException { } Properties sprops = new Properties(); sprops.put("init-prefix", ""); - + sprops.put("alias", - getProp(properties, "org.apache.cxf.servlet.context", "/cxf")); - sprops.put("servlet-name", - getProp(properties, "org.apache.cxf.servlet.name", "cxf-osgi-transport-servlet")); + getProp(properties, "org.apache.cxf.servlet.context", "/cxf")); + sprops.put("servlet-name", + getProp(properties, "org.apache.cxf.servlet.name", "cxf-osgi-transport-servlet")); sprops.put("hide-service-list-page", - getProp(properties, "org.apache.cxf.servlet.hide-service-list-page", "false")); + getProp(properties, "org.apache.cxf.servlet.hide-service-list-page", "false")); sprops.put("disable-address-updates", - getProp(properties, "org.apache.cxf.servlet.disable-address-updates", "true")); + getProp(properties, "org.apache.cxf.servlet.disable-address-updates", "true")); sprops.put("base-address", - getProp(properties, "org.apache.cxf.servlet.base-address", "")); + getProp(properties, "org.apache.cxf.servlet.base-address", "")); sprops.put("service-list-path", - getProp(properties, "org.apache.cxf.servlet.service-list-path", "")); + getProp(properties, "org.apache.cxf.servlet.service-list-path", "")); sprops.put("static-resources-list", - getProp(properties, "org.apache.cxf.servlet.static-resources-list", "")); + getProp(properties, "org.apache.cxf.servlet.static-resources-list", "")); sprops.put("redirects-list", - getProp(properties, "org.apache.cxf.servlet.redirects-list", "")); + getProp(properties, "org.apache.cxf.servlet.redirects-list", "")); sprops.put("redirect-servlet-name", - getProp(properties, "org.apache.cxf.servlet.redirect-servlet-name", "")); + getProp(properties, "org.apache.cxf.servlet.redirect-servlet-name", "")); sprops.put("redirect-servlet-path", - getProp(properties, "org.apache.cxf.servlet.redirect-servlet-path", "")); + getProp(properties, "org.apache.cxf.servlet.redirect-servlet-path", "")); sprops.put("service-list-all-contexts", - getProp(properties, "org.apache.cxf.servlet.service-list-all-contexts", "")); + getProp(properties, "org.apache.cxf.servlet.service-list-all-contexts", "")); sprops.put("service-list-page-authenticate", - getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate", "false")); + getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate", "false")); sprops.put("service-list-page-authenticate-realm", - getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf")); + getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf")); sprops.put("use-x-forwarded-headers", - getProp(properties, "org.apache.cxf.servlet.use-x-forwarded-headers", "false")); + getProp(properties, "org.apache.cxf.servlet.use-x-forwarded-headers", "false")); if (serviceRegistration != null) { serviceRegistration.unregister(); } @@ -154,6 +156,6 @@ private Object getProp(Dictionary properties, String key, Object defaultValue) { Object value = properties.get(key); return value == null ? defaultValue : value; } - + } } From 786b14e1cef0ffab273f16a0cad047f9a8e91187 Mon Sep 17 00:00:00 2001 From: James Carman Date: Tue, 18 Aug 2015 09:30:34 -0400 Subject: [PATCH 4/4] CXF-6547: HTTPTransportActivator Does Not Propagate Servlet Init Parameters - Trying the init-prefix = "" approach. --- .../http/osgi/HTTPTransportActivator.java | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java index 6973450f771..976c7309bab 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java @@ -6,9 +6,9 @@ * 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 @@ -41,30 +41,29 @@ import org.osgi.service.cm.ManagedService; import org.osgi.service.cm.ManagedServiceFactory; - -public class HTTPTransportActivator - implements BundleActivator { +public class HTTPTransportActivator + implements BundleActivator { private static final String CXF_CONFIG_SCOPE = "org.apache.cxf.osgi"; private static final String DISABLE_DEFAULT_HTTP_TRANSPORT = CXF_CONFIG_SCOPE + ".http.transport.disable"; - + public void start(BundleContext context) throws Exception { - + ConfigAdminHttpConduitConfigurer conduitConfigurer = new ConfigAdminHttpConduitConfigurer(); - - registerService(context, ManagedServiceFactory.class, conduitConfigurer, - ConfigAdminHttpConduitConfigurer.FACTORY_PID); - registerService(context, HTTPConduitConfigurer.class, conduitConfigurer, - "org.apache.cxf.http.conduit-configurer"); - + + registerService(context, ManagedServiceFactory.class, conduitConfigurer, + ConfigAdminHttpConduitConfigurer.FACTORY_PID); + registerService(context, HTTPConduitConfigurer.class, conduitConfigurer, + "org.apache.cxf.http.conduit-configurer"); + if (PropertyUtils.isTrue(context.getProperty(DISABLE_DEFAULT_HTTP_TRANSPORT))) { //TODO: Review if it also makes sense to support "http.transport.disable" // directly in the CXF_CONFIG_SCOPE properties file return; } - + DestinationRegistry destinationRegistry = new DestinationRegistryImpl(); HTTPTransportFactory transportFactory = new HTTPTransportFactory(destinationRegistry); - Servlet servlet = new CXFNonSpringServlet(destinationRegistry, false); + Servlet servlet = new CXFNonSpringServlet(destinationRegistry , false); ServletConfigurer servletConfig = new ServletConfigurer(context, servlet); context.registerService(DestinationRegistry.class.getName(), destinationRegistry, null); @@ -72,33 +71,33 @@ public void start(BundleContext context) throws Exception { registerService(context, ManagedService.class, servletConfig, CXF_CONFIG_SCOPE); BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() { - + @Override public Object createNamespaceHandler() { return new HttpBPHandler(); } }; NamespaceHandlerRegisterer.register(context, factory, - "http://cxf.apache.org/transports/http/configuration"); + "http://cxf.apache.org/transports/http/configuration"); } private void registerService(BundleContext context, Class serviceInterface, - Object serviceObject, String servicePid) { + Object serviceObject, String servicePid) { Properties servProps = new Properties(); - servProps.put(Constants.SERVICE_PID, servicePid); + servProps.put(Constants.SERVICE_PID, servicePid); context.registerService(serviceInterface.getName(), serviceObject, servProps); } public void stop(BundleContext context) throws Exception { } - + class ServletConfigurer implements ManagedService { private ServiceRegistration reg; private BundleContext context; private Servlet servlet; private ServiceRegistration serviceRegistration; - + public ServletConfigurer(BundleContext context, Servlet servlet) { this.servlet = servlet; this.context = context; @@ -115,35 +114,35 @@ public void updated(Dictionary properties) throws ConfigurationException { } Properties sprops = new Properties(); sprops.put("init-prefix", ""); - + sprops.put("alias", - getProp(properties, "org.apache.cxf.servlet.context", "/cxf")); - sprops.put("servlet-name", - getProp(properties, "org.apache.cxf.servlet.name", "cxf-osgi-transport-servlet")); + getProp(properties, "org.apache.cxf.servlet.context", "/cxf")); + sprops.put("servlet-name", + getProp(properties, "org.apache.cxf.servlet.name", "cxf-osgi-transport-servlet")); sprops.put("hide-service-list-page", - getProp(properties, "org.apache.cxf.servlet.hide-service-list-page", "false")); + getProp(properties, "org.apache.cxf.servlet.hide-service-list-page", "false")); sprops.put("disable-address-updates", - getProp(properties, "org.apache.cxf.servlet.disable-address-updates", "true")); + getProp(properties, "org.apache.cxf.servlet.disable-address-updates", "true")); sprops.put("base-address", - getProp(properties, "org.apache.cxf.servlet.base-address", "")); + getProp(properties, "org.apache.cxf.servlet.base-address", "")); sprops.put("service-list-path", - getProp(properties, "org.apache.cxf.servlet.service-list-path", "")); + getProp(properties, "org.apache.cxf.servlet.service-list-path", "")); sprops.put("static-resources-list", - getProp(properties, "org.apache.cxf.servlet.static-resources-list", "")); + getProp(properties, "org.apache.cxf.servlet.static-resources-list", "")); sprops.put("redirects-list", - getProp(properties, "org.apache.cxf.servlet.redirects-list", "")); + getProp(properties, "org.apache.cxf.servlet.redirects-list", "")); sprops.put("redirect-servlet-name", - getProp(properties, "org.apache.cxf.servlet.redirect-servlet-name", "")); + getProp(properties, "org.apache.cxf.servlet.redirect-servlet-name", "")); sprops.put("redirect-servlet-path", - getProp(properties, "org.apache.cxf.servlet.redirect-servlet-path", "")); + getProp(properties, "org.apache.cxf.servlet.redirect-servlet-path", "")); sprops.put("service-list-all-contexts", - getProp(properties, "org.apache.cxf.servlet.service-list-all-contexts", "")); + getProp(properties, "org.apache.cxf.servlet.service-list-all-contexts", "")); sprops.put("service-list-page-authenticate", - getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate", "false")); + getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate", "false")); sprops.put("service-list-page-authenticate-realm", - getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf")); + getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf")); sprops.put("use-x-forwarded-headers", - getProp(properties, "org.apache.cxf.servlet.use-x-forwarded-headers", "false")); + getProp(properties, "org.apache.cxf.servlet.use-x-forwarded-headers", "false")); if (serviceRegistration != null) { serviceRegistration.unregister(); } @@ -156,6 +155,6 @@ private Object getProp(Dictionary properties, String key, Object defaultValue) { Object value = properties.get(key); return value == null ? defaultValue : value; } - + } }