Return-Path: X-Original-To: apmail-ace-commits-archive@www.apache.org Delivered-To: apmail-ace-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 9659518B66 for ; Wed, 10 Feb 2016 14:10:27 +0000 (UTC) Received: (qmail 40270 invoked by uid 500); 10 Feb 2016 14:10:27 -0000 Delivered-To: apmail-ace-commits-archive@ace.apache.org Received: (qmail 40242 invoked by uid 500); 10 Feb 2016 14:10:27 -0000 Mailing-List: contact commits-help@ace.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ace.apache.org Delivered-To: mailing list commits@ace.apache.org Received: (qmail 40231 invoked by uid 99); 10 Feb 2016 14:10:27 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Feb 2016 14:10:27 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 0DB8C1A008C for ; Wed, 10 Feb 2016 14:10:27 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.567 X-Spam-Level: * X-Spam-Status: No, score=1.567 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.233] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id dc7kSAgsn6Os for ; Wed, 10 Feb 2016 14:10:24 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 3F39D20271 for ; Wed, 10 Feb 2016 14:10:24 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 6FB36E0099 for ; Wed, 10 Feb 2016 14:10:23 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id CB5453A023C for ; Wed, 10 Feb 2016 14:10:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1729606 - in /ace/trunk: ./ org.apache.ace.bnd/ org.apache.ace.bnd/services/ org.apache.ace.bnd/src/org/apache/ace/bnd/repository/ org.apache.ace.gogo/ Date: Wed, 10 Feb 2016 14:10:23 -0000 To: commits@ace.apache.org From: jawi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160210141023.CB5453A023C@svn01-us-west.apache.org> Author: jawi Date: Wed Feb 10 14:10:23 2016 New Revision: 1729606 URL: http://svn.apache.org/viewvc?rev=1729606&view=rev Log: ACE-499 - support authentication in AceObrRepository - applied patch from @brampouwelse; - this closes #3. Added: ace/trunk/org.apache.ace.bnd/services/ ace/trunk/org.apache.ace.bnd/services/org.apache.ace.connectionfactory.ConnectionFactory ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceUrlConnector.java (with props) Modified: ace/trunk/.gitignore ace/trunk/org.apache.ace.bnd/bnd.bnd ace/trunk/org.apache.ace.bnd/repository.bnd ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceObrRepository.java ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/packageinfo ace/trunk/org.apache.ace.gogo/bnd.bnd Modified: ace/trunk/.gitignore URL: http://svn.apache.org/viewvc/ace/trunk/.gitignore?rev=1729606&r1=1729605&r2=1729606&view=diff ============================================================================== --- ace/trunk/.gitignore (original) +++ ace/trunk/.gitignore Wed Feb 10 14:10:23 2016 @@ -10,3 +10,7 @@ cnf/*/.obrcache/ */reports/ *~ */.settings/ +*/bundle-cache +*/store +*/test-output +rat-report.xml Modified: ace/trunk/org.apache.ace.bnd/bnd.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/bnd.bnd?rev=1729606&r1=1729605&r2=1729606&view=diff ============================================================================== --- ace/trunk/org.apache.ace.bnd/bnd.bnd (original) +++ ace/trunk/org.apache.ace.bnd/bnd.bnd Wed Feb 10 14:10:23 2016 @@ -2,5 +2,8 @@ -sub: *.bnd -buildpath: \ + osgi.cmpn,\ biz.aQute.bnd,\ - biz.aQute.repository + biz.aQute.repository,\ + org.apache.ace.connectionfactory;version=latest + Modified: ace/trunk/org.apache.ace.bnd/repository.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/repository.bnd?rev=1729606&r1=1729605&r2=1729606&view=diff ============================================================================== --- ace/trunk/org.apache.ace.bnd/repository.bnd (original) +++ ace/trunk/org.apache.ace.bnd/repository.bnd Wed Feb 10 14:10:23 2016 @@ -1,6 +1,15 @@ # Licensed to the Apache Software Foundation (ASF) under the terms of ASLv2 (http://www.apache.org/licenses/LICENSE-2.0). -Bundle-Version: 1.0.1 +Bundle-Version: 1.1.0 Bundle-Name: Apache ACE OBR Repository Bundle-Description: Provides an ACE Bnd Repository implementation -Export-Package: org.apache.ace.bnd.repository \ No newline at end of file +Export-Package: \ + org.apache.ace.bnd.repository,\ + org.apache.commons.codec,\ + org.apache.commons.codec.binary,\ + org.osgi.service.cm,\ + org.osgi.service.useradmin,\ + org.apache.ace.connectionfactory,\ + org.apache.ace.connectionfactory.impl + +-includeresource: META-INF/services=services \ No newline at end of file Added: ace/trunk/org.apache.ace.bnd/services/org.apache.ace.connectionfactory.ConnectionFactory URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/services/org.apache.ace.connectionfactory.ConnectionFactory?rev=1729606&view=auto ============================================================================== --- ace/trunk/org.apache.ace.bnd/services/org.apache.ace.connectionfactory.ConnectionFactory (added) +++ ace/trunk/org.apache.ace.bnd/services/org.apache.ace.connectionfactory.ConnectionFactory Wed Feb 10 14:10:23 2016 @@ -0,0 +1 @@ +org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl \ No newline at end of file Modified: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceObrRepository.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceObrRepository.java?rev=1729606&r1=1729605&r2=1729606&view=diff ============================================================================== --- ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceObrRepository.java (original) +++ ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceObrRepository.java Wed Feb 10 14:10:23 2016 @@ -28,6 +28,8 @@ import java.net.URL; import java.net.URLConnection; import java.util.Map; +import org.apache.ace.connectionfactory.ConnectionFactory; + import aQute.bnd.deployer.repository.FixedIndexedRepo; /** @@ -88,7 +90,19 @@ public class AceObrRepository extends Fi try { URL url = new URL(m_endpoint, "?filename=" + filename); - URLConnection connection = url.openConnection(); + + URLConnection connection = null; + if (registry != null) { + ConnectionFactory connectionFactory = registry.getPlugin(ConnectionFactory.class); + if (connectionFactory != null) { + connection = connectionFactory.createConnection(url); + } + } + + if (connection == null) { + connection = url.openConnection(); + } + connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); Added: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceUrlConnector.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceUrlConnector.java?rev=1729606&view=auto ============================================================================== --- ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceUrlConnector.java (added) +++ ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceUrlConnector.java Wed Feb 10 14:10:23 2016 @@ -0,0 +1,168 @@ +/* + * 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.ace.bnd.repository; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; +import java.util.ServiceLoader; +import java.util.StringTokenizer; + +import org.apache.ace.connectionfactory.ConnectionFactory; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedServiceFactory; +import org.osgi.service.useradmin.User; + +import aQute.bnd.service.Plugin; +import aQute.bnd.service.url.TaggedData; +import aQute.bnd.service.url.URLConnector; +import aQute.service.reporter.Reporter; + +/** + * BND URLConnector plugin based on the Ace ConnectionFactory + * + * Can be configured as a bnd plugin with a configs configuration property that contains + * comma separated list of connection factory configurations + * + * Example: + * -plugin: org.apache.ace.bnd.repository.AceUrlConnector; \ + * configs=${workspace}/run-server-allinone/conf/org.apache.ace.connectionfactory/obr.cfg; + * + * Note: The default ace configurations contain placeholders in the baseURL property this doesn't + * work when the configuration is used in this plugin as these placeholders are not replaced by bnd. + */ +public class AceUrlConnector implements URLConnector, Plugin, ConnectionFactory { + + private static final String HEADER_IF_NONE_MATCH = "If-None-Match"; + private static final String HEADER_ETAG = "ETag"; + private static final int RESPONSE_NOT_MODIFIED = 304; + + private ConnectionFactory m_connectionFactory; + + public AceUrlConnector() { + m_connectionFactory = getConnectionFactory(); + } + + public AceUrlConnector(ConnectionFactory connectionFactory) { + m_connectionFactory = connectionFactory; + } + + private ConnectionFactory getConnectionFactory() { + ServiceLoader loader = ServiceLoader.load(ConnectionFactory.class, getClass().getClassLoader()); + return loader.iterator().next(); + } + + @Override + public TaggedData connectTagged(URL url, String tag) throws IOException { + TaggedData result; + URLConnection connection = m_connectionFactory.createConnection(url); + if (connection instanceof HttpURLConnection) { + HttpURLConnection httpConnection = (HttpURLConnection) connection; + + httpConnection.setUseCaches(true); + if (tag != null) { + httpConnection.setRequestProperty(HEADER_IF_NONE_MATCH, tag); + } + int responseCode = httpConnection.getResponseCode(); + if (responseCode == RESPONSE_NOT_MODIFIED) { + result = null; + httpConnection.disconnect(); + } else { + String responseTag = httpConnection.getHeaderField(HEADER_ETAG); + result = new TaggedData(responseTag, connection.getInputStream()); + } + } else { + // Non-HTTP so ignore all this tagging malarky + result = new TaggedData(null, connection.getInputStream()); + } + + return result; + } + + @Override + public TaggedData connectTagged(URL url) throws IOException { + return connectTagged(url, null); + } + + @Override + public InputStream connect(URL url) throws IOException { + return m_connectionFactory.createConnection(url).getInputStream(); + } + + @Override + public URLConnection createConnection(URL url) throws IOException { + return m_connectionFactory.createConnection(url); + } + + @Override + public URLConnection createConnection(URL url, User user) throws IOException { + return m_connectionFactory.createConnection(url, user); + } + + @Override + public void setProperties(Map map) { + String configFileList = map.get("configs"); + if (configFileList == null) { + throw new IllegalArgumentException("'configs' must be specified on HttpBasicAuthURLConnector"); + } + + ConnectionFactory connectionFactory = getConnectionFactory(); + ManagedServiceFactory managedServiceFactory = (ManagedServiceFactory) connectionFactory; + + StringTokenizer tokenizer = new StringTokenizer(configFileList, ","); + while (tokenizer.hasMoreTokens()) { + String configFileName = tokenizer.nextToken().trim(); + + File file = new File(configFileName); + if (file.exists()) { + + try { + Properties properties = new Properties(); + properties.load(new FileInputStream(file)); + + Dictionary dict = new Hashtable<>(); + for (Object key : properties.keySet()) { + String value = (String) properties.get(key); + dict.put((String) key, value); + } + + managedServiceFactory.updated(file.getAbsolutePath(), dict); + } catch (IOException | ConfigurationException e) { + + } + } + + m_connectionFactory = connectionFactory; + } + } + + @Override + public void setReporter(Reporter reporter) { + + } + +} Propchange: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/AceUrlConnector.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/packageinfo URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/packageinfo?rev=1729606&r1=1729605&r2=1729606&view=diff ============================================================================== --- ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/packageinfo (original) +++ ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/repository/packageinfo Wed Feb 10 14:10:23 2016 @@ -1 +1 @@ -version 1.0 \ No newline at end of file +version 1.1.0 \ No newline at end of file Modified: ace/trunk/org.apache.ace.gogo/bnd.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/bnd.bnd?rev=1729606&r1=1729605&r2=1729606&view=diff ============================================================================== --- ace/trunk/org.apache.ace.gogo/bnd.bnd (original) +++ ace/trunk/org.apache.ace.gogo/bnd.bnd Wed Feb 10 14:10:23 2016 @@ -14,9 +14,10 @@ Bundle-Name: Apache ACE Gogo commands Bundle-Description: Provides Gogo commands for working with ACE -Bundle-Version: 1.0.1 +Bundle-Version: 1.0.2 Bundle-Activator: org.apache.ace.gogo.Activator -Private-Package: org.apache.ace.bnd.repository,\ +Private-Package: \ + org.apache.ace.bnd.repository,\ org.apache.ace.gogo,\ org.apache.ace.gogo.execute,\ org.apache.ace.gogo.math,\