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/04/27 13:27:54 UTC
svn commit: r1792883 - in
/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl:
PostResponseWithErrorHandling.java SlingPostServlet.java
helper/JCRSupport.java operations/ImportOperation.java
Author: cziegeler
Date: Thu Apr 27 13:27:53 2017
New Revision: 1792883
URL: http://svn.apache.org/viewvc?rev=1792883&view=rev
Log:
SLING-6723 : Make dependency to javax.jcr, jcr.contentloader and jcr.api optional
Modified:
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/JCRSupport.java
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java
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=1792883&r1=1792882&r2=1792883&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 Thu Apr 27 13:27:53 2017
@@ -29,7 +29,10 @@ import org.apache.sling.servlets.post.Po
import org.apache.sling.servlets.post.SlingPostConstants;
import org.osgi.service.component.annotations.Component;
-@Component(service = PostResponseCreator.class)
+@Component(service = PostResponseCreator.class,
+ property = {
+ "service.vendor=The Apache Software Foundation"
+ })
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=1792883&r1=1792882&r2=1792883&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 Thu Apr 27 13:27:53 2017
@@ -49,6 +49,7 @@ import org.apache.sling.servlets.post.Sl
import org.apache.sling.servlets.post.VersioningConfiguration;
import org.apache.sling.servlets.post.impl.helper.DateParser;
import org.apache.sling.servlets.post.impl.helper.DefaultNodeNameGenerator;
+import org.apache.sling.servlets.post.impl.helper.JCRSupport;
import org.apache.sling.servlets.post.impl.helper.MediaRangeList;
import org.apache.sling.servlets.post.impl.operations.CheckinOperation;
import org.apache.sling.servlets.post.impl.operations.CheckoutOperation;
@@ -70,6 +71,7 @@ import org.osgi.service.component.annota
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.component.annotations.ReferencePolicyOption;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@@ -191,11 +193,6 @@ public class SlingPostServlet extends Sl
private final ImportOperation importOperation = new ImportOperation();
- /**
- * The content importer reference.
- */
- private ContentImporter contentImporter;
-
private VersioningConfiguration baseVersioningConfiguration;
@Override
@@ -434,19 +431,17 @@ public class SlingPostServlet extends Sl
SlingPostConstants.OPERATION_DELETE, new DeleteOperation()));
providedServices.add(registerOperation(bundleContext,
SlingPostConstants.OPERATION_NOP, new NopOperation()));
- providedServices.add(registerOperation(bundleContext,
- SlingPostConstants.OPERATION_IMPORT, importOperation));
// the following operations require JCR:
- try {
+ if ( JCRSupport.INSTANCE.jcrEnabled()) {
+ providedServices.add(registerOperation(bundleContext,
+ SlingPostConstants.OPERATION_IMPORT, importOperation));
providedServices.add(registerOperation(bundleContext,
SlingPostConstants.OPERATION_CHECKIN, new CheckinOperation()));
providedServices.add(registerOperation(bundleContext,
SlingPostConstants.OPERATION_CHECKOUT, new CheckoutOperation()));
providedServices.add(registerOperation(bundleContext,
SlingPostConstants.OPERATION_RESTORE, new RestoreOperation()));
- } catch ( final Throwable t) {
- // ignore as JCR is optional
}
internalOperations = providedServices.toArray(new ServiceRegistration[providedServices.size()]);
}
@@ -722,17 +717,16 @@ public class SlingPostServlet extends Sl
this.cachedPostResponseCreators = localCache;
}
- @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC)
- protected void bindContentImporter(final ContentImporter importer) {
- this.contentImporter = importer;
+ @Reference(service = ContentImporter.class,
+ cardinality = ReferenceCardinality.OPTIONAL,
+ policy = ReferencePolicy.DYNAMIC,
+ policyOption = ReferencePolicyOption.GREEDY)
+ protected void bindContentImporter(final Object importer) {
importOperation.setContentImporter(importer);
}
- protected void unbindContentImporter(final ContentImporter importer) {
- if ( this.contentImporter == importer ) {
- this.contentImporter = null;
- importOperation.setContentImporter(null);
- }
+ protected void unbindContentImporter(final Object importer) {
+ importOperation.unsetContentImporter(importer);
}
private VersioningConfiguration createBaseVersioningConfiguration(Config config) {
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java?rev=1792883&r1=1792882&r2=1792883&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java Thu Apr 27 13:27:53 2017
@@ -43,7 +43,7 @@ public class JCRSupport {
try {
impl = new JCRSupportImpl();
} catch ( final Throwable t) {
- logger.warn("Support for JCR operations like checkin, checkout, ordering etc. is currently disabled " +
+ logger.warn("Support for JCR operations like checkin, checkout, import, ordering etc. is currently disabled " +
"in the servlets post module. Check whether the JCR API is available.");
}
this.supportImpl = impl;
@@ -215,4 +215,8 @@ public class JCRSupport {
// the caller already got an item and a node, so supportImpl is available
((JCRSupportImpl)supportImpl).move(src, dstParent, name);
}
+
+ public boolean jcrEnabled() {
+ return this.supportImpl != null;
+ }
}
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java?rev=1792883&r1=1792882&r2=1792883&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ImportOperation.java Thu Apr 27 13:27:53 2017
@@ -49,12 +49,18 @@ public class ImportOperation extends Abs
/**
* Reference to the content importer service
*/
- private ContentImporter contentImporter;
+ private Object contentImporter;
- public void setContentImporter(ContentImporter importer) {
+ public void setContentImporter(Object importer) {
this.contentImporter = importer;
}
+ public void unsetContentImporter(Object importer) {
+ if ( this.contentImporter == importer ) {
+ this.contentImporter = null;
+ }
+ }
+
private String getRequestParamAsString(SlingHttpServletRequest request, String key) {
RequestParameter requestParameter = request.getRequestParameter(key);
if (requestParameter == null) {
@@ -67,7 +73,7 @@ public class ImportOperation extends Abs
protected void doRun(SlingHttpServletRequest request, PostResponse response, final List<Modification> changes)
throws PersistenceException {
try {
- ContentImporter importer = contentImporter;
+ Object importer = contentImporter;
if (importer == null) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Missing content importer for import");
@@ -166,7 +172,7 @@ public class ImportOperation extends Abs
"Missing content for import");
return;
} else {
- importer.importContent(node, contentRootName, contentStream,
+ ((ContentImporter)importer).importContent(node, contentRootName, contentStream,
new ImportOptions() {
@Override