You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2014/01/15 09:54:00 UTC
svn commit: r1558322 - in /cxf/trunk/rt/transports: http-hc/
http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/
http/src/main/java/org/apache/cxf/transport/http/osgi/
http/src/main/resources/OSGI-INF/
Author: cschneider
Date: Wed Jan 15 08:53:59 2014
New Revision: 1558322
URL: http://svn.apache.org/r1558322
Log:
CXF-4736 Switching the blueprint files for http and http-hc to activators to allow running without blueprint
Added:
cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
Removed:
cxf/trunk/rt/transports/http/src/main/resources/OSGI-INF/
Modified:
cxf/trunk/rt/transports/http-hc/pom.xml
cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java
Modified: cxf/trunk/rt/transports/http-hc/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/pom.xml?rev=1558322&r1=1558321&r2=1558322&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/pom.xml (original)
+++ cxf/trunk/rt/transports/http-hc/pom.xml Wed Jan 15 08:53:59 2014
@@ -20,7 +20,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cxf-rt-transports-http-hc</artifactId>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<name>Apache CXF Runtime HTTP Async Transport</name>
<description>Apache CXF Runtime HTTP Async Transport</description>
<url>http://cxf.apache.org</url>
@@ -31,14 +31,10 @@
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
<properties>
+ <cxf.bundle.activator>org.apache.cxf.transport.http.asyncclient.Activator</cxf.bundle.activator>
<cxf.osgi.import>
- org.apache.http.nio.conn;version="${cxf.httpcomponents.asyncclient.version.range}",
- org.apache.http.nio.conn.scheme;version="${cxf.httpcomponents.asyncclient.version.range}",
- org.apache.http.nio.conn.ssl;version="${cxf.httpcomponents.asyncclient.version.range}",
- org.apache.http.impl.nio.client;version="${cxf.httpcomponents.asyncclient.version.range}",
- org.apache.http.impl.nio.conn;version="${cxf.httpcomponents.asyncclient.version.range}",
- org.apache.http.*;version="${cxf.httpcomponents.core.version.range}",
javax.annotation;version="${cxf.osgi.javax.annotation.version}",
+ *
</cxf.osgi.import>
</properties>
<dependencies>
@@ -53,6 +49,18 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ <optional/>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ <optional/>
+ </dependency>
+ <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>${project.version}</version>
Added: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java?rev=1558322&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java (added)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java Wed Jan 15 08:53:59 2014
@@ -0,0 +1,98 @@
+/**
+ * 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.transport.http.asyncclient;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.transport.http.HTTPConduitFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class Activator implements BundleActivator {
+
+ private ServiceTracker tracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ tracker = new ServiceTracker(context, Bus.class.getName(), null);
+ tracker.open();
+ ConduitConfigurer conduitConfigurer = new ConduitConfigurer(context, tracker);
+ registerManagedService(context, conduitConfigurer, "org.apache.cxf.transport.http.async");
+ }
+
+ private void registerManagedService(BundleContext context, ConduitConfigurer conduitConfigurer, String servicePid) {
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_PID, servicePid);
+ context.registerService(ManagedService.class.getName(), conduitConfigurer, properties);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ tracker.close();
+ }
+
+ class ConduitConfigurer implements ManagedService {
+ private AsyncHTTPConduitFactory conduitFactory;
+ private ServiceTracker busTracker;
+ private BundleContext context;
+ private ServiceRegistration reg;
+
+ public ConduitConfigurer(BundleContext context, ServiceTracker busTracker) {
+ this.context = context;
+ this.busTracker = busTracker;
+ }
+
+ @SuppressWarnings({
+ "rawtypes", "unchecked"
+ })
+ @Override
+ public void updated(Dictionary properties) throws ConfigurationException {
+ if (reg != null) {
+ reg.unregister();
+ }
+ conduitFactory = new AsyncHTTPConduitFactory((Bus)this.busTracker.getService());
+ conduitFactory.update(toMap(properties));
+ reg = context.registerService(HTTPConduitFactory.class.getName(), conduitFactory, null);
+ }
+
+ private Map<String, Object> toMap(Dictionary<String, ?> properties) {
+ Map<String, Object> props = new HashMap<String, Object>();
+ if (properties == null) {
+ return props;
+ }
+ Enumeration<String> keys = properties.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ props.put(key, properties.get(key));
+ }
+ return props;
+ }
+
+ }
+}
Modified: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java?rev=1558322&r1=1558321&r2=1558322&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java Wed Jan 15 08:53:59 2014
@@ -67,7 +67,6 @@ import org.apache.http.protocol.HttpCont
*/
@NoJSR250Annotations(unlessNull = "bus")
public class AsyncHTTPConduitFactory implements BusLifeCycleListener, HTTPConduitFactory {
-
//TCP related properties
public static final String TCP_NODELAY = "org.apache.cxf.transport.http.async.TCP_NODELAY";
Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java?rev=1558322&r1=1558321&r2=1558322&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java Wed Jan 15 08:53:59 2014
@@ -19,36 +19,45 @@
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.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.http.DestinationRegistryImpl;
import org.apache.cxf.transport.http.HTTPConduitConfigurer;
+import org.apache.cxf.transport.http.HTTPTransportFactory;
import org.apache.cxf.transport.http.blueprint.HttpBPHandler;
+import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
import org.osgi.service.cm.ManagedServiceFactory;
public class HTTPTransportActivator
implements BundleActivator {
- ServiceRegistration reg;
- ServiceRegistration reg2;
-
public void start(BundleContext context) throws Exception {
ConfigAdminHttpConduitConfigurer conduitConfigurer = new ConfigAdminHttpConduitConfigurer();
+ DestinationRegistry destinationRegistry = new DestinationRegistryImpl();
+ HTTPTransportFactory transportFactory = new HTTPTransportFactory(destinationRegistry);
+ Servlet servlet = new CXFNonSpringServlet(destinationRegistry , false);
+ ServletConfigurer servletConfig = new ServletConfigurer(context, servlet);
+
+ registerService(context, ManagedServiceFactory.class, conduitConfigurer,
+ ConfigAdminHttpConduitConfigurer.FACTORY_PID);
+ registerService(context, HTTPConduitConfigurer.class, conduitConfigurer,
+ "org.apache.cxf.http.conduit-configurer");
+ context.registerService(DestinationRegistry.class.getName(), destinationRegistry, null);
+ context.registerService(HTTPTransportFactory.class.getName(), transportFactory, null);
+ registerService(context, ManagedService.class, servletConfig, "org.apache.cxf.osgi");
- Properties servProps = new Properties();
- servProps.put(Constants.SERVICE_PID, ConfigAdminHttpConduitConfigurer.FACTORY_PID);
- reg2 = context.registerService(ManagedServiceFactory.class.getName(),
- conduitConfigurer, servProps);
-
- servProps = new Properties();
- servProps.put(Constants.SERVICE_PID, "org.apache.cxf.http.conduit-configurer");
- reg = context.registerService(HTTPConduitConfigurer.class.getName(),
- conduitConfigurer, servProps);
BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() {
@Override
@@ -60,9 +69,71 @@ public class HTTPTransportActivator
"http://cxf.apache.org/transports/http/configuration");
}
+ private void registerService(BundleContext context, Class<?> serviceInterface,
+ Object serviceObject, String servicePid) {
+ Properties servProps = new Properties();
+ servProps.put(Constants.SERVICE_PID, servicePid);
+ context.registerService(serviceInterface.getName(), serviceObject, servProps);
+ }
+
public void stop(BundleContext context) throws Exception {
- reg.unregister();
- reg2.unregister();
}
+
+ class ServletConfigurer implements ManagedService {
+ private ServiceRegistration reg;
+ private BundleContext context;
+ private Servlet servlet;
+
+ public ServletConfigurer(BundleContext context, Servlet servlet) {
+ this.servlet = servlet;
+ this.context = context;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public void updated(Dictionary properties) throws ConfigurationException {
+ if (reg != null) {
+ reg.unregister();
+ }
+ if (properties == null) {
+ properties = new Properties();
+ }
+ Properties sprops = new Properties();
+ 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("hide-service-list-page",
+ 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", "false"));
+ sprops.put("base-address",
+ getProp(properties, "org.apache.cxf.servlet.base-address", ""));
+ sprops.put("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", ""));
+ sprops.put("redirects-list",
+ getProp(properties, "org.apache.cxf.servlet.redirects-list", ""));
+ sprops.put("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", ""));
+ sprops.put("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"));
+ sprops.put("service-list-page-authenticate-realm",
+ getProp(properties, "org.apache.cxf.servlet.service-list-page-authenticate-realm", "karaf"));
+ context.registerService(Servlet.class.getName(), servlet, sprops);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private Object getProp(Dictionary properties, String key, Object defaultValue) {
+ Object value = properties.get(key);
+ return value == null ? defaultValue : value;
+ }
+
+ }
}