You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/03/29 05:49:17 UTC
svn commit: r1789274 - in /sling/trunk/bundles/servlets/post: ./
src/main/java/org/apache/sling/servlets/post/impl/
src/main/java/org/apache/sling/servlets/post/impl/helper/
src/main/resources/OSGI-INF/
Author: cziegeler
Date: Wed Mar 29 05:49:17 2017
New Revision: 1789274
URL: http://svn.apache.org/viewvc?rev=1789274&view=rev
Log:
SLING-6721 : Migrate to R6 annotations, clean up dependencies
Removed:
sling/trunk/bundles/servlets/post/src/main/resources/OSGI-INF/
Modified:
sling/trunk/bundles/servlets/post/pom.xml
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostResponseWithErrorHandling.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java
Modified: sling/trunk/bundles/servlets/post/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/pom.xml?rev=1789274&r1=1789273&r2=1789274&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/pom.xml (original)
+++ sling/trunk/bundles/servlets/post/pom.xml Wed Mar 29 05:49:17 2017
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>29</version>
+ <version>30</version>
<relativePath />
</parent>
@@ -49,11 +49,6 @@
<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>
@@ -102,23 +97,12 @@
<artifactId>osgi.core</artifactId>
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.cmpn</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
- <version>2.0</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -137,12 +121,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.0.2-incubator</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java?rev=1789274&r1=1789273&r2=1789274&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostOperationProxyProvider.java Wed Mar 29 05:49:17 2017
@@ -23,9 +23,6 @@ import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.Map;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.servlets.HtmlResponse;
import org.apache.sling.servlets.post.PostOperation;
@@ -40,6 +37,9 @@ import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,11 +48,11 @@ import org.slf4j.LoggerFactory;
* {@link SlingPostOperation} services being registered and wraps them with a
* proxy for the new {@link PostOperation} API and registers the procies.
*/
-@Component(specVersion = "1.1", metatype = false)
+@Component
public class PostOperationProxyProvider implements ServiceListener {
private final Logger log = LoggerFactory.getLogger(getClass());
-
+
/**
* The service listener filter to listen for SlingPostOperation services
*/
@@ -61,7 +61,7 @@ public class PostOperationProxyProvider
// maps references to the SlingPostOperation services to the registrations
// of the PostOperation proxies for unregistration purposes
- private final Map<ServiceReference, ServiceRegistration> proxies = new IdentityHashMap<ServiceReference, ServiceRegistration>();
+ private final Map<ServiceReference, ServiceRegistration> proxies = new IdentityHashMap<>();
// The DS component context to access the services to proxy
private BundleContext bundleContext;
@@ -125,6 +125,7 @@ public class PostOperationProxyProvider
// ServiceEvent handling
+ @Override
public void serviceChanged(ServiceEvent event) {
/*
@@ -214,7 +215,7 @@ public class PostOperationProxyProvider
*/
private Dictionary<String, Object> copyServiceProperties(
final ServiceReference serviceReference) {
- final Dictionary<String, Object> props = new Hashtable<String, Object>();
+ final Dictionary<String, Object> props = new Hashtable<>();
for (String key : serviceReference.getPropertyKeys()) {
props.put(key, serviceReference.getProperty(key));
}
@@ -237,11 +238,13 @@ public class PostOperationProxyProvider
PostOperationProxy(final SlingPostOperation delegatee) {
this.delegatee = delegatee;
}
-
+
+ @Override
public String toString() {
return getClass().getSimpleName() + " for " + delegatee.getClass().getName();
}
+ @Override
public void run(SlingHttpServletRequest request, PostResponse response,
SlingPostProcessor[] processors) {
HtmlResponse apiResponse = new HtmlResponseProxy(response);
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostResponseWithErrorHandling.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostResponseWithErrorHandling.java?rev=1789274&r1=1789273&r2=1789274&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostResponseWithErrorHandling.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/PostResponseWithErrorHandling.java Wed Mar 29 05:49:17 2017
@@ -22,16 +22,14 @@ import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.servlets.post.HtmlResponse;
import org.apache.sling.servlets.post.PostResponse;
import org.apache.sling.servlets.post.PostResponseCreator;
import org.apache.sling.servlets.post.SlingPostConstants;
+import org.osgi.service.component.annotations.Component;
-@Component
-@Service
+@Component(service = PostResponseCreator.class)
public class PostResponseWithErrorHandling implements PostResponseCreator {
@Override
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java?rev=1789274&r1=1789273&r2=1789274&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java Wed Mar 29 05:49:17 2017
@@ -32,22 +32,11 @@ import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
-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.Modified;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.felix.scr.annotations.References;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceNotFoundException;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
-import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.jcr.contentloader.ContentImporter;
import org.apache.sling.servlets.post.HtmlResponse;
import org.apache.sling.servlets.post.JSONResponse;
@@ -75,73 +64,105 @@ import org.apache.sling.servlets.post.im
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Modified;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* POST servlet that implements the sling client library "protocol"
*/
-@Component(immediate = true, specVersion = "1.1", metatype = true, label = "%servlet.post.name", description = "%servlet.post.description")
-@Service(value = Servlet.class)
-@org.apache.felix.scr.annotations.Properties({
- @Property(name = "service.description", value = "Sling Post Servlet"),
- @Property(name = "service.vendor", value = "The Apache Software Foundation"),
- @Property(name = "sling.servlet.prefix", intValue = -1, propertyPrivate = true),
- @Property(name = "sling.servlet.paths", value = "sling/servlet/default/POST", propertyPrivate = true) })
-@References({
- @Reference(name = "postProcessor", referenceInterface = SlingPostProcessor.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
- @Reference(name = "postOperation", referenceInterface = PostOperation.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
- @Reference(name = "nodeNameGenerator", referenceInterface = NodeNameGenerator.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
- @Reference(name = "postResponseCreator", referenceInterface = PostResponseCreator.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
- @Reference(name = "contentImporter", referenceInterface = ContentImporter.class, cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC) })
+@Component(service = Servlet.class,
+ property = {
+ "service.description=Sling Post Servlet",
+ "service.vendor=The Apache Software Foundation",
+ "sling.servlet.prefix:Integer=-1",
+ "sling.servlet.paths=sling/servlet/default/POST"
+ })
+@Designate(ocd = SlingPostServlet.Config.class)
public class SlingPostServlet extends SlingAllMethodsServlet {
private static final long serialVersionUID = 1837674988291697074L;
+ @ObjectClassDefinition(name = "Apache Sling POST Servlet",
+ description="The Sling POST Servlet is registered as the default " +
+ "servlet to handle POST requests in Sling.")
+ public @interface Config {
+
+ @AttributeDefinition(name = "Date Format",
+ description = "List SimpleDateFormat strings for date "+
+ "formats supported for parsing from request input to data fields. The special "+
+ "format \"ISO8601\" (without the quotes) can be used to designate strict ISO-8601 "+
+ "parser which is able to parse strings generated by the Property.getString() "+
+ "method for Date properties. The default "+
+ "value is [ \"EEE MMM dd yyyy HH:mm:ss 'GMT'Z\", \"ISO8601\", "+
+ "\"yyyy-MM-dd'T'HH:mm:ss.SSSZ\", "+
+ "\"yyyy-MM-dd'T'HH:mm:ss\", \"yyyy-MM-dd\", \"dd.MM.yyyy HH:mm:ss\", \"dd.MM.yyyy\" ].")
+ String[] servlet_post_dateFormats() default { "EEE MMM dd yyyy HH:mm:ss 'GMT'Z", "ISO8601",
+ "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd",
+ "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy" };
+
+ @AttributeDefinition(name = "Node Name Hint Properties",
+ description = "The list of properties whose values "+
+ "may be used to derive a name for newly created nodes. When handling a request "+
+ "to create a new node, the name of the node is automatically generated if the "+
+ "request URL ends with a star (\"*\") or a slash (\"/\"). In this case the request "+
+ "parameters listed in this configuration value may be used to create the name. "+
+ "Default value is [ \"title\", \"jcr:title\", \"name\", \"description\", "+
+ "\"jcr:description\", \"abstract\", \"text\", \"jcr:text\" ].")
+ String[] servlet_post_nodeNameHints() default { "title", "jcr:title", "name", "description",
+ "jcr:description", "abstract", "text", "jcr:text" };
+
+ @AttributeDefinition(name = "Maximum Node Name Length",
+ description = "Maximum number of characters to "+
+ "use for automatically generated node names. The default value is 20. Note, "+
+ "that actual node names may be generated with at most 4 more characters if the "+
+ "numeric suffixes must be appended to make the name unique.")
+ int servlet_post_nodeNameMaxLength() default 20;
+
+ @AttributeDefinition(name = "Checkin New Versionable Nodes",
+ description = "If true, newly created "+
+ "versionable nodes or non-versionable nodes which are made versionable by the "+
+ "addition of the mix:versionable mixin are checked in. By default, false.")
+ boolean servlet_post_checkinNewVersionableNodes() default false;
+
+ @AttributeDefinition(name = "Auto Checkout Nodes",
+ description = "If true, checked in nodes are "+
+ "checked out when necessary. By default, false.")
+ boolean servlet_post_autoCheckout() default false;
+
+ @AttributeDefinition(name = "Auto Checkin Nodes",
+ description = "If true, nodes which are checked out "+
+ "by the post servlet are checked in. By default, true.")
+ boolean servlet_post_autoCheckin() default true;
+
+ @AttributeDefinition(name = "Ignored Parameters",
+ description = "Configures a regular expression "+
+ "pattern to select request parameters which should be ignored when writing "+
+ "content to the repository. By default this is \"j_.*\" thus ignoring all "+
+ "request parameters starting with j_ such as j_username.")
+ String servlet_post_ignorePattern() default "j_.*";
+ }
+
/**
* default log
*/
private final Logger log = LoggerFactory.getLogger(getClass());
- @Property({ "EEE MMM dd yyyy HH:mm:ss 'GMT'Z", "ISO8601",
- "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd",
- "dd.MM.yyyy HH:mm:ss", "dd.MM.yyyy" })
- private static final String PROP_DATE_FORMAT = "servlet.post.dateFormats";
-
- @Property({ "title", "jcr:title", "name", "description",
- "jcr:description", "abstract", "text", "jcr:text" })
- private static final String PROP_NODE_NAME_HINT_PROPERTIES = "servlet.post.nodeNameHints";
-
- @Property(intValue = 20)
- private static final String PROP_NODE_NAME_MAX_LENGTH = "servlet.post.nodeNameMaxLength";
-
- private static final boolean DEFAULT_CHECKIN_ON_CREATE = false;
-
- @Property(boolValue = DEFAULT_CHECKIN_ON_CREATE)
- private static final String PROP_CHECKIN_ON_CREATE = "servlet.post.checkinNewVersionableNodes";
-
- private static final boolean DEFAULT_AUTO_CHECKOUT = false;
-
- @Property(boolValue = DEFAULT_AUTO_CHECKOUT)
- private static final String PROP_AUTO_CHECKOUT = "servlet.post.autoCheckout";
-
- private static final boolean DEFAULT_AUTO_CHECKIN = true;
-
- @Property(boolValue = DEFAULT_AUTO_CHECKIN)
- private static final String PROP_AUTO_CHECKIN = "servlet.post.autoCheckin";
-
-
private static final String PARAM_CHECKIN_ON_CREATE = ":checkinNewVersionableNodes";
private static final String PARAM_AUTO_CHECKOUT = ":autoCheckout";
private static final String PARAM_AUTO_CHECKIN = ":autoCheckin";
- private static final String DEFAULT_IGNORED_PARAMETER_NAME_PATTERN = "j_.*";
-
- @Property(value = DEFAULT_IGNORED_PARAMETER_NAME_PATTERN)
- private static final String PROP_IGNORED_PARAMETER_NAME_PATTERN = "servlet.post.ignorePattern";
-
private final ModifyOperation modifyOperation = new ModifyOperation();
private final StreamedUploadOperation streamedUploadOperation = new StreamedUploadOperation();
@@ -149,22 +170,22 @@ public class SlingPostServlet extends Sl
private ServiceRegistration[] internalOperations;
/** Map of post operations. */
- private final Map<String, PostOperation> postOperations = new HashMap<String, PostOperation>();
+ private final Map<String, PostOperation> postOperations = new HashMap<>();
/** Sorted list of post processor holders. */
- private final List<PostProcessorHolder> postProcessors = new ArrayList<PostProcessorHolder>();
+ private final List<PostProcessorHolder> postProcessors = new ArrayList<>();
/** Cached list of post processors, used during request processing. */
private SlingPostProcessor[] cachedPostProcessors = new SlingPostProcessor[0];
/** Sorted list of node name generator holders. */
- private final List<NodeNameGeneratorHolder> nodeNameGenerators = new ArrayList<NodeNameGeneratorHolder>();
+ private final List<NodeNameGeneratorHolder> nodeNameGenerators = new ArrayList<>();
/** Cached list of node name generators used during request processing. */
private NodeNameGenerator[] cachedNodeNameGenerators = new NodeNameGenerator[0];
/** Sorted list of post response creator holders. */
- private final List<PostResponseCreatorHolder> postResponseCreators = new ArrayList<PostResponseCreatorHolder>();
+ private final List<PostResponseCreatorHolder> postResponseCreators = new ArrayList<>();
/** Cached array of post response creators used during request processing. */
private PostResponseCreator[] cachedPostResponseCreators = new PostResponseCreator[0];
@@ -398,12 +419,12 @@ public class SlingPostServlet extends Sl
@Activate
protected void activate(final BundleContext bundleContext,
- final Map<String, Object> configuration) {
+ final Config configuration) {
// configure now
this.configure(configuration);
// other predefined operations
- final ArrayList<ServiceRegistration> providedServices = new ArrayList<ServiceRegistration>();
+ final ArrayList<ServiceRegistration> providedServices = new ArrayList<>();
providedServices.add(registerOperation(bundleContext,
SlingPostConstants.OPERATION_MODIFY, modifyOperation));
providedServices.add(registerOperation(bundleContext,
@@ -428,7 +449,7 @@ public class SlingPostServlet extends Sl
private ServiceRegistration registerOperation(final BundleContext context,
final String opCode, final PostOperation operation) {
- final Hashtable<String, Object> properties = new Hashtable<String, Object>();
+ final Hashtable<String, Object> properties = new Hashtable<>();
properties.put(PostOperation.PROP_OPERATION_NAME, opCode);
properties.put(Constants.SERVICE_DESCRIPTION,
"Apache Sling POST Servlet Operation " + opCode);
@@ -445,11 +466,11 @@ public class SlingPostServlet extends Sl
}
@Modified
- private void configure(final Map<String, Object> configuration) {
+ private void configure(final Config configuration) {
this.baseVersioningConfiguration = createBaseVersioningConfiguration(configuration);
final DateParser dateParser = new DateParser();
- final String[] dateFormats = OsgiUtil.toStringArray(configuration.get(PROP_DATE_FORMAT));
+ final String[] dateFormats = configuration.servlet_post_dateFormats();
for (String dateFormat : dateFormats) {
try {
dateParser.register(dateFormat);
@@ -460,15 +481,12 @@ public class SlingPostServlet extends Sl
}
}
- final String[] nameHints = OsgiUtil.toStringArray(configuration.get(PROP_NODE_NAME_HINT_PROPERTIES));
- final int nameMax = (int) OsgiUtil.toLong(
- configuration.get(PROP_NODE_NAME_MAX_LENGTH), -1);
+ final String[] nameHints = configuration.servlet_post_nodeNameHints();
+ final int nameMax = configuration.servlet_post_nodeNameMaxLength();
final NodeNameGenerator nodeNameGenerator = new DefaultNodeNameGenerator(
nameHints, nameMax);
- final String paramMatch = OsgiUtil.toString(
- configuration.get(PROP_IGNORED_PARAMETER_NAME_PATTERN),
- DEFAULT_IGNORED_PARAMETER_NAME_PATTERN);
+ final String paramMatch = configuration.servlet_post_ignorePattern();
final Pattern paramMatchPattern = Pattern.compile(paramMatch);
this.modifyOperation.setDateParser(dateParser);
@@ -501,6 +519,9 @@ public class SlingPostServlet extends Sl
/**
* Bind a new post operation
*/
+ @Reference(service = PostOperation.class,
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
protected void bindPostOperation(final PostOperation operation, final Map<String, Object> properties) {
final String operationName = (String) properties.get(SlingPostOperation.PROP_OPERATION_NAME);
if ( operationName != null && operation != null ) {
@@ -522,13 +543,21 @@ public class SlingPostServlet extends Sl
}
}
+ private int getRanking(final Map<String, Object> properties) {
+ final Object val = properties.get(Constants.SERVICE_RANKING);
+ return val instanceof Integer ? (Integer)val : 0;
+ }
+
/**
* Bind a new post processor
*/
+ @Reference(service = SlingPostProcessor.class,
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
protected void bindPostProcessor(final SlingPostProcessor processor, final Map<String, Object> properties) {
final PostProcessorHolder pph = new PostProcessorHolder();
pph.processor = processor;
- pph.ranking = OsgiUtil.toInteger(properties.get(Constants.SERVICE_RANKING), 0);
+ pph.ranking = getRanking(properties);
synchronized ( this.postProcessors ) {
int index = 0;
@@ -578,10 +607,13 @@ public class SlingPostServlet extends Sl
/**
* Bind a new node name generator
*/
+ @Reference(service = NodeNameGenerator.class,
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
protected void bindNodeNameGenerator(final NodeNameGenerator generator, final Map<String, Object> properties) {
final NodeNameGeneratorHolder nngh = new NodeNameGeneratorHolder();
nngh.generator = generator;
- nngh.ranking = OsgiUtil.toInteger(properties.get(Constants.SERVICE_RANKING), 0);
+ nngh.ranking = getRanking(properties);
synchronized ( this.nodeNameGenerators ) {
int index = 0;
@@ -633,10 +665,13 @@ public class SlingPostServlet extends Sl
/**
* Bind a new post response creator
*/
+ @Reference(service = PostResponseCreator.class,
+ cardinality = ReferenceCardinality.MULTIPLE,
+ policy = ReferencePolicy.DYNAMIC)
protected void bindPostResponseCreator(final PostResponseCreator creator, final Map<String, Object> properties) {
final PostResponseCreatorHolder nngh = new PostResponseCreatorHolder();
nngh.creator = creator;
- nngh.ranking = OsgiUtil.toInteger(properties.get(Constants.SERVICE_RANKING), 0);
+ nngh.ranking = getRanking(properties);
synchronized ( this.postResponseCreators ) {
int index = 0;
@@ -683,6 +718,7 @@ public class SlingPostServlet extends Sl
this.cachedPostResponseCreators = localCache;
}
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
protected void bindContentImporter(final ContentImporter importer) {
this.contentImporter = importer;
importOperation.setContentImporter(importer);
@@ -695,14 +731,11 @@ public class SlingPostServlet extends Sl
}
}
- private VersioningConfiguration createBaseVersioningConfiguration(Map<?, ?> props) {
+ private VersioningConfiguration createBaseVersioningConfiguration(Config config) {
VersioningConfiguration cfg = new VersioningConfiguration();
- cfg.setCheckinOnNewVersionableNode(OsgiUtil.toBoolean(
- props.get(PROP_CHECKIN_ON_CREATE), DEFAULT_CHECKIN_ON_CREATE));
- cfg.setAutoCheckout(OsgiUtil.toBoolean(
- props.get(PROP_AUTO_CHECKOUT), DEFAULT_AUTO_CHECKOUT));
- cfg.setAutoCheckin(OsgiUtil.toBoolean(
- props.get(PROP_AUTO_CHECKIN), DEFAULT_AUTO_CHECKIN));
+ cfg.setCheckinOnNewVersionableNode(config.servlet_post_checkinNewVersionableNodes());
+ cfg.setAutoCheckout(config.servlet_post_autoCheckout());
+ cfg.setAutoCheckin(config.servlet_post_autoCheckin());
return cfg;
}
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java?rev=1789274&r1=1789273&r2=1789274&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/ChunkCleanUpTask.java Wed Mar 29 05:49:17 2017
@@ -16,8 +16,6 @@
*/
package org.apache.sling.servlets.post.impl.helper;
-import java.util.Map;
-
import javax.jcr.InvalidItemStateException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -27,15 +25,14 @@ import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-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.OsgiUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.servlets.post.SlingPostConstants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,27 +56,38 @@ import org.slf4j.LoggerFactory;
* default workspace assuming users are stored in that workspace and the
* administrative user has full access.
*/
-@Component(metatype = true, label = "Apache Sling Post Chunk Upload : Cleanup Task", description = "Task to regularly purge incomplete chunks from the repository")
-@Service(value = Runnable.class)
-@Properties({
- @Property(name = "scheduler.expression", value = "31 41 0/12 * * ?", label = "Schedule", description = "Cron expression scheudling this job. Default is hourly 17m23s after the hour. "
- + "See http://www.docjar.com/docs/api/org/quartz/CronTrigger.html for a description "
- + "of the format for this value."),
- @Property(name = "service.description", value = "Periodic Chunk Cleanup Job", propertyPrivate = true),
- @Property(name = "service.vendor", value = "The Apache Software Foundation", propertyPrivate = true),
- @Property(name = "scheduler.concurrent", label = "scheduler.concurrent", boolValue = false,
- description = "Allow Chunk Cleanup Task to run concurrently (default: false).")})
+@Component(service = Runnable.class,
+ property = {
+ "service.description=Periodic Chunk Cleanup Job",
+ "service.vendor=The Apache Software Foundation"
+ })
+@Designate(ocd = ChunkCleanUpTask.Config.class)
public class ChunkCleanUpTask implements Runnable {
+ @ObjectClassDefinition(name = "Apache Sling Post Chunk Upload : Cleanup Task",
+ description = "Task to regularly purge incomplete chunks from the repository")
+ public @interface Config {
+
+ @AttributeDefinition(name = "Schedule", description = "Cron expression scheudling this job. Default is hourly 17m23s after the hour. "
+ + "See http://www.docjar.com/docs/api/org/quartz/CronTrigger.html for a description "
+ + "of the format for this value.")
+ String scheduler_expression() default "31 41 0/12 * * ?";
+
+ @AttributeDefinition(name = "scheduler.concurrent",
+ description = "Allow Chunk Cleanup Task to run concurrently (default: false).")
+ boolean scheduler_concurrent() default false;
+
+ @AttributeDefinition(name = "Cleanup Age",
+ description = "The chunk's age in minutes before it is considered for clean up.")
+ int chunk_cleanup_age() default 360;
+ }
+
/** default log */
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference
private SlingRepository repository;
- @Property(intValue = 360, label = "chunk.cleanup.age", description = "The chunk's age in minutes before it is considered for clean up.")
- private static final String CHUNK_CLEANUP_AGE = "chunk.cleanup.age";
-
private SlingFileUploadHandler uploadhandler = new SlingFileUploadHandler();
/**
@@ -175,11 +183,10 @@ public class ChunkCleanUpTask implements
}
@Activate
- protected void activate(final Map<String, Object> configuration) {
- chunkCleanUpAge = OsgiUtil.toInteger(
- configuration.get(CHUNK_CLEANUP_AGE), 1) * 60 * 1000;
+ protected void activate(final Config configuration) {
+ chunkCleanUpAge = configuration.chunk_cleanup_age();
log.info("scheduler config [{}], chunkGarbageTime [{}] ms",
- OsgiUtil.toString(configuration.get("scheduler.expression"), ""),
+ configuration.scheduler_expression(),
chunkCleanUpAge);
}