This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-crankstart-test-services.git
commit bb987c43d67675430b9c767c9f0a7f236492d5d3 Author: Bertrand Delacretaz <[email protected]> AuthorDate: Fri May 2 08:13:56 2014 +0000 SLING-3528 - add test-services to prepare for config command testing git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1591823 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 65 ++++++++++++++++++++++ .../testservices/ConfigFactoryServlet.java | 61 ++++++++++++++++++++ .../testservices/SingleConfigServlet.java | 60 ++++++++++++++++++++ .../sling/crankstart/testservices/TestServlet.java | 65 ++++++++++++++++++++++ 4 files changed, 251 insertions(+) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..855f696 --- /dev/null +++ b/pom.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>19</version> + </parent> + + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.crankstart.test.services</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>bundle</packaging> + <name>Apache Sling Crankstart Test Services</name> + <description>Bundle used to test the Crankstart launcher</description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Private-Package>org.apache.sling.crankstart.*</Private-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.osgi</artifactId> + <version>2.2.0</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> +</project> diff --git a/src/main/java/org/apache/sling/crankstart/testservices/ConfigFactoryServlet.java b/src/main/java/org/apache/sling/crankstart/testservices/ConfigFactoryServlet.java new file mode 100644 index 0000000..105bc7f --- /dev/null +++ b/src/main/java/org/apache/sling/crankstart/testservices/ConfigFactoryServlet.java @@ -0,0 +1,61 @@ +/* + * 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.sling.crankstart.testservices; + +import java.util.Map; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; + +/** Servlet that requires a configuration, used to test the + * Crankstart initial config feature with factory configs + */ +@Component(immediate=true,configurationFactory=true, policy=ConfigurationPolicy.REQUIRE, metatype=true) +@Service(value=Servlet.class) +@Reference(name="httpService",referenceInterface=HttpService.class) +public class ConfigFactoryServlet extends TestServlet { + private static final long serialVersionUID = -6918378772515948579L; + + @Property(value="default message") + protected static final String PROP_MESSAGE = "message"; + + @Property(value="/default_path") + protected static final String PROP_PATH = "path"; + + @Activate + protected void activate(Map<String, Object> config) throws ServletException, NamespaceException { + message = PropertiesUtil.toString(config.get(PROP_MESSAGE), "no message"); + path = PropertiesUtil.toString(config.get(PROP_PATH), "no path"); + register(); + } + + @Deactivate + protected void deactivate(Map<String, Object> config) throws ServletException, NamespaceException { + unregister(); + } +} diff --git a/src/main/java/org/apache/sling/crankstart/testservices/SingleConfigServlet.java b/src/main/java/org/apache/sling/crankstart/testservices/SingleConfigServlet.java new file mode 100644 index 0000000..c01eeb1 --- /dev/null +++ b/src/main/java/org/apache/sling/crankstart/testservices/SingleConfigServlet.java @@ -0,0 +1,60 @@ +/* + * 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.sling.crankstart.testservices; + +import java.util.Map; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; + +/** Servlet with a non-factory configuration, used to test the + * Crankstart initial config feature + */ +@Component(immediate=true,metatype=true) +@Service(value=Servlet.class) +@Reference(name="httpService",referenceInterface=HttpService.class) +public class SingleConfigServlet extends TestServlet { + private static final long serialVersionUID = -6918378772515948581L; + + @Property(value="default message") + protected static final String PROP_MESSAGE = "message"; + + @Property(value="/default_path") + protected static final String PROP_PATH = "path"; + + @Activate + protected void activate(Map<String, Object> config) throws ServletException, NamespaceException { + message = PropertiesUtil.toString(config.get(PROP_MESSAGE), "no message"); + path = PropertiesUtil.toString(config.get(PROP_PATH), "/no_path"); + register(); + } + + @Deactivate + protected void deactivate(Map<String, Object> config) throws ServletException, NamespaceException { + unregister(); + } +} diff --git a/src/main/java/org/apache/sling/crankstart/testservices/TestServlet.java b/src/main/java/org/apache/sling/crankstart/testservices/TestServlet.java new file mode 100644 index 0000000..3d03789 --- /dev/null +++ b/src/main/java/org/apache/sling/crankstart/testservices/TestServlet.java @@ -0,0 +1,65 @@ +/* + * 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.sling.crankstart.testservices; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.osgi.service.http.HttpService; +import org.osgi.service.http.NamespaceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Base class for our test servlets */ +abstract class TestServlet extends HttpServlet { + private static final long serialVersionUID = -6918378772515948578L; + protected String message; + protected String path; + protected final Logger log = LoggerFactory.getLogger(getClass()); + + protected HttpService httpService; + + protected void register() throws ServletException, NamespaceException { + httpService.registerServlet(path, this, null, null); + log.info("Registered {} on path {}", this, path); + } + + protected void unregister() throws ServletException, NamespaceException { + httpService.unregister(path); + log.info("Unregistered path {}", path); + } + + protected void bindHttpService(HttpService s) { + httpService = s; + } + + protected void unbindHttpService(HttpService s) { + httpService = null; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/plain"); + resp.setCharacterEncoding("UTF-8"); + resp.getWriter().write(getClass().getSimpleName() + ":" + message); + resp.getWriter().flush(); + } +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
