You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/09/05 01:45:45 UTC
[1/2] incubator-tamaya git commit: Fixed quality gate issues. Added
doc templates for new modules (server,
remote). Added running code for corresponding remote/server example.
Implemented additional functions required. Added/moved remote/server to
module
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 8a93bad81 -> 2c64ac027
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java b/modules/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java
new file mode 100644
index 0000000..1765e4f
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java
@@ -0,0 +1,188 @@
+/*
+ * 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.tamaya.server.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.server.spi.ConfigProviderService;
+import org.apache.tamaya.server.spi.ScopeManager;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Implementation of the JAX-RS interface for serving configuration.
+ */
+public class DefaultConfigService implements ConfigProviderService {
+
+ @Override
+ @GET
+ @Path("/config/filtered/{path}")
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN, MediaType.WILDCARD})
+ public String getConfigurationWithPath(@PathParam("path") String path,
+ @Context HttpServletRequest request){
+ Map<String,String> requestInfo = new HashMap<>();
+ requestInfo.put("filter",path);
+ requestInfo.put("timestamp", String.valueOf(System.currentTimeMillis()));
+ String format = request.getParameter("format");
+ if(format==null){
+ format = request.getHeader(HttpHeaders.ACCEPT);
+ }
+ requestInfo.put("format", format);
+ String scope = request.getParameter("scope");
+ String scopeId = request.getParameter("scopeId");
+ if(scope!=null && scopeId!=null){
+ return getScopedConfigurationWithPath(scope, scopeId, path, request, format, requestInfo);
+ }
+ Configuration config = ConfigurationProvider.getConfiguration()
+ .with(ConfigurationFunctions.sectionsRecursive(path.split(",")));
+ if(format.contains(MediaType.APPLICATION_JSON)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
+ return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
+ }
+ if(format.contains(MediaType.APPLICATION_XML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
+ return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_HTML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
+ return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_PLAIN)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
+ return config.query(ConfigurationFunctions.textInfo(requestInfo));
+ }
+ Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
+ .build();
+ return null;
+ }
+
+
+
+ @Override
+ @GET
+ @Path("/config")
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN, MediaType.WILDCARD})
+ public String getConfiguration(@Context HttpServletRequest request) {
+ Map<String,String> requestInfo = new HashMap<>();
+ requestInfo.put("timestamp", String.valueOf(System.currentTimeMillis()));
+ String format = request.getParameter("format");
+ if(format==null){
+ format = request.getHeader(HttpHeaders.ACCEPT);
+ }
+ String scope = request.getParameter("scope");
+ String scopeId = request.getParameter("scopeId");
+ if(scope!=null && scopeId!=null){
+ return getScopedConfiguration(scope, scopeId, request, format, requestInfo);
+ }
+ Configuration config = ConfigurationProvider.getConfiguration();
+ if(format.contains(MediaType.APPLICATION_JSON)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
+ return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
+ }
+ if(format.contains(MediaType.APPLICATION_XML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
+ return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_HTML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
+ return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_PLAIN)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
+ return config.query(ConfigurationFunctions.textInfo(requestInfo));
+ }
+ Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML);
+ return null;
+ }
+
+ private String getScopedConfigurationWithPath(String scope, String scopeId, String path, HttpServletRequest request, String format, Map<String,String> requestInfo) {
+ requestInfo.put("scope", scope);
+ requestInfo.put("scopeId", scopeId);
+ Configuration config = ConfigurationProvider.getConfiguration()
+ .with(ScopeManager.getScope(scope, scopeId)).with(ConfigurationFunctions.sectionsRecursive(path.split(",")));
+ if(format.contains(MediaType.APPLICATION_JSON)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
+ return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
+ }
+ if(format.contains(MediaType.APPLICATION_XML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
+ return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_HTML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
+ return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_PLAIN)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
+ return config.query(ConfigurationFunctions.textInfo(requestInfo));
+ }
+ Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML);
+ return null;
+ }
+
+ private String getScopedConfiguration(String scope, String scopeId, HttpServletRequest request, String format,
+ Map<String,String> requestInfo) {
+ requestInfo.put("scope", scope);
+ requestInfo.put("scopeId", scopeId);
+ Configuration config = ConfigurationProvider.getConfiguration().with(ScopeManager.getScope(scope, scopeId));
+ if(format.contains(MediaType.APPLICATION_JSON)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
+ return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
+ }
+ if(format.contains(MediaType.APPLICATION_XML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
+ return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_HTML)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
+ return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
+ }
+ if(format.contains(MediaType.TEXT_PLAIN)) {
+ Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
+ return config.query(ConfigurationFunctions.textInfo(requestInfo));
+ }
+ Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
+ .build();
+ return null;
+ }
+
+ @Override
+ public String updateConfiguration(@Context HttpServletRequest request) {
+ Response.status(Response.Status.INTERNAL_SERVER_ERROR);
+ return "UPDATE Configuration: Not implemented";
+ }
+
+ @Override
+ public String deleteConfiguration(String paths, @Context HttpServletRequest request) {
+ Response.status(Response.Status.INTERNAL_SERVER_ERROR);
+ return "DELETE Configuration: Not implemented";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java b/modules/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java
new file mode 100644
index 0000000..ac26d8b
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java
@@ -0,0 +1,56 @@
+/*
+ * 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.tamaya.server.spi;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Configuration serving RESTful service interface.
+ */
+public interface ConfigProviderService {
+
+ @GET
+ @Path("/config/filtered/{path}")
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN,MediaType.WILDCARD})
+ String getConfigurationWithPath(@PathParam("path") String path,
+ @Context HttpServletRequest request);
+
+ @GET
+ @Path("/config")
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN,MediaType.WILDCARD })
+ String getConfiguration(@Context HttpServletRequest request);
+
+ @PUT
+ @Path("/config")
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ String updateConfiguration(@Context HttpServletRequest request);
+
+ @DELETE
+ @Path("/config/{paths}")
+ String deleteConfiguration(@PathParam("paths") String paths, @Context HttpServletRequest request);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
new file mode 100644
index 0000000..a91ffc2
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
@@ -0,0 +1,81 @@
+/*
+ * 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.tamaya.server.spi;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Singleton manager for scopes, used by the server component to filtering returned config.
+ */
+public final class ScopeManager {
+ /** The logger used. */
+ private static final Logger LOG = Logger.getLogger(ScopeManager.class.getName());
+
+ private static Map<String, ScopeProvider> scopeProviders = initProviders();
+
+ /**
+ * Singleton constructor.
+ */
+ private static Map<String, ScopeProvider> initProviders(){
+ Map<String, ScopeProvider> result = new ConcurrentHashMap<>();
+ for(ScopeProvider prov: ServiceContextManager.getServiceContext().getServices(ScopeProvider.class)){
+ try{
+ result.put(prov.getScopeType(), prov);
+ } catch(Exception e){
+ LOG.log(Level.WARNING, "Error loading scopes from " + prov, e);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Singleton constructor.
+ */
+ private ScopeManager(){}
+
+ /**
+ * Get the scope given its name.
+ * @param scopeId the scope name
+ * @return the scope matching
+ * @throws ConfigException, if nos such scope is defined.
+ */
+ public static ConfigOperator getScope(String scopeId, String target){
+ ScopeProvider prov = scopeProviders.get(scopeId);
+ if(prov==null){
+ throw new ConfigException("No such scope: " + scopeId);
+ }
+ return prov.getScope(target);
+ }
+
+ /**
+ * Get the defined scope names.
+ * @return the defined scope names, never null.
+ */
+ public static Set<String> getScopes(){
+ return scopeProviders.keySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
new file mode 100644
index 0000000..d74317c
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
@@ -0,0 +1,39 @@
+/*
+ * 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.tamaya.server.spi;
+
+import org.apache.tamaya.ConfigOperator;
+
+/**
+ * Simple registratable provider class to register scopes for the server extension.
+ */
+public interface ScopeProvider {
+
+ /**
+ * Access the unique scope name.
+ * @return the unique scope name.
+ */
+ String getScopeType();
+
+ /**
+ * Return the scope operator that implements the scope for the given scope id.
+ * @return the scope operator, never null.
+ */
+ ConfigOperator getScope(String scopeId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server
----------------------------------------------------------------------
diff --git a/modules/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server b/modules/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server
new file mode 100644
index 0000000..72b1998
--- /dev/null
+++ b/modules/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.server.internal.CXFServer
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/pom.xml b/sandbox/pom.xml
index 9012c97..2935530 100644
--- a/sandbox/pom.xml
+++ b/sandbox/pom.xml
@@ -40,7 +40,6 @@ under the License.
<module>jodatime</module>
<module>sysprops</module>
<module>environment</module>
- <module>remote</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/remote/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/remote/pom.xml b/sandbox/remote/pom.xml
deleted file mode 100644
index ebc09be..0000000
--- a/sandbox/remote/pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<!--
-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 current 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.
--->
-<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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-sandbox</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>tamaya-remote</artifactId>
- <name>Apache Tamaya Remote PropertySource / Configuration Support</name>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>tamaya-json</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java b/sandbox/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
deleted file mode 100644
index fd1bd7c..0000000
--- a/sandbox/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.tamaya.remote;
-
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.json.JSONFormat;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Abstract base class for implementing a PropertySource that reads configuration data from a remote resource. It uses
- * by default the JSON format as defined by the JSON module.
- */
-public abstract class BaseRemotePropertySource implements PropertySource{
-
- private static final ConfigurationFormat DEFAULT_FORMAT = new JSONFormat();
-
- private Map<String,String> properties = new HashMap<>();
-
- protected BaseRemotePropertySource(){
- reload();
- }
-
- @Override
- public String getName() {
- return getClass().getSimpleName();
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-
- /**
- * Reloads the remote configuration. If reloads fails to whatever reasons the already loaded configuration will
- * stay untouched.
- */
- public void reload(){
- Map readProperties;
- ConfigurationFormat format = getConfigurationFormat();
- for(URL url:getAccessURLs()) {
- try(InputStream is = url.openStream()) {
- ConfigurationData data = format.readConfiguration(url.toExternalForm(), is);
- if(data!=null){
- readProperties = data.getDefaultSection();
- if(readProperties!=null){
- Map<String,String> newProperties = new HashMap<>();
- for(Map.Entry<String,String> en:readProperties.entrySet()){
- // filter data entries
- if(en.getKey().startsWith("data.")) {
- newProperties.put(en.getKey().substring(5), en.getValue());
- }
- }
- // the configs served by the tamaya server module has a 'data' root section containing the
- // config entries. if not present, we assume an alternate format, which is sued as is...
- if(newProperties.isEmpty()){
- Logger.getLogger(getClass().getName()).info(
- "Loaded remote config from: " + url + ", does not have a data section, using as is...");
- newProperties = readProperties;
- }
- this.properties = newProperties;
- Logger.getLogger(getClass().getName()).info(
- "Reloaded remote config from: " + url + ", entriea read: " + this.properties.size());
- }
- }
- }
- catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to load config from url: " + url, e);
- }
- }
- }
-
- protected abstract Collection<URL> getAccessURLs();
-
- protected ConfigurationFormat getConfigurationFormat(){
- return DEFAULT_FORMAT;
- }
-
- protected Map<String,String> mapConfigurationData(ConfigurationData data){
- return data.getDefaultSection();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/server/pom.xml b/sandbox/server/pom.xml
deleted file mode 100644
index 4ae4ea1..0000000
--- a/sandbox/server/pom.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<!--
-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 current 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.
--->
-<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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-sandbox</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>tamaya-server</artifactId>
- <name>Apache Tamaya Configuration: Server Extension</name>
- <packaging>jar</packaging>
-
- <properties>
- <jdkVersion>1.7</jdkVersion>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-java7-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-java7-core</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>tamaya-json</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>apache-cxf</artifactId>
- <version>3.1.2</version>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/ConfigServer.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/ConfigServer.java b/sandbox/server/src/main/java/org/apache/tamaya/server/ConfigServer.java
deleted file mode 100644
index 101bf7c..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/ConfigServer.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.tamaya.server;
-
-import org.apache.tamaya.spi.ServiceContextManager;
-
-/**
- * Simple abstraction of the Server interface.
- */
-public final class ConfigServer {
-
- /**
- * Creates a new server instance.
- * @return a new server instance.
- */
- public static Server createServer(){
- return ServiceContextManager.getServiceContext().getService(Server.class);
- }
-
- public static void main(String... args){
- createServer().start(8888);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/Server.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/Server.java b/sandbox/server/src/main/java/org/apache/tamaya/server/Server.java
deleted file mode 100644
index 5e2cb52..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/Server.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.tamaya.server;
-
-/**
- * Simple abstraction of the Server interface.
- */
-public interface Server {
- /**
- * Starts the server on the given port-
- * @param port the target port.
- */
- void start(int port);
-
- /**
- * Checks if the server us started.
- * @return true if the server us started.
- */
- boolean isStarted();
-
- /**
- * Stops the server, but does not destroy it, so it might be restarted.
- */
- void stop();
-
- /**
- * Destroy the server instance.
- */
- void destroy();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java b/sandbox/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java
deleted file mode 100644
index c976723..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.tamaya.server.internal;
-
-
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.tamaya.server.Server;
-
-/**
- * CXF based implementation of a JAX-RS server, serving the {@link DefaultConfigService} service.
- */
-public class CXFServer implements Server {
- /** The CXF endpoint. */
- private org.apache.cxf.endpoint.Server cxfEndpoint;
-
- /**
- * Starts the CXF server under the port.
- * @param port the port.
- */
- public void start(int port) {
- if(cxfEndpoint!=null){
- if(cxfEndpoint.isStarted()){
- return;
- }
- // start it at the end...
- }
- else {
- JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
- DefaultConfigService confService = new DefaultConfigService();
- sf.setServiceBeanObjects(confService);
- sf.setAddress("http://localhost:" + port + "/");
- cxfEndpoint = sf.create();
- }
- cxfEndpoint.start();
- }
-
- /**
- * Returns the current started state.
- * @return true, if the server is started.
- */
- public boolean isStarted(){
- if(cxfEndpoint!=null){
- return cxfEndpoint.isStarted();
- }
- return false;
- }
-
- /**
- * Stops the server if running.
- */
- public void stop(){
- if(cxfEndpoint!=null){
- cxfEndpoint.stop();
- }
- }
-
- /**
- * Destroy the server.
- */
- public void destroy(){
- if(cxfEndpoint!=null){
- cxfEndpoint.destroy();
- cxfEndpoint = null;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java b/sandbox/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java
deleted file mode 100644
index 019b0b3..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/internal/DefaultConfigService.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * 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.tamaya.server.internal;
-
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.apache.tamaya.server.spi.ConfigProviderService;
-import org.apache.tamaya.server.spi.ScopeManager;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * Implementation of the JAX-RS interface for serving configuration.
- */
-public class DefaultConfigService implements ConfigProviderService {
-
- @Override
- @GET
- @Path("/config/filtered/{path}")
- @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN})
- public String getConfigurationWithPath(@PathParam("path") String path,
- @Context HttpServletRequest request){
- Map<String,String> requestInfo = new HashMap<>();
- requestInfo.put("filter",path);
- requestInfo.put("timestamp", String.valueOf(System.currentTimeMillis()));
- String format = request.getParameter("format");
- if(format==null){
- format = request.getHeader(HttpHeaders.ACCEPT);
- }
- requestInfo.put("format", format);
- String scope = request.getParameter("scope");
- if(scope!=null){
- return getScopedConfigurationWithPath(scope, path, request, format, requestInfo);
- }
- Configuration config = ConfigurationProvider.getConfiguration()
- .with(ConfigurationFunctions.sectionsRecursive(path.split(",")));
- if(format.contains(MediaType.APPLICATION_JSON)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
- return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
- }
- if(format.contains(MediaType.APPLICATION_XML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
- return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_HTML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
- return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_PLAIN)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
- return config.query(ConfigurationFunctions.textInfo(requestInfo));
- }
- Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
- .build();
- return null;
- }
-
-
-
- @Override
- @GET
- @Path("/config")
- @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN})
- public String getConfiguration(@Context HttpServletRequest request) {
- Map<String,String> requestInfo = new HashMap<>();
- requestInfo.put("timestamp", String.valueOf(System.currentTimeMillis()));
- String format = request.getParameter("format");
- if(format==null){
- format = request.getHeader(HttpHeaders.ACCEPT);
- }
- String scope = request.getParameter("scope");
- if(scope!=null){
- return getScopedConfiguration(scope, request, format, requestInfo);
- }
- Configuration config = ConfigurationProvider.getConfiguration();
- if(format.contains(MediaType.APPLICATION_JSON)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
- return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
- }
- if(format.contains(MediaType.APPLICATION_XML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
- return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_HTML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
- return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_PLAIN)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
- return config.query(ConfigurationFunctions.textInfo(requestInfo));
- }
- Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML);
- return null;
- }
-
- private String getScopedConfigurationWithPath(String scope, String path, HttpServletRequest request, String format, Map<String,String> requestInfo) {
- requestInfo.put("scope", scope);
- Configuration config = ConfigurationProvider.getConfiguration()
- .with(getScope(scope)).with(ConfigurationFunctions.sectionsRecursive(path.split(",")));
- if(format.contains(MediaType.APPLICATION_JSON)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
- return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
- }
- if(format.contains(MediaType.APPLICATION_XML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
- return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_HTML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
- return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_PLAIN)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
- return config.query(ConfigurationFunctions.textInfo(requestInfo));
- }
- Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML);
- return null;
- }
-
- private String getScopedConfiguration(String scope, HttpServletRequest request, String format, Map<String,String> requestInfo) {
- requestInfo.put("scope", scope);
- Configuration config = ConfigurationProvider.getConfiguration().with(getScope(scope));
- if(format.contains(MediaType.APPLICATION_JSON)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_JSON_TYPE);
- return config.query(ConfigurationFunctions.jsonInfo(requestInfo));
- }
- if(format.contains(MediaType.APPLICATION_XML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.APPLICATION_XML_TYPE);
- return config.query(ConfigurationFunctions.xmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_HTML)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_HTML_TYPE);
- return config.query(ConfigurationFunctions.htmlInfo(requestInfo));
- }
- if(format.contains(MediaType.TEXT_PLAIN)) {
- Response.status(Response.Status.OK).encoding("utf-8").type(MediaType.TEXT_PLAIN_TYPE);
- return config.query(ConfigurationFunctions.textInfo(requestInfo));
- }
- Response.status(Response.Status.BAD_REQUEST).allow(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
- .build();
- return null;
- }
-
- private ConfigOperator getScope(String scope) {
- return ScopeManager.getScope(scope);
- }
-
- @Override
- public String updateConfiguration(@Context HttpServletRequest request) {
- Response.status(Response.Status.INTERNAL_SERVER_ERROR);
- return "UPDATE Configuration: Not implemented";
- }
-
- @Override
- public String deleteConfiguration(String paths, @Context HttpServletRequest request) {
- Response.status(Response.Status.INTERNAL_SERVER_ERROR);
- return "DELETE Configuration: Not implemented";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java b/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java
deleted file mode 100644
index 1e080c3..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ConfigProviderService.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.tamaya.server.spi;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-/**
- * Configuration serving RESTful service interface.
- */
-public interface ConfigProviderService {
-
- @GET
- @Path("/config/filtered/{path}")
- @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN})
- String getConfigurationWithPath(@PathParam("path") String path,
- @Context HttpServletRequest request);
-
- @GET
- @Path("/config")
- @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_PLAIN})
- String getConfiguration(@Context HttpServletRequest request);
-
- @PUT
- @Path("/config")
- @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
- String updateConfiguration(@Context HttpServletRequest request);
-
- @DELETE
- @Path("/config/{paths}")
- String deleteConfiguration(@PathParam("paths") String paths, @Context HttpServletRequest request);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java b/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
deleted file mode 100644
index 7bd6c81..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.tamaya.server.spi;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Singleton manager for scopes, used by the server component to filtering returned config.
- */
-public final class ScopeManager {
- /** The logger used. */
- private static final Logger LOG = Logger.getLogger(ScopeManager.class.getName());
-
- /**
- * Singleton constructor.
- */
- private ScopeManager(){
- }
-
- /** The scopes read from the {@link org.apache.tamaya.spi.ServiceContext}. */
- private static final Map<String,ConfigOperator> scopes = readScopes();
-
- /**
- * Read the scopes from the providers, ordered by their priority.
- * @return the map of registered scopes.
- */
- private static Map<String, ConfigOperator> readScopes() {
- Map<String,ConfigOperator> scopes = new ConcurrentHashMap<>();
- for(ScopeProvider prov: ServiceContextManager.getServiceContext().getServices(ScopeProvider.class)){
- try{
- ScopeManager.scopes.putAll(prov.getScopes());
- }
- catch(Exception e){
- LOG.log(Level.WARNING, "Error loading scopes from " + prov, e);
- }
- }
- return scopes;
- }
-
- /**
- * Get the scope given its name.
- * @param scopeId the scope name
- * @return the scope matching
- * @throws ConfigException, if nos such scope is defined.
- */
- public static ConfigOperator getScope(String scopeId){
- ConfigOperator op = scopes.get(scopeId);
- if(op==null){
- throw new ConfigException("No such scope: " + scopeId);
- }
- return op;
- }
-
- /**
- * Get the defined scope names.
- * @return the defined scope names, never null.
- */
- public Set<String> getScopes(){
- return scopes.keySet();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java b/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
deleted file mode 100644
index b74f551..0000000
--- a/sandbox/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.tamaya.server.spi;
-
-import org.apache.tamaya.ConfigOperator;
-
-import java.util.Map;
-
-/**
- * Simple registratable provider class to register scopes for the server extension.
- */
-public interface ScopeProvider {
-
- /**
- * Return the scopes to be registered.
- * @return the scope map. The keys are the scope ids that identify the scope operators to be used.
- */
- Map<String,ConfigOperator> getScopes();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/sandbox/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server
----------------------------------------------------------------------
diff --git a/sandbox/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server b/sandbox/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server
deleted file mode 100644
index 72b1998..0000000
--- a/sandbox/server/src/main/resources/META-INF/services/org.apache.tamaya.server.Server
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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 current 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.
-#
-org.apache.tamaya.server.internal.CXFServer
\ No newline at end of file
[2/2] incubator-tamaya git commit: Fixed quality gate issues. Added
doc templates for new modules (server,
remote). Added running code for corresponding remote/server example.
Implemented additional functions required. Added/moved remote/server to
module
Posted by an...@apache.org.
Fixed quality gate issues.
Added doc templates for new modules (server,remote).
Added running code for corresponding remote/server example.
Implemented additional functions required.
Added/moved remote/server to module directory.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/2c64ac02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/2c64ac02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/2c64ac02
Branch: refs/heads/master
Commit: 2c64ac027089e73930920a586c56fd7e4c4749cf
Parents: 8a93bad
Author: anatole <an...@apache.org>
Authored: Sat Sep 5 01:45:06 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Sat Sep 5 01:45:24 2015 +0200
----------------------------------------------------------------------
docs/src/main/asciidoc/mod_remote.adoc | 80 ++++++++
docs/src/main/asciidoc/mod_server.adoc | 79 ++++++++
docs/src/main/asciidoc/modules.adoc | 2 +
examples/8-remote-example/client/pom.xml | 79 ++++++++
.../tamaya/examples/remote/client/Client.java | 93 +++++++++
.../remote/client/PrintConfigServlet.java | 75 ++++++++
.../remote/client/RemotePropertySource.java | 62 ++++++
.../org.apache.tamaya.spi.PropertySource | 19 ++
examples/8-remote-example/pom.xml | 79 ++++++++
examples/8-remote-example/server/pom.xml | 63 +++++++
.../remote/server/ClientScopeProvider.java | 49 +++++
.../tamaya/examples/remote/server/Start.java | 63 +++++++
.../META-INF/javaconfiguration.properties | 29 +++
.../org.apache.tamaya.server.spi.ScopeProvider | 19 ++
examples/pom.xml | 2 +-
.../tamaya/functions/CombinedConfiguration.java | 112 +++++++++++
.../functions/ConfigWrappingPropertySource.java | 79 ++++++++
.../functions/ConfigurationFunctions.java | 111 +++++++----
.../management/internal/ManagedConfigTest.java | 1 -
modules/pom.xml | 2 +
modules/remote/pom.xml | 55 ++++++
.../tamaya/remote/BaseRemotePropertySource.java | 150 +++++++++++++++
modules/server/pom.xml | 72 +++++++
.../org/apache/tamaya/server/ConfigServer.java | 44 +++++
.../java/org/apache/tamaya/server/Server.java | 46 +++++
.../tamaya/server/internal/CXFServer.java | 82 ++++++++
.../server/internal/DefaultConfigService.java | 188 +++++++++++++++++++
.../server/spi/ConfigProviderService.java | 56 ++++++
.../apache/tamaya/server/spi/ScopeManager.java | 81 ++++++++
.../apache/tamaya/server/spi/ScopeProvider.java | 39 ++++
.../services/org.apache.tamaya.server.Server | 19 ++
sandbox/pom.xml | 1 -
sandbox/remote/pom.xml | 55 ------
.../tamaya/remote/BaseRemotePropertySource.java | 107 -----------
sandbox/server/pom.xml | 70 -------
.../org/apache/tamaya/server/ConfigServer.java | 40 ----
.../java/org/apache/tamaya/server/Server.java | 46 -----
.../tamaya/server/internal/CXFServer.java | 83 --------
.../server/internal/DefaultConfigService.java | 188 -------------------
.../server/spi/ConfigProviderService.java | 56 ------
.../apache/tamaya/server/spi/ScopeManager.java | 85 ---------
.../apache/tamaya/server/spi/ScopeProvider.java | 35 ----
.../services/org.apache.tamaya.server.Server | 19 --
43 files changed, 1892 insertions(+), 823 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/docs/src/main/asciidoc/mod_remote.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_remote.adoc b/docs/src/main/asciidoc/mod_remote.adoc
new file mode 100644
index 0000000..b9741ce
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_remote.adoc
@@ -0,0 +1,80 @@
+= Apache Tamaya -- Extension: Remote Configuration
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.remote
+:title: Apache Tamaya Extension: Remote Configuration
+:revnumber: 0.1.1
+:revremark: Incubator
+:revdate: March 2015
+:longversion: {revnumber} ({revremark}) {revdate}
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Remote]]
+== Tamaya Remote Configuration (Extension Module)
+=== Overview
+
+The Tamaya remote module provides support for reading configuration from remote resources. It provides
+especially out-of-the-box support for reading scoped configuration from a configuration server as
+provided with the _Tamaya server module_ .
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from configuration builder support you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-remote</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== Reading Remote configuration from a Tamaya Configuration Server
+
+For reading JSON based onfiguration as provided by the _Tamaya server extension:
+
+[source, java]
+-----------------------------------------------
+TBD
+-----------------------------------------------
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/docs/src/main/asciidoc/mod_server.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_server.adoc b/docs/src/main/asciidoc/mod_server.adoc
new file mode 100644
index 0000000..3a26591
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_server.adoc
@@ -0,0 +1,79 @@
+= Apache Tamaya -- Extension: Configuration Server
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.server
+:title: Apache Tamaya Extension: Configuration Server
+:revnumber: 0.1.1
+:revremark: Incubator
+:revdate: March 2015
+:longversion: {revnumber} ({revremark}) {revdate}
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Remote]]
+== Tamaya Configuration Server (Extension Module)
+=== Overview
+
+The Tamaya server module provides support for providing scoped configuration using a http server serving JSON formatted
+configuration properties.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from configuration server support you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-server</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== Providing configuration using a Tamaya Configuration Server
+
+For providing JSON based onfiguration you have multiple options:
+
+[source, java]
+-----------------------------------------------
+TBD
+-----------------------------------------------
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/docs/src/main/asciidoc/modules.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/modules.adoc b/docs/src/main/asciidoc/modules.adoc
index 9e38e1f..c9a319c 100644
--- a/docs/src/main/asciidoc/modules.adoc
+++ b/docs/src/main/asciidoc/modules.adoc
@@ -65,6 +65,8 @@ NOTE All extensions, despite the _tamaya-builder_ module, currently run on Java
|+org.apache.tamaya.ext:tamaya-model+ |Provides support documenting ang validating configuration during runtime. |link:mod_model.html[Documentation]
|+org.apache.tamaya.ext:tamaya-functions+ |Provides several functional extension points. |link:mod_functions.html[Documentation]
|+org.apache.tamaya.ext:tamaya-management+ |Provides JMX support for inspecting configuration. |link:mod_management.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-server+ |Lets a Tamaya configuration instance provide scoped configuration as a http service. |link:mod_server.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-remote+ |Provides remote configuration support. |link:mod_remote.html[Documentation]
|=======
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/client/pom.xml
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/pom.xml b/examples/8-remote-example/client/pom.xml
new file mode 100644
index 0000000..fab1113
--- /dev/null
+++ b/examples/8-remote-example/client/pom.xml
@@ -0,0 +1,79 @@
+<!--
+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 current 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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tamaya.examples</groupId>
+ <artifactId>tamaya-example-remote</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-example-remote-client</artifactId>
+ <name>Apache Tamaya Example: Remote (Client)</name>
+ <description>This project contains the configuration client (using the remote
+ module) of the remote example.
+ </description>
+ <packaging>jar</packaging>
+
+ <properties>
+ <jdk.verion>1.7</jdk.verion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-api</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-core</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-remote</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-catalina</artifactId>
+ <version>7.0.41</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-util</artifactId>
+ <version>7.0.41</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ <version>7.0.41</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-functions</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
new file mode 100644
index 0000000..b9cdd61
--- /dev/null
+++ b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/Client.java
@@ -0,0 +1,93 @@
+/*
+ * 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.tamaya.examples.remote.client;
+
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.startup.Tomcat;
+
+import org.apache.catalina.Context;
+import org.apache.tamaya.ConfigurationProvider;
+
+import java.io.File;
+
+/**
+ * Simple Remote client class. Usage:
+ * {@code java -jar tamaya-remote-client.jar [-Dport=<port>][-DclientId=<clientId>]}.
+ * Hereby the clientId is used as a scope identifier passed as a parameter to the
+ * configuration server to define the effective configuration to be provided to
+ * the client. Hereby this class also reads the port to be used from the remote
+ * configuration server.
+ */
+public class Client {
+
+ /**
+ * Util class constructor.
+ */
+ private Client(){}
+
+ /**
+ * Main method. Usage:
+ * {@code java -jar tamaya-remote-client.jar [-Dport=<port>][-DclientId=<clientId>]}.
+ * @param args the arguments passed.
+ */
+ public static void main(String... args){
+ // init configuration
+ Tomcat tomcat = new Tomcat();
+
+ String portValue = System.getProperty("port");
+ if(portValue==null){
+ portValue = ConfigurationProvider.getConfiguration().get("port");
+ }
+ int port = portValue!=null?Integer.parseInt(portValue):8080;
+ tomcat.setPort(port);
+ File base = new File(System.getProperty("java.io.tmpdir"));
+ Context rootCtx = tomcat.addContext("/client", base.getAbsolutePath());
+ Tomcat.addServlet(rootCtx, "printConfigServlet", new PrintConfigServlet());
+ rootCtx.addServletMapping("/config", "printConfigServlet");
+ try {
+ System.out.println("Starting client: " + getClientId() + " with port " + port);
+ tomcat.start();
+ } catch (LifecycleException e) {
+ e.printStackTrace();
+ }
+ tomcat.getServer().await();
+ }
+
+ /**
+ * Evaluates the current client id in the following order:
+ * <ul>
+ * <li>Checking for an <b>environment</b> variable CLIENT_ID</li>
+ * <li>Checking for a system property <b>clientId</b>.</li>
+ * <li>If not found <i>default</i> is returned.</li>
+ * </ul>
+ * @return the client identifier to be used.
+ */
+ public static String getClientId() {
+ String clientId = System.getenv("CLIENT_ID");
+ if(clientId == null){
+ clientId = System.getProperty("clientId");
+ }
+ if(clientId == null){
+ clientId = "default";
+ }
+ return clientId;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/PrintConfigServlet.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/PrintConfigServlet.java b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/PrintConfigServlet.java
new file mode 100644
index 0000000..b5095a5
--- /dev/null
+++ b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/PrintConfigServlet.java
@@ -0,0 +1,75 @@
+/*
+ * 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.tamaya.examples.remote.client;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * S simple servlet, which simply prints out the current local configuration. This is useful to demonstrate the
+ * different client configurations read.
+ */
+public class PrintConfigServlet extends HttpServlet {
+
+ /** Serial UID. */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The client id used.
+ */
+ private String clientId = Client.getClientId();
+ /**
+ * The current info map, containing the clientId. This is passed to be added to the configuration's info section
+ * when shows.
+ */
+ private Map<String,String> info = new HashMap<>();
+
+ /**
+ * Constructor.
+ */
+ public PrintConfigServlet(){
+ info.put("clientId", clientId);
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setHeader("CONTENT-TYPE", "text/html");
+ Map<String,String> info = new HashMap<>();
+ info.put("clientId", clientId);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ String filter = req.getContextPath();
+ if (filter != null) {
+ info.put("filter", filter);
+ resp.getWriter().append(ConfigurationProvider.getConfiguration().with(ConfigurationFunctions
+ .sectionRecursive(false, filter)).query(ConfigurationFunctions.htmlInfo(info)));
+ } else {
+ info.put("filter", ".*");
+ resp.getWriter().append(ConfigurationProvider.getConfiguration().query(ConfigurationFunctions.htmlInfo(info)));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java
new file mode 100644
index 0000000..1d66caa
--- /dev/null
+++ b/examples/8-remote-example/client/src/main/java/org/apache/tamaya/examples/remote/client/RemotePropertySource.java
@@ -0,0 +1,62 @@
+/*
+ * 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.tamaya.examples.remote.client;
+
+import org.apache.tamaya.remote.BaseRemotePropertySource;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Property Resource, which reads configuration dat from the (local) configuration server. Normally also the config
+ * server should be configured, e.g. using system or environment properties.
+ */
+public class RemotePropertySource extends BaseRemotePropertySource{
+ /** Current remote property source default ordinal. */
+ private static final int REMOTE_ORDINAL = 15000;
+
+ @Override
+ public int getDefaultOrdinal(){
+ return REMOTE_ORDINAL;
+ }
+
+ @Override
+ protected Collection<URL> getAccessURLs() {
+ try {
+ String configServerUrl = System.getenv("CONFIG_SERVER");
+ if(configServerUrl==null){
+ configServerUrl = System.getProperty("configServer");
+ }
+ if(configServerUrl==null){
+ configServerUrl = "http://localhost:8888/config?scope=CLIENT&scopeId={clientId}&format=application/json";
+ }
+ System.out.println("Reading config from " + configServerUrl.replace("{clientId}", Client.getClientId()));
+ return Arrays.asList(new URL[]{new URL(configServerUrl.replace("{clientId}", Client.getClientId()))});
+ } catch (MalformedURLException e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to configure remote config location,", e);
+ return Collections.emptySet();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..63d9a5b
--- /dev/null
+++ b/examples/8-remote-example/client/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.examples.remote.client.RemotePropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/pom.xml b/examples/8-remote-example/pom.xml
new file mode 100644
index 0000000..8c0e51b
--- /dev/null
+++ b/examples/8-remote-example/pom.xml
@@ -0,0 +1,79 @@
+<!--
+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 current 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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-examples</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-example-remote</artifactId>
+ <groupId>org.apache.tamaya.examples</groupId>
+ <name>Apache Tamaya Example: Remote</name>
+ <description>This project contains a multi module project defining a configuration server (using the server
+ module) and multiple remote clients that read their configs from the server using the server's rest API
+ (using the remote module).
+ </description>
+ <packaging>pom</packaging>
+
+ <properties>
+ <jdk.verion>1.7</jdk.verion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-api</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-core</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-resources</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <modules>
+ <module>server</module>
+ <module>client</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/server/pom.xml
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/pom.xml b/examples/8-remote-example/server/pom.xml
new file mode 100644
index 0000000..a8fd287
--- /dev/null
+++ b/examples/8-remote-example/server/pom.xml
@@ -0,0 +1,63 @@
+<!--
+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 current 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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tamaya.examples</groupId>
+ <artifactId>tamaya-example-remote</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-example-remote-server</artifactId>
+ <name>Apache Tamaya Example: Remote (Server)</name>
+ <description>This project contains the configuration server (using the server
+ module) of the remote example.
+ </description>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-core</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-api</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-server</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java b/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java
new file mode 100644
index 0000000..16f3e7c
--- /dev/null
+++ b/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/ClientScopeProvider.java
@@ -0,0 +1,49 @@
+/*
+ * 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.tamaya.examples.remote.server;
+
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.server.spi.ScopeProvider;
+
+
+/**
+ * Implementation of a {@link ScopeProvider} that registers a {@link ConfigOperator} that
+ * filters out and combines a configuration subsection identified by
+ * {@code client.default, client.<CLIENTID>}.
+ */
+public class ClientScopeProvider implements ScopeProvider{
+
+ /**
+ * Access the unique scope name.
+ * @return the unique scope name.
+ */
+ public String getScopeType(){
+ return "CLIENT";
+ }
+
+ @Override
+ public ConfigOperator getScope(String scopeId) {
+ return c ->
+ ConfigurationFunctions.combine("Scoped Config CLIENT="+scopeId,
+ c.with(ConfigurationFunctions.sectionRecursive(true, "client.default")),
+ c.with(ConfigurationFunctions.sectionRecursive(true, "client." + scopeId))
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java b/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java
new file mode 100644
index 0000000..f4372cf
--- /dev/null
+++ b/examples/8-remote-example/server/src/main/java/org/apache/tamaya/examples/remote/server/Start.java
@@ -0,0 +1,63 @@
+/*
+ * 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.tamaya.examples.remote.server;
+
+
+import org.apache.tamaya.server.Server;
+
+
+/**
+ * Main class to start the server part of this example. Usage:
+ * <pre>
+ * java org.apache.tamaya.examples.remote.server.Start [-Dport=1234]
+ * </pre>
+ * The optional port value hereby overrides any port value received from the remote configuration.
+ * By default port 8888 is used.
+ */
+public class Start {
+
+ /**
+ * Utility class only.
+ */
+ private Start(){}
+
+ /**
+ * Mein methods. Usage:
+ * <pre>
+ * java org.apache.tamaya.examples.remote.server.Start [-Dport=1234]
+ * </pre>
+ * The optional port value hereby overrides any port value received from the remote configuration.
+ * By default port 8888 is used.
+ * @param args the args passed.
+ */
+ public static void main(String... args){
+ // init configuration
+ String portValue = System.getProperty("port");
+ int port = portValue!=null?Integer.parseInt(portValue):8888;
+ try {
+ System.out.println("Starting server with port " + port);
+ Server server = org.apache.tamaya.server.ConfigServer.createServer();
+ server.start(port);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/server/src/main/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/resources/META-INF/javaconfiguration.properties b/examples/8-remote-example/server/src/main/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..adf63e5
--- /dev/null
+++ b/examples/8-remote-example/server/src/main/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,29 @@
+#
+# 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 current 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.
+#
+client.default.name=Default Client
+client.default.port=8000
+client.default.stage=TEST
+clinet.default.security=none
+client.client1.name=client1
+client.client1.port=8001
+client.client2.port=8002
+client.client3.port=8003
+client.client4.port=8004
+client.client5.port=8005
+client.client6.port=8006
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider
----------------------------------------------------------------------
diff --git a/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider b/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider
new file mode 100644
index 0000000..52e219c
--- /dev/null
+++ b/examples/8-remote-example/server/src/main/resources/META-INF/services/org.apache.tamaya.server.spi.ScopeProvider
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.examples.remote.server.ClientScopeProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index c1fb5e1..02c330e 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -40,7 +40,7 @@ under the License.
<module>6-fileobserver-example</module>
<module>5-injection-example</module>
<module>7-builder-example</module>
- <!-- module>server-example</module -->
+ <module>8-remote-example</module>
</modules>
<build>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java b/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
new file mode 100644
index 0000000..0d3dee9
--- /dev/null
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
@@ -0,0 +1,112 @@
+/*
+ * 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.tamaya.functions;
+
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.ConfigQuery;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Combines a set of child configurations to a new one, by overriding the first entries with result from
+ * later instances.
+ */
+class CombinedConfiguration implements Configuration{
+ /** The name of the new configuration. */
+ private String name;
+ /** The configuration's in evaluation order. Instances with higher indices override results with lower ones. */
+ private Configuration[] configurations;
+
+ /**
+ * Creates a combined configuration instance.
+ * @param configName the name of the new config.
+ * @param configs the configurations hereby instances with higher indices override results with lower ones.
+ */
+ public CombinedConfiguration(String configName, Configuration... configs){
+ this.name = configName;
+ this.configurations =configs.clone();
+ }
+
+ @Override
+ public String get(String key) {
+ String curValue = null;
+ for(Configuration config: configurations){
+ String value = config.get(key);
+ if(value!=null){
+ curValue = value;
+ }
+ }
+ return curValue;
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ T curValue = null;
+ for(Configuration config: configurations){
+ T value = config.get(key, type);
+ if(value!=null){
+ curValue = value;
+ }
+ }
+ return curValue;
+ }
+
+ @Override
+ public <T> T get(String key, TypeLiteral<T> type) {
+ T curValue = null;
+ for(Configuration config: configurations){
+ T value = config.get(key, type);
+ if(value!=null){
+ curValue = value;
+ }
+ }
+ return curValue;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> result = new HashMap<>();
+ for(Configuration ps:configurations){
+ result.putAll(ps.getProperties());
+ }
+ return result;
+ }
+
+ @Override
+ public Configuration with(ConfigOperator operator) {
+ return operator.operate(this);
+ }
+
+ @Override
+ public <T> T query(ConfigQuery<T> query) {
+ return query.query(this);
+ }
+
+ @Override
+ public String toString() {
+ return "CombinedConfiguration{" +
+ "name='" + name + '\'' +
+ ", configurations=" + Arrays.toString(configurations) +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
new file mode 100644
index 0000000..2c32c82
--- /dev/null
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
@@ -0,0 +1,79 @@
+/*
+ * 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.tamaya.functions;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * PropertySource that wraps a Configuration instance.
+ */
+final class ConfigWrappingPropertySource implements PropertySource {
+ /** The property source name. */
+ private String name;
+ /** The ordinal. */
+ private int ordinal;
+ /** The wrapped config. */
+ private Configuration config;
+
+ /**
+ * Constructor.
+ * @param name the property source name, not null.
+ * @param ordinal ths ordinal
+ * @param config the wrapped config, not null.
+ */
+ public ConfigWrappingPropertySource(String name, int ordinal, Configuration config){
+ this.name = Objects.requireNonNull(name);
+ this.ordinal = ordinal;
+ this.config = Objects.requireNonNull(config);
+ }
+
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String get(String key) {
+ return config.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return config.getProperties();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+
+ @Override
+ public String toString(){
+ return "ConfigWrappingPropertySource(name="+name+", ordinal="+ordinal+", config="+config+")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index efcc053..a0da2fd 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.functions;
import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.PropertySource;
import java.net.Inet4Address;
import java.util.Arrays;
@@ -43,33 +44,6 @@ public final class ConfigurationFunctions {
private static final Logger LOG = Logger.getLogger(ConfigurationFunctions.class.getName());
- private static void addFooter(StringBuilder b) {
- b.append("</body>\n</html>\n");
- }
-
- private static void addHeader(StringBuilder b) {
- String host = "unknown";
- try {
- host = Inet4Address.getLocalHost().getHostName();
- } catch (Exception e) {
- LOG.log(Level.INFO, "Failed to lookup hostname.", e);
- }
- b.append("<html>\n<head><title>System Configuration</title></head>\n" +
- "<body>\n" +
- "<h1>Sysem Configuration</h1>\n" +
- "<p>This view shows the system configuration of " + host + " at " + new Date() + ".</p>");
-
- }
-
- /**
- * Replaces new lines, returns, tabs and '"' with escaped variants.
- *
- * @param text the input text, not null
- * @return the escaped text.
- */
- private static String escape(String text) {
- return text.replace("\t", "\\t").replace("\"", "\\\"");
- }
/**
* Private singleton constructor.
@@ -163,11 +137,11 @@ public final class ConfigurationFunctions {
*/
public static boolean isKeyInSection(String key, String sectionKey) {
int lastIndex = key.lastIndexOf('.');
- if(lastIndex<0){
+ if (lastIndex < 0) {
return false;
}
String curAreaKey = key.substring(0, lastIndex);
- if(curAreaKey.startsWith(sectionKey)){
+ if (curAreaKey.startsWith(sectionKey)) {
return true;
}
return false;
@@ -301,6 +275,30 @@ public final class ConfigurationFunctions {
}
/**
+ * Creates a Configuration that creates a new instance using the configuration instances provided. Hereby
+ * values from higher instances override previous values..
+ *
+ * @param configName the new config name
+ * @param configs the configs to be combined. The entries of the first config are overwritten
+ * by entries of the later instances.
+ * @return the resulting configuration instance.
+ */
+ public static Configuration combine(String configName, Configuration... configs) {
+ return new CombinedConfiguration(configName, configs);
+ }
+
+ /**
+ * Creates a {@link PropertySource}, based on the given {@link Configuration}. The keys and propertx map
+ * are dynamically calculated, so the returned PropertySource is a real dynamic wrapper.
+ * @param name the name of the property source, not null.
+ * @param config the config to be mapped, not null.
+ * @return a property source wrapping the configuration.
+ */
+ public static PropertySource propertySourceFrom(final String name, final int ordinal, final Configuration config){
+ return new ConfigWrappingPropertySource(name, ordinal, config);
+ }
+
+ /**
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given section (recursive).
*
@@ -333,6 +331,7 @@ public final class ConfigurationFunctions {
/**
* Creates a ConfigQuery that creates a JSON formatted ouitput of all properties in the given configuration.
+ *
* @return the given query.
*/
public static ConfigQuery<String> jsonInfo() {
@@ -341,30 +340,40 @@ public final class ConfigurationFunctions {
/**
* Creates a ConfigQuery that creates a JSON formatted ouitput of all properties in the given configuration.
+ *
* @param info the additional information attributes to be added to the output, e.g. the original request
* parameters.
* @return the given query.
*/
- public static ConfigQuery<String> jsonInfo(final Map<String,String> info) {
+ public static ConfigQuery<String> jsonInfo(final Map<String, String> info) {
return new ConfigQuery<String>() {
@Override
public String query(Configuration config) {
StringBuilder builder = new StringBuilder();
Map<String, String> props = new TreeMap<>(config.getProperties());
- builder.append("\"configuration\": {\n")
+ builder.append("{\n")
+ .append(" \"type\": \"Configuration\",\n")
.append(" \"class\": \"" + config.getClass().getName() + "\",\n")
.append(" \"timestamp\": " + System.currentTimeMillis() + ",\n");
- if (info!=null && !info.isEmpty()) {
+ if (info != null && !info.isEmpty()) {
builder.append(" \"info\": {\n");
for (Map.Entry<String, String> en : info.entrySet()) {
builder.append(" \"" + escape(en.getKey()) + "\": \"" + escape(en.getValue()) + "\",\n");
}
+ if(builder.toString().endsWith("\",\n") || builder.toString().endsWith(",\n")){
+ builder.setLength(builder.length()-2);
+ builder.append('\n');
+ }
builder.append(" },\n");
}
builder.append(" \"data\": {\n");
for (Map.Entry<String, String> en : props.entrySet()) {
builder.append(" \"" + escape(en.getKey()) + "\": \"" + escape(en.getValue()) + "\",\n");
}
+ if(builder.toString().endsWith(",\n")){
+ builder.setLength(builder.length()-2);
+ builder.append('\n');
+ }
builder.append(" }\n}");
return builder.toString();
}
@@ -382,11 +391,12 @@ public final class ConfigurationFunctions {
/**
* Creates a ConfigQuery that creates a XML formatted ouitput of all properties in the given configuration.
+ *
* @param info the additional information attributes to be added to the output, e.g. the original request
* parameters.
* @return the given query.
*/
- public static ConfigQuery<String> xmlInfo(final Map<String,String> info) {
+ public static ConfigQuery<String> xmlInfo(final Map<String, String> info) {
return new ConfigQuery<String>() {
@Override
public String query(Configuration config) {
@@ -395,7 +405,7 @@ public final class ConfigurationFunctions {
builder.append("<configuration>\n")
.append(" <class>" + config.getClass().getName() + "</class>\n")
.append(" <timestamp>" + System.currentTimeMillis() + "</timestamp>\n");
- if (info!=null && !info.isEmpty()) {
+ if (info != null && !info.isEmpty()) {
builder.append(" <info>\n");
for (Map.Entry<String, String> en : info.entrySet()) {
builder.append(" <entry key=\"" + escape(en.getKey()) + "\">" + escape(en.getValue()) + "</entry>\n");
@@ -426,7 +436,7 @@ public final class ConfigurationFunctions {
*
* @return the given query.
*/
- public static ConfigQuery<String> textInfo(final Map<String,String> info) {
+ public static ConfigQuery<String> textInfo(final Map<String, String> info) {
return new ConfigQuery<String>() {
@Override
public String query(Configuration config) {
@@ -465,7 +475,7 @@ public final class ConfigurationFunctions {
*
* @return the given query.
*/
- public static ConfigQuery<String> htmlInfo(final Map<String,String> info) {
+ public static ConfigQuery<String> htmlInfo(final Map<String, String> info) {
return new ConfigQuery<String>() {
@Override
public String query(Configuration config) {
@@ -478,4 +488,33 @@ public final class ConfigurationFunctions {
};
}
+ private static void addFooter(StringBuilder b) {
+ b.append("</body>\n</html>\n");
+ }
+
+ private static void addHeader(StringBuilder b) {
+ String host = "unknown";
+ try {
+ host = Inet4Address.getLocalHost().getHostName();
+ } catch (Exception e) {
+ LOG.log(Level.INFO, "Failed to lookup hostname.", e);
+ }
+ b.append("<html>\n<head><title>System Configuration</title></head>\n" +
+ "<body>\n" +
+ "<h1>Sysem Configuration</h1>\n" +
+ "<p>This view shows the system configuration of " + host + " at " + new Date() + ".</p>");
+
+ }
+
+ /**
+ * Replaces new lines, returns, tabs and '"' with escaped variants.
+ *
+ * @param text the input text, not null
+ * @return the escaped text.
+ */
+ private static String escape(String text) {
+ return text.replace("\t", "\\t").replace("\"", "\\\"");
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java b/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
index 5a8a121..b3abf72 100644
--- a/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
+++ b/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
@@ -43,7 +43,6 @@ public class ManagedConfigTest {
assertNotNull(info);
assertTrue(info.contains("java.version"));
System.out.println(bean.getJsonConfigurationInfo());
- assertTrue(info.contains("\"configuration\": "));
}
@org.junit.Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index 08863c3..a2b34ff 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -43,6 +43,8 @@ under the License.
<module>functions</module>
<module>model</module>
<module>management</module>
+ <module>server</module>
+ <module>remote</module>
</modules>
<build>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/remote/pom.xml
----------------------------------------------------------------------
diff --git a/modules/remote/pom.xml b/modules/remote/pom.xml
new file mode 100644
index 0000000..453b896
--- /dev/null
+++ b/modules/remote/pom.xml
@@ -0,0 +1,55 @@
+<!--
+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 current 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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-extensions</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-remote</artifactId>
+ <name>Apache Tamaya Remote PropertySource</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java b/modules/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
new file mode 100644
index 0000000..e3f46b3
--- /dev/null
+++ b/modules/remote/src/main/java/org/apache/tamaya/remote/BaseRemotePropertySource.java
@@ -0,0 +1,150 @@
+/*
+ * 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.tamaya.remote;
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormat;
+import org.apache.tamaya.json.JSONFormat;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Abstract base class for implementing a PropertySource that reads configuration data from a remote resource. It uses
+ * by default the JSON format as defined by the JSON module.
+ */
+public abstract class BaseRemotePropertySource implements PropertySource{
+
+ private static final ConfigurationFormat DEFAULT_FORMAT = new JSONFormat();
+
+ private Map<String,String> properties = new HashMap<>();
+
+ protected BaseRemotePropertySource(){
+ reload();
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getSimpleName();
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ /**
+ * Reloads the remote configuration. If reloads fails to whatever reasons the already loaded configuration will
+ * stay untouched.
+ */
+ public void reload(){
+ ConfigurationFormat format = getConfigurationFormat();
+ for(URL url:getAccessURLs()) {
+ try(InputStream is = url.openStream()) {
+ ConfigurationData data = format.readConfiguration(url.toExternalForm(), is);
+ if(data!=null){
+ Map<String,String> newProperties = mapConfigurationData(data);
+ // the configs served by the tamaya server module has a 'data' root section containing the
+ // config entries. if not present, we assume an alternate format, which is sued as is...
+ if(!newProperties.isEmpty()){
+ this.properties = newProperties;
+ Logger.getLogger(getClass().getName()).info(
+ "Reloaded remote config from: " + url + ", entriea read: " + this.properties.size());
+ }
+ }
+ }
+ catch(Exception e){
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to load config from url: " + url, e);
+ }
+ }
+ }
+
+ protected abstract Collection<URL> getAccessURLs();
+
+ protected ConfigurationFormat getConfigurationFormat(){
+ return DEFAULT_FORMAT;
+ }
+
+ protected Map<String,String> mapConfigurationData(ConfigurationData data){
+ Map<String,String> readProperties;
+ if(data!=null){
+ readProperties = data.getCombinedProperties();
+ if(readProperties!=null){
+ Map<String,String> newProperties = new HashMap<>();
+ for(Map.Entry<String,String> en:readProperties.entrySet()){
+ // filter data entries
+ if(en.getKey().startsWith("data.")) {
+ newProperties.put(en.getKey().substring(5), en.getValue());
+ }
+ }
+ // the configs served by the tamaya server module has a 'data' root section containing the
+ // config entries. if not present, we assume an alternate format, which is sued as is...
+ if(newProperties.isEmpty()){
+ Logger.getLogger(getClass().getName()).info(
+ "Loaded remote config from: " + data.getResource() + ", does not have a data section, using as is...");
+ newProperties = readProperties;
+ }
+ Logger.getLogger(getClass().getName()).info(
+ "Reloaded remote config from: " + data.getResource() + ", entriea read: " + this.properties.size());
+ return newProperties;
+ }
+ }
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable(){
+ return true;
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public int getOrdinal(){
+ String configuredOrdinal = get(TAMAYA_ORDINAL);
+ if(configuredOrdinal!=null){
+ try{
+ return Integer.parseInt(configuredOrdinal);
+ } catch(Exception e){
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e,
+ () -> "Configured Ordinal is not an int number: " + configuredOrdinal);
+ }
+ }
+ return getDefaultOrdinal();
+ }
+
+ /**
+ * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
+ * @return the default ordinal used, by default 0.
+ */
+ public int getDefaultOrdinal(){
+ return 0;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/pom.xml
----------------------------------------------------------------------
diff --git a/modules/server/pom.xml b/modules/server/pom.xml
new file mode 100644
index 0000000..416d783
--- /dev/null
+++ b/modules/server/pom.xml
@@ -0,0 +1,72 @@
+<!--
+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 current 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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-extensions</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-server</artifactId>
+ <name>Apache Tamaya Modules: Server Extension</name>
+ <packaging>jar</packaging>
+
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>tamaya-json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>tamaya-functions</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>apache-cxf</artifactId>
+ <type>pom</type>
+ <version>3.1.2</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/ConfigServer.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/ConfigServer.java b/modules/server/src/main/java/org/apache/tamaya/server/ConfigServer.java
new file mode 100644
index 0000000..0a3f737
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/ConfigServer.java
@@ -0,0 +1,44 @@
+/*
+ * 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.tamaya.server;
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Simple abstraction of the Server interface.
+ */
+public final class ConfigServer {
+ /**
+ * Utility class constructor.
+ */
+ private ConfigServer(){}
+
+ /**
+ * Creates a new server instance.
+ * @return a new server instance.
+ */
+ public static Server createServer(){
+ return ServiceContextManager.getServiceContext().getService(Server.class);
+ }
+
+ public static void main(String... args){
+ createServer().start(8888);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/Server.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/Server.java b/modules/server/src/main/java/org/apache/tamaya/server/Server.java
new file mode 100644
index 0000000..5e2cb52
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/Server.java
@@ -0,0 +1,46 @@
+/*
+ * 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.tamaya.server;
+
+/**
+ * Simple abstraction of the Server interface.
+ */
+public interface Server {
+ /**
+ * Starts the server on the given port-
+ * @param port the target port.
+ */
+ void start(int port);
+
+ /**
+ * Checks if the server us started.
+ * @return true if the server us started.
+ */
+ boolean isStarted();
+
+ /**
+ * Stops the server, but does not destroy it, so it might be restarted.
+ */
+ void stop();
+
+ /**
+ * Destroy the server instance.
+ */
+ void destroy();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2c64ac02/modules/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java b/modules/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java
new file mode 100644
index 0000000..36704bf
--- /dev/null
+++ b/modules/server/src/main/java/org/apache/tamaya/server/internal/CXFServer.java
@@ -0,0 +1,82 @@
+/*
+ * 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.tamaya.server.internal;
+
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.tamaya.server.Server;
+
+/**
+ * CXF based implementation of a JAX-RS server, serving the {@link DefaultConfigService} service.
+ */
+public class CXFServer implements Server {
+ /** The CXF endpoint. */
+ private org.apache.cxf.endpoint.Server cxfEndpoint;
+
+ /**
+ * Starts the CXF server under the port.
+ * @param port the port.
+ */
+ public void start(int port) {
+ if(cxfEndpoint!=null){
+ if(cxfEndpoint.isStarted()){
+ return;
+ }
+ // start it at the end...
+ } else {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ DefaultConfigService confService = new DefaultConfigService();
+ sf.setServiceBeanObjects(confService);
+ sf.setAddress("http://localhost:" + port + "/");
+ cxfEndpoint = sf.create();
+ }
+ cxfEndpoint.start();
+ }
+
+ /**
+ * Returns the current started state.
+ * @return true, if the server is started.
+ */
+ public boolean isStarted(){
+ if(cxfEndpoint!=null){
+ return cxfEndpoint.isStarted();
+ }
+ return false;
+ }
+
+ /**
+ * Stops the server if running.
+ */
+ public void stop(){
+ if(cxfEndpoint!=null){
+ cxfEndpoint.stop();
+ }
+ }
+
+ /**
+ * Destroy the server.
+ */
+ public void destroy(){
+ if(cxfEndpoint!=null){
+ cxfEndpoint.destroy();
+ cxfEndpoint = null;
+ }
+ }
+
+}
\ No newline at end of file