Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 45099 invoked from network); 3 Dec 2008 17:39:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Dec 2008 17:39:33 -0000 Received: (qmail 15341 invoked by uid 500); 3 Dec 2008 17:39:45 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 15299 invoked by uid 500); 3 Dec 2008 17:39:45 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 15290 invoked by uid 99); 3 Dec 2008 17:39:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Dec 2008 09:39:44 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Dec 2008 17:38:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0DC0A238898E; Wed, 3 Dec 2008 09:38:33 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r722981 - in /incubator/sling/trunk/extensions/jcrinstall: service/ service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/ service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ servlet/ servlet/src/ servlet/src/main/ servlet/s... Date: Wed, 03 Dec 2008 17:38:31 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081203173833.0DC0A238898E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Wed Dec 3 09:38:30 2008 New Revision: 722981 URL: http://svn.apache.org/viewvc?rev=722981&view=rev Log: SLING-755 - Move /system/sling/jcrinstall servlet to its own bundle Added: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java (with props) incubator/sling/trunk/extensions/jcrinstall/servlet/ (with props) incubator/sling/trunk/extensions/jcrinstall/servlet/pom.xml (with props) incubator/sling/trunk/extensions/jcrinstall/servlet/src/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java (with props) Modified: incubator/sling/trunk/extensions/jcrinstall/service/pom.xml incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml Modified: incubator/sling/trunk/extensions/jcrinstall/service/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/pom.xml?rev=722981&r1=722980&r2=722981&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/service/pom.xml (original) +++ incubator/sling/trunk/extensions/jcrinstall/service/pom.xml Wed Dec 3 09:38:30 2008 @@ -83,11 +83,6 @@ org.apache.sling - org.apache.sling.api - 2.0.3-incubator-SNAPSHOT - - - org.apache.sling org.apache.sling.jcr.api 2.0.2-incubator Added: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java?rev=722981&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java Wed Dec 3 09:38:30 2008 @@ -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 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.jcr.jcrinstall.jcr; + +/** Service interface for jcrinstall */ +public interface JcrInstallService { + /** Enable or disable the service - used to simulate a disappearing + * repository in integration tests + */ + void enable(boolean enabled) throws IllegalStateException; + + boolean isEnabled(); +} Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/JcrInstallService.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=722981&r1=722980&r2=722981&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Wed Dec 3 09:38:30 2008 @@ -19,13 +19,10 @@ package org.apache.sling.jcr.jcrinstall.jcr.impl; import java.io.File; -import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.SortedSet; @@ -37,17 +34,13 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.observation.Event; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.SlingHttpServletResponse; -import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.jcr.jcrinstall.jcr.JcrInstallService; import org.apache.sling.jcr.jcrinstall.jcr.NodeConverter; import org.apache.sling.jcr.jcrinstall.osgi.OsgiController; import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules; -import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkEvent; import org.osgi.framework.FrameworkListener; import org.osgi.framework.ServiceReference; @@ -73,10 +66,8 @@ * @scr.property * name="service.vendor" * value="The Apache Software Foundation" - * @scr.property name="sling.servlet.paths" value="/system/sling/jcrinstall" */ -@SuppressWarnings("serial") -public class RepositoryObserver extends SlingAllMethodsServlet implements Runnable, FrameworkListener { +public class RepositoryObserver implements Runnable, FrameworkListener, JcrInstallService { private final SortedSet folders = new TreeSet(); private RegexpFilter folderNameFilter; @@ -87,8 +78,6 @@ private boolean observationCycleActive; private boolean activated; - public static final String POST_ENABLE_PARAM = "enabled"; - /** @scr.reference */ protected OsgiController osgiController; @@ -513,76 +502,35 @@ return folders; } - /** A POST can be used to deactivate/reactivate this, simulating a disappearing SlingRepository. - * Used for integration testing. + /** Enable or disable this, disabling must be done in the same way as when + * the repository disappears. */ - @Override - protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) - throws ServletException, IOException { - final String enable = request.getParameter(POST_ENABLE_PARAM); - if(enable != null) { - if(Boolean.parseBoolean(enable)) { - log.info("Processing POST with {}=true, attempting to bind SlingRepository", POST_ENABLE_PARAM); - if(repository != null) { - response.sendError(HttpServletResponse.SC_CONFLICT, "Already enabled"); - return; - } - if(componentContext == null) { - response.sendError(HttpServletResponse.SC_EXPECTATION_FAILED, "No ComponentContext, cannot enable service"); - return; - } - final ServiceReference ref = componentContext.getBundleContext().getServiceReference(SlingRepository.class.getName()); - if(ref == null) { - response.sendError(HttpServletResponse.SC_EXPECTATION_FAILED, "No SlingRepository ServiceReference available"); - return; - } - - final SlingRepository r = (SlingRepository)componentContext.getBundleContext().getService(ref); - bindSlingRepository(r); - - } else { - log.info("Processing POST with {}=false, attempting to unbind SlingRepository", POST_ENABLE_PARAM); - if(repository == null) { - response.sendError(HttpServletResponse.SC_CONFLICT, "Not currently enabled, cannot disable"); - return; - } - unbindSlingRepository(repository); + public void enable(boolean enabled) throws IllegalStateException { + if(enabled) { + if(repository != null) { + throw new IllegalStateException("Already enabled"); } - } else { - response.sendError(HttpServletResponse.SC_BAD_REQUEST, - "Use '" + POST_ENABLE_PARAM + "' parameter to enable/disable the RepositoryObserver"); - return; - } - - doGet(request, response); - } - - /** Report on the jcrinstall enabled/disabled status, number of bundles in each state, etc. */ - @Override - protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) - throws ServletException, IOException - { - final Properties props = new Properties(); - - if(componentContext != null) { - // report on how many bundles we have in the different states - final Map states = new HashMap(); - for(Bundle b : componentContext.getBundleContext().getBundles()) { - final Integer s = new Integer(b.getState()); - Integer i = states.get(s); - i = i == null ? new Integer(1) : new Integer(i.intValue() + 1); - states.put(s, i); - } - - for(Map.Entry e : states.entrySet()) { - props.put("bundles.in.state." + e.getKey().toString(), e.getValue().toString()); - } - } - - props.put("osgi.start.level", String.valueOf(startLevel.getStartLevel())); - props.put("jcrinstall.enabled", new Boolean(repository != null).toString()); - - response.setContentType("text/plain"); - props.store(response.getOutputStream(), "jcrinstall status"); - } + if(componentContext == null) { + throw new IllegalStateException("No ComponentContext, cannot enable service"); + } + final ServiceReference ref = componentContext.getBundleContext().getServiceReference(SlingRepository.class.getName()); + if(ref == null) { + throw new IllegalStateException("No SlingRepository ServiceReference available, cannot enable service"); + } + + final SlingRepository r = (SlingRepository)componentContext.getBundleContext().getService(ref); + bindSlingRepository(r); + log.info("Service enabled by enable(true) call"); + } else { + if(repository == null) { + throw new IllegalStateException("Not currently enabled, cannot disable"); + } + unbindSlingRepository(repository); + log.info("Service disabled by enable(false) call"); + } + } + + public boolean isEnabled() { + return repository != null; + } } \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/servlet/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Wed Dec 3 09:38:30 2008 @@ -0,0 +1,13 @@ +target +bin +derby.log +*.iml +*.ipr +*.iws +.settings +.project +.classpath +.externalToolBuilders +maven-eclipse.xml + + Added: incubator/sling/trunk/extensions/jcrinstall/servlet/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/servlet/pom.xml?rev=722981&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/servlet/pom.xml (added) +++ incubator/sling/trunk/extensions/jcrinstall/servlet/pom.xml Wed Dec 3 09:38:30 2008 @@ -0,0 +1,97 @@ + + + + + 4.0.0 + + org.apache.sling + org.apache.sling.jcr.jcrinstall.parent + 2.0.3-incubator-SNAPSHOT + ../ + + + org.apache.sling.jcr.jcrinstall.servlet + 2.0.3-incubator-SNAPSHOT + bundle + + Sling - JCR OSGi Installer Servlet + + Information and control servlet for the jcrinstall service + + + + scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/extensions/jcrinstall/servlet + scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/extensions/jcrinstall/servlet + http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/servlet + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.sling.jcr.jcrinstall.servlet.* + + + + + + + + + org.apache.felix + org.osgi.core + + + org.apache.felix + org.osgi.compendium + + + org.apache.felix + org.apache.felix.configadmin + + + org.apache.sling + org.apache.sling.api + 2.0.2-incubator + + + javax.servlet + servlet-api + + + org.slf4j + slf4j-simple + + + org.apache.sling + org.apache.sling.jcr.jcrinstall + 2.0.3-incubator-SNAPSHOT + provided + + + \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/servlet/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java?rev=722981&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java Wed Dec 3 09:38:30 2008 @@ -0,0 +1,148 @@ +/* + * 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.jcr.jcrinstall.servlet; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingAllMethodsServlet; +import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.jcr.jcrinstall.jcr.JcrInstallService; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceReference; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.startlevel.StartLevel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Info and control servlet for jcrinstall. + * Created for integration tests, but might be + * generally useful for monitoring purposes. + * + * @scr.component + * label="jcrinstall servlet" + * description="Information and control servlet for jcrinstall" + * immediate="true" + * @scr.service + * @scr.property + * name="service.description" + * value="Sling jcrinstall Servlet" + * @scr.property + * name="service.vendor" + * value="The Apache Software Foundation" + * + * @scr.property name="sling.servlet.paths" value="/system/sling/jcrinstall" + */ +@SuppressWarnings("serial") +public class JcrInstallServlet extends SlingAllMethodsServlet { + + public static final String POST_ENABLE_PARAM = "enabled"; + + /** @scr.reference */ + protected StartLevel startLevel; + + private final Logger log = LoggerFactory.getLogger(getClass()); + private ComponentContext componentContext; + + protected void activate(ComponentContext context) { + componentContext = context; + } + + protected void deactivate(ComponentContext context) { + componentContext = null; + } + + protected JcrInstallService getJcrinstallService() { + JcrInstallService result = null; + if(componentContext != null) { + final ServiceReference ref = componentContext.getBundleContext().getServiceReference(JcrInstallService.class.getName()); + if(ref != null) { + result = (JcrInstallService)componentContext.getBundleContext().getService(ref); + } + } + return result; + } + + /** A POST can be used to deactivate/reactivate this, simulating a disappearing SlingRepository. + * Used for integration testing. + */ + @Override + protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) + throws ServletException, IOException { + final String enable = request.getParameter(POST_ENABLE_PARAM); + if(enable != null) { + final JcrInstallService jis = getJcrinstallService(); + if(jis == null) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "JcrInstallService is not available"); + + } else if(Boolean.parseBoolean(enable)) { + log.info("Processing POST with {}=true, enabling JcrInstallService", POST_ENABLE_PARAM); + jis.enable(true); + + } else { + log.info("Processing POST with {}=false, disabling JcrInstallService", POST_ENABLE_PARAM); + jis.enable(false); + } + } else { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, + "Use '" + POST_ENABLE_PARAM + "' parameter to enable/disable the RepositoryObserver"); + return; + } + + doGet(request, response); + } + + /** Report on the jcrinstall enabled/disabled status, number of bundles in each state, etc. */ + @Override + protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) + throws ServletException, IOException + { + final Properties props = new Properties(); + + if(componentContext != null) { + // report on how many bundles we have in the different states + final Map states = new HashMap(); + for(Bundle b : componentContext.getBundleContext().getBundles()) { + final Integer s = new Integer(b.getState()); + Integer i = states.get(s); + i = i == null ? new Integer(1) : new Integer(i.intValue() + 1); + states.put(s, i); + } + + for(Map.Entry e : states.entrySet()) { + props.put("bundles.in.state." + e.getKey().toString(), e.getValue().toString()); + } + } + + props.put("osgi.start.level", String.valueOf(startLevel.getStartLevel())); + final JcrInstallService jis = getJcrinstallService(); + final boolean jisState = jis == null ? false : jis.isEnabled(); + props.put("jcrinstall.enabled", new Boolean(jisState).toString()); + + response.setContentType("text/plain"); + props.store(response.getOutputStream(), "jcrinstall status"); + } +} \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/servlet/src/main/java/org/apache/sling/jcr/jcrinstall/servlet/JcrInstallServlet.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml?rev=722981&r1=722980&r2=722981&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml (original) +++ incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml Wed Dec 3 09:38:30 2008 @@ -726,6 +726,12 @@ 2.0.3-incubator-SNAPSHOT provided + + org.apache.sling + org.apache.sling.jcr.jcrinstall.servlet + 2.0.3-incubator-SNAPSHOT + provided +