sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SLING-7357) Send Content-Type header along with the DistributionPackage's content in forward distribution
Date Tue, 09 Jan 2018 08:44:00 GMT

    [ https://issues.apache.org/jira/browse/SLING-7357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16318047#comment-16318047
] 

ASF GitHub Bot commented on SLING-7357:
---------------------------------------

tteofili closed pull request #2: SLING-7357: set content type to forward distrib http headers
URL: https://github.com/apache/sling-org-apache-sling-distribution-core/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
b/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
index 66fbd3f..edf53b6 100644
--- a/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
+++ b/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
@@ -34,6 +34,7 @@
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.http.HttpHeaders;
 import org.apache.jackrabbit.vault.packaging.Packaging;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.commons.osgi.PropertiesUtil;
@@ -246,8 +247,10 @@ protected SimpleDistributionAgent createAgent(String agentName, BundleContext
co
         Map<String, String> priorityQueues = PropertiesUtil.toMap(config.get(PRIORITY_QUEUES),
new String[0]);
         priorityQueues = SettingsUtils.removeEmptyEntries(priorityQueues);
 
+        Map<String, String> headers = new HashMap<String, String>(1);
+        headers.put(HttpHeaders.CONTENT_TYPE, packageBuilder.getContentType());
         Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
-        HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
+        HttpConfiguration httpConfiguration = new HttpConfiguration(timeout, headers);
 
         DistributionPackageExporter packageExporter = new LocalDistributionPackageExporter(packageBuilder);
 
diff --git a/src/main/java/org/apache/sling/distribution/monitor/impl/MonitoringDistributionPackageBuilder.java
b/src/main/java/org/apache/sling/distribution/monitor/impl/MonitoringDistributionPackageBuilder.java
index 32066c9..d6e22c5 100644
--- a/src/main/java/org/apache/sling/distribution/monitor/impl/MonitoringDistributionPackageBuilder.java
+++ b/src/main/java/org/apache/sling/distribution/monitor/impl/MonitoringDistributionPackageBuilder.java
@@ -59,6 +59,11 @@ public String getType() {
         return wrapped.getType();
     }
 
+    @Override
+    public String getContentType() {
+        return wrapped.getContentType();
+    }
+
     @Nonnull
     @Override
     public DistributionPackage createPackage(@Nonnull ResourceResolver resourceResolver,
@Nonnull DistributionRequest request) throws DistributionException {
diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageBuilder.java
b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageBuilder.java
index 6713072..d6c65b4 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageBuilder.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageBuilder.java
@@ -39,6 +39,12 @@
      */
     String getType();
 
+    /**
+     * returns the content type of packages created and consumed by the package builder.
+     * @return the content type of the package
+     */
+    String getContentType();
+
     /**
      * creates a {@link DistributionPackage} for a specific {@link org.apache.sling.distribution.DistributionRequest}
      *
diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/AbstractDistributionPackageBuilder.java
b/src/main/java/org/apache/sling/distribution/packaging/impl/AbstractDistributionPackageBuilder.java
index 37e28ca..0a32868 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/AbstractDistributionPackageBuilder.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/AbstractDistributionPackageBuilder.java
@@ -50,15 +50,21 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     private final String type;
+    private final String contentType;
 
-    AbstractDistributionPackageBuilder(String type) {
+    AbstractDistributionPackageBuilder(String type, String contentType) {
         this.type = type;
+        this.contentType = contentType;
     }
 
     public String getType() {
         return type;
     }
 
+    public String getContentType() {
+        return this.contentType;
+    }
+
     @Nonnull
     public DistributionPackage createPackage(@Nonnull ResourceResolver resourceResolver,
@Nonnull DistributionRequest request)
             throws DistributionException {
diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
b/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
index da8c496..878c1ea 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilder.java
@@ -66,7 +66,7 @@ public FileDistributionPackageBuilder(String type,
                                           String tempFilesFolder,
                                           String digestAlgorithm, String[] nodeFilters,
                                           String[] propertyFilters) {
-        super(type);
+        super(type, distributionContentSerializer.getContentType());
         this.distributionContentSerializer = distributionContentSerializer;
         this.nodeFilters = VltUtils.parseFilters(nodeFilters);
         this.propertyFilters = VltUtils.parseFilters(propertyFilters);
diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/ResourceDistributionPackageBuilder.java
b/src/main/java/org/apache/sling/distribution/packaging/impl/ResourceDistributionPackageBuilder.java
index 70a5186..04a4cfb 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/ResourceDistributionPackageBuilder.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/ResourceDistributionPackageBuilder.java
@@ -77,7 +77,7 @@ public ResourceDistributionPackageBuilder(String type,
                                               boolean useOffHeapMemory,
                                               String digestAlgorithm, String[] nodeFilters,
                                               String[] propertyFilters) {
-        super(type);
+        super(type, distributionContentSerializer.getContentType());
         this.distributionContentSerializer = distributionContentSerializer;
         this.nodeFilters = VltUtils.parseFilters(nodeFilters);
         this.propertyFilters = VltUtils.parseFilters(propertyFilters);
diff --git a/src/main/java/org/apache/sling/distribution/serialization/DistributionContentSerializer.java
b/src/main/java/org/apache/sling/distribution/serialization/DistributionContentSerializer.java
index 60f1fa6..ab1735d 100644
--- a/src/main/java/org/apache/sling/distribution/serialization/DistributionContentSerializer.java
+++ b/src/main/java/org/apache/sling/distribution/serialization/DistributionContentSerializer.java
@@ -55,6 +55,12 @@ void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions
      */
     String getName();
 
+    /**
+     * retrieve the mime type of the exported content of this content serializer
+     * @implNote the default implementation returns application/octet-stream.
+     */
+    String getContentType();
+
     /**
      * whether or not this {@link DistributionContentSerializer} can build package filters
for including / excluding
      * certain resources / attributes directly from a {@link org.apache.sling.distribution.DistributionRequest}
diff --git a/src/main/java/org/apache/sling/distribution/serialization/impl/DistributionPackageBuilderFactory.java
b/src/main/java/org/apache/sling/distribution/serialization/impl/DistributionPackageBuilderFactory.java
index 40bd3ab..00401e5 100644
--- a/src/main/java/org/apache/sling/distribution/serialization/impl/DistributionPackageBuilderFactory.java
+++ b/src/main/java/org/apache/sling/distribution/serialization/impl/DistributionPackageBuilderFactory.java
@@ -237,6 +237,10 @@ public String getType() {
         return packageBuilder.getType();
     }
 
+    public String getContentType() {
+        return contentSerializer.getContentType();
+    }
+
     @Nonnull
     public DistributionPackage createPackage(@Nonnull ResourceResolver resourceResolver,
@Nonnull DistributionRequest request) throws DistributionException {
         return packageBuilder.createPackage(resourceResolver, request);
diff --git a/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultContentSerializer.java
b/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultContentSerializer.java
index 5547185..9b09665 100644
--- a/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultContentSerializer.java
+++ b/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultContentSerializer.java
@@ -196,6 +196,11 @@ public String getName() {
         return name;
     }
 
+    @Override
+    public String getContentType() {
+        return "application/octet-stream";
+    }
+
     @Override
     public boolean isRequestFiltering() {
         return true;
diff --git a/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/VaultDistributionPackageBuilderFactory.java
b/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/VaultDistributionPackageBuilderFactory.java
index d44dcbe..409589c 100644
--- a/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/VaultDistributionPackageBuilderFactory.java
+++ b/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/VaultDistributionPackageBuilderFactory.java
@@ -288,6 +288,10 @@ public String getType() {
         return packageBuilder.getType();
     }
 
+    public String getContentType() {
+        return packageBuilder.getContentType();
+    }
+
     @Nonnull
     public DistributionPackage createPackage(@Nonnull ResourceResolver resourceResolver,
@Nonnull DistributionRequest request) throws DistributionException {
         return packageBuilder.createPackage(resourceResolver, request);
diff --git a/src/main/java/org/apache/sling/distribution/serialization/package-info.java b/src/main/java/org/apache/sling/distribution/serialization/package-info.java
index 8759b0e..2b90d5f 100644
--- a/src/main/java/org/apache/sling/distribution/serialization/package-info.java
+++ b/src/main/java/org/apache/sling/distribution/serialization/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("0.1.0")
+@Version("1.0.0")
 package org.apache.sling.distribution.serialization;
 
 import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/distribution/transport/impl/HttpConfiguration.java
b/src/main/java/org/apache/sling/distribution/transport/impl/HttpConfiguration.java
index 8f48d4a..a460053 100644
--- a/src/main/java/org/apache/sling/distribution/transport/impl/HttpConfiguration.java
+++ b/src/main/java/org/apache/sling/distribution/transport/impl/HttpConfiguration.java
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.distribution.transport.impl;
 
+import java.util.Collections;
+import java.util.Map;
+
 /**
  * HTTP related configuration for {@link SimpleHttpDistributionTransport}
  */
@@ -25,15 +28,24 @@
 
     private final Integer connectTimeout;
     private final Integer socketTimeout;
+    private final Map<String, String> headers;
 
     public HttpConfiguration(Integer timeout) {
-        this.socketTimeout = timeout;
-        this.connectTimeout = timeout;
+        this(timeout, timeout);
     }
 
     public HttpConfiguration(Integer connectTimeout, Integer socketTimeout) {
+        this(connectTimeout, socketTimeout, Collections.<String, String>emptyMap());
+    }
+
+    public HttpConfiguration(Integer timeout, Map<String, String> headers) {
+        this(timeout, timeout, headers);
+    }
+
+    public HttpConfiguration(Integer connectTimeout, Integer socketTimeout, Map<String,
String> headers) {
         this.connectTimeout = connectTimeout;
         this.socketTimeout = socketTimeout;
+        this.headers = headers;
     }
 
     public Integer getConnectTimeout() {
@@ -43,4 +55,8 @@ public Integer getConnectTimeout() {
     public Integer getSocketTimeout() {
         return socketTimeout;
     }
+
+    public Map<String, String> getHeaders() {
+        return headers;
+    }
 }
diff --git a/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
b/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
index 86e33e2..5d243cb 100644
--- a/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
+++ b/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
@@ -137,6 +137,10 @@ public void deliverPackage(@Nonnull ResourceResolver resourceResolver,
@Nonnull
                     }
                 }
 
+                for (Map.Entry<String, String> header : httpConfiguration.getHeaders().entrySet())
{
+                    req.addHeader(header.getKey(), header.getValue());
+                }
+
                 InputStream inputStream = null;
                 try {
                     inputStream = DistributionPackageUtils.createStreamWithHeader(distributionPackage);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Send Content-Type header along with the DistributionPackage's content in forward distribution
> ---------------------------------------------------------------------------------------------
>
>                 Key: SLING-7357
>                 URL: https://issues.apache.org/jira/browse/SLING-7357
>             Project: Sling
>          Issue Type: Improvement
>          Components: Content Distribution
>            Reporter: Dirk Rudolph
>            Priority: Minor
>
> Currently SimpleHttpDistributionTransport only adds Connection and Digest http header
(if configured to do so) to the http request. When integrating into other systems then sling
the API might require the content type of the package transmitted to be present. 
> I see to options to support that:
> a) implement configureable headers for the http transport similar to the timeouts. This
might clash with headers set by the implementation
> b) let the serializer specify the type of the content it generates. This will be an API
change in the core bundle.
> From my perspective b) will be simpler to implement.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message