Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C8CC69638 for ; Fri, 27 Jan 2012 21:20:30 +0000 (UTC) Received: (qmail 96119 invoked by uid 500); 27 Jan 2012 21:20:30 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 96046 invoked by uid 500); 27 Jan 2012 21:20:30 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 96039 invoked by uid 99); 27 Jan 2012 21:20:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jan 2012 21:20:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jan 2012 21:20:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4CDEB2388A67 for ; Fri, 27 Jan 2012 21:20:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1236893 - in /cxf/trunk/rt/transports/http: ./ src/main/java/org/apache/cxf/transport/http/ src/main/java/org/apache/cxf/transport/http/osgi/ Date: Fri, 27 Jan 2012 21:20:04 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120127212004.4CDEB2388A67@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Fri Jan 27 21:20:03 2012 New Revision: 1236893 URL: http://svn.apache.org/viewvc?rev=1236893&view=rev Log: Add ability to start configuring some conduit settings via config:admin Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java (with props) cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java (with props) Modified: cxf/trunk/rt/transports/http/pom.xml cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java Modified: cxf/trunk/rt/transports/http/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/pom.xml?rev=1236893&r1=1236892&r2=1236893&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/pom.xml (original) +++ cxf/trunk/rt/transports/http/pom.xml Fri Jan 27 21:20:03 2012 @@ -33,6 +33,7 @@ ../../../parent/pom.xml + org.apache.cxf.transport.http.osgi.HTTPTransportActivator javax.servlet*;version="${cxf.osgi.javax.servlet.version}", @@ -54,6 +55,16 @@ test + org.osgi + org.osgi.core + provided + + + org.osgi + org.osgi.compendium + provided + + org.apache.cxf cxf-api ${project.version} Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java?rev=1236893&view=auto ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java (added) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java Fri Jan 27 21:20:03 2012 @@ -0,0 +1,28 @@ +/** + * 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; + +/** + * + */ +public interface HTTPConduitConfigurer { + + void configure(String name, String address, HTTPConduit c); +} Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduitConfigurer.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java?rev=1236893&r1=1236892&r2=1236893&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java (original) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java Fri Jan 27 21:20:03 2012 @@ -253,6 +253,10 @@ public class HTTPTransportFactory if (address != null && address.indexOf('?') != -1) { address = address.substring(0, address.indexOf('?')); } + HTTPConduitConfigurer c1 = bus.getExtension(HTTPConduitConfigurer.class); + if (c1 != null) { + c1.configure(conduit.getBeanName(), address, conduit); + } configure(conduit, conduit.getBeanName(), address); conduit.finalizeConfig(); return conduit; Added: 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=1236893&view=auto ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java (added) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java Fri Jan 27 21:20:03 2012 @@ -0,0 +1,288 @@ +/** + * 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.osgi; + +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.cxf.configuration.jsse.TLSClientParameters; +import org.apache.cxf.configuration.security.AuthorizationPolicy; +import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transport.http.HTTPConduitConfigurer; +import org.apache.cxf.transports.http.configuration.ConnectionType; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; +import org.apache.cxf.transports.http.configuration.ProxyServerType; +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.ConfigurationAdmin; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedServiceFactory; +import org.osgi.util.tracker.ServiceTracker; + +/** + * + */ +public class HTTPTransportActivator + implements BundleActivator, ManagedServiceFactory, HTTPConduitConfigurer { + public static final String FACTORY_PID = "org.apache.cxf.http.conduits"; + + + ServiceTracker configAdminTracker; + ServiceRegistration reg; + ServiceRegistration reg2; + Map> props + = new ConcurrentHashMap>(); + Map matchers = new IdentityHashMap(); + + public void start(BundleContext context) throws Exception { + Properties servProps = new Properties(); + servProps.put(Constants.SERVICE_PID, FACTORY_PID); + reg2 = context.registerService(ManagedServiceFactory.class.getName(), + this, servProps); + + servProps = new Properties(); + servProps.put(Constants.SERVICE_PID, "org.apache.cxf.http.conduit-configurer"); + reg = context.registerService(HTTPConduitConfigurer.class.getName(), + this, servProps); + + configAdminTracker = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null); + configAdminTracker.open(); + } + + public void stop(BundleContext context) throws Exception { + reg.unregister(); + reg2.unregister(); + configAdminTracker.close(); + } + + @Override + public String getName() { + return FACTORY_PID; + } + + @SuppressWarnings("unchecked") + @Override + public void updated(String pid, @SuppressWarnings("rawtypes") Dictionary properties) + throws ConfigurationException { + if (pid == null) { + return; + } + String url = (String)properties.get("url"); + String name = (String)properties.get("name"); + + props.put(pid, properties); + if (url != null) { + props.put(url, properties); + Matcher matcher = Pattern.compile(url).matcher(""); + synchronized (matchers) { + matchers.put(matcher, pid); + } + } + if (name != null) { + props.put(name, properties); + } + + } + + @Override + public void deleted(String pid) { + @SuppressWarnings("rawtypes") + Dictionary d = props.remove(pid); + if (d != null) { + String url = (String)d.get("url"); + String name = (String)d.get("name"); + if (url != null) { + props.remove(url); + } + if (name != null) { + props.remove(name); + } + } + synchronized (matchers) { + for (Map.Entry ent : matchers.entrySet()) { + if (ent.getValue().equals(pid)) { + matchers.remove(ent.getValue()); + break; + } + } + } + } + + @Override + public void configure(String name, String address, HTTPConduit c) { + String pid = null; + synchronized (matchers) { + for (Map.Entry ent : matchers.entrySet()) { + Matcher m = ent.getKey(); + m.reset(address); + if (m.matches()) { + pid = ent.getValue(); + } + } + } + Dictionary d = null; + if (name != null) { + d = props.get(name); + } + if (d != null) { + apply(d, c); + } + if (address != null && props.get(address) != d) { + apply(props.get(address), c); + } + if (pid != null && props.get(pid) != d) { + apply(props.get(pid), c); + } + } + + private void apply(Dictionary d, HTTPConduit c) { + applyClientPolicies(d, c); + applyAuthorization(d, c); + applyProxyAuthorization(d, c); + applyTlsClientParameters(d, c); + } + + private void applyTlsClientParameters(Dictionary d, HTTPConduit c) { + Enumeration keys = d.keys(); + TLSClientParameters p = c.getTlsClientParameters(); + while (keys.hasMoreElements()) { + String k = keys.nextElement(); + if (k.startsWith("tlsClientParameters.")) { + if (p == null) { + p = new TLSClientParameters(); + c.setTlsClientParameters(p); + } + String v = d.get(k); + k = k.substring("tlsClientParameters.".length()); + + if ("".equals(v)) { + // + } + //TODO - map properties into tls information + } + } + } + + private void applyProxyAuthorization(Dictionary d, HTTPConduit c) { + Enumeration keys = d.keys(); + ProxyAuthorizationPolicy p = c.getProxyAuthorization(); + while (keys.hasMoreElements()) { + String k = keys.nextElement(); + if (k.startsWith("proxyAuthorization.")) { + if (p == null) { + p = new ProxyAuthorizationPolicy(); + c.setProxyAuthorization(p); + } + String v = d.get(k); + k = k.substring("proxyAuthorization.".length()); + + if ("UserName".equals(k)) { + p.setUserName(v); + } else if ("Password".equals(k)) { + p.setPassword(v); + } else if ("Authorization".equals(k)) { + p.setAuthorization(v); + } else if ("AuthorizationType".equals(k)) { + p.setAuthorizationType(v); + } + } + } + } + + private void applyAuthorization(Dictionary d, HTTPConduit c) { + Enumeration keys = d.keys(); + AuthorizationPolicy p = c.getAuthorization(); + while (keys.hasMoreElements()) { + String k = keys.nextElement(); + if (k.startsWith("authorization.")) { + if (p == null) { + p = new AuthorizationPolicy(); + c.setAuthorization(p); + } + String v = d.get(k); + k = k.substring("authorization.".length()); + + if ("UserName".equals(k)) { + p.setUserName(v); + } else if ("Password".equals(k)) { + p.setPassword(v); + } else if ("Authorization".equals(k)) { + p.setAuthorization(v); + } else if ("AuthorizationType".equals(k)) { + p.setAuthorizationType(v); + } + } + } + } + + + private void applyClientPolicies(Dictionary d, HTTPConduit c) { + Enumeration keys = d.keys(); + HTTPClientPolicy p = c.getClient(); + while (keys.hasMoreElements()) { + String k = keys.nextElement(); + if (k.startsWith("client.")) { + if (p == null) { + p = new HTTPClientPolicy(); + c.setClient(p); + } + String v = d.get(k); + k = k.substring("client.".length()); + if ("ConnectionTimeout".equals(k)) { + p.setConnectionTimeout(Long.parseLong(v.trim())); + } else if ("ReceiveTimeout".equals(k)) { + p.setReceiveTimeout(Long.parseLong(v.trim())); + } else if ("AutoRedirect".equals(k)) { + p.setAutoRedirect(Boolean.parseBoolean(v.trim())); + } else if ("MaxRetransmits".equals(k)) { + p.setMaxRetransmits(Integer.parseInt(v.trim())); + } else if ("AllowChunking".equals(k)) { + p.setAllowChunking(Boolean.parseBoolean(v.trim())); + } else if ("ChunkingThreshold".equals(k)) { + p.setChunkingThreshold(Integer.parseInt(v.trim())); + } else if ("Connection".equals(k)) { + p.setConnection(ConnectionType.valueOf(v)); + } else if ("DecoupledEndpoint".equals(k)) { + p.setDecoupledEndpoint(v); + } else if ("ProxyServer".equals(k)) { + p.setProxyServer(v); + } else if ("ProxyServerPort".equals(k)) { + p.setProxyServerPort(Integer.parseInt(v.trim())); + } else if ("ProxyServerType".equals(k)) { + p.setProxyServerType(ProxyServerType.fromValue(v)); + } else if ("NonProxyHosts".equals(k)) { + p.setNonProxyHosts(v); + } + } + } + } + + + +} Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/osgi/HTTPTransportActivator.java ------------------------------------------------------------------------------ svn:keywords = Rev Date