Skip to main content
Level 3
Jul 25, 2024 12:00 AM UTC
Solved

ResourceFilterStream is always null after adapting from a resource

I followed this article to try to use Resource Filter Stream, project builds and deploys fine, however rfs is always null, any ideas?  Am I missing something?  Thanks in advance.

 

ResourceFilterStream rfs = resource.adaptTo(ResourceFilterStream.class);
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
EstebanBustamante
EstebanBustamanteAccepted solution
Adobe Champion and Community Advisor
Jul 25, 2024 1:46 PM UTC

Hi

 

This is an external bundle, so you need to wrap it into your bundle to deploy it along with your code. Please check this thread: 

https://blogs.perficient.com/2018/10/09/resource-streams-in-apache-sling/ 

 

Hope this helps

Esteban Bustamante

7 replies

AMANATH_ULLAH
Community Advisor
Community Advisor
Jul 25, 2024 2:59 AM UTC

@nelsonatensemble 

Can you verify if you have below dependency included in POM.xml and included the right imports for ResourceFilterStream

<dependency>
    <groupid>org.apache.sling</groupid>
    <artifactid>org.apache.sling.resource.filter</artifactid>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>

 

Translate
Amanath Ullah
Level 3
Jul 26, 2024 3:41 AM UTC

Yes that was done, however, I did not embed the jar per h_kataria's comment below, so that's probably the issue.  I had assumed that the jar is available OOTB.

 

<embedded> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.resource.filter</artifactId> <target>/apps/<your-project>/application/install</target> </embedded>
Translate
h_kataria
Community Advisor
Community Advisor
Jul 25, 2024 7:10 AM UTC

As far as I know, resourcefilterstream is not available OOB, so you will have to embed it in your all pom.xml in filevault-package-maven-plugin config section

<embedded> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.resource.filter</artifactId> <target>/apps/<your-project>/application/install</target> </embedded>

 and add the dependency

<dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.resource.filter</artifactId> <version>1.0.0</version> <scope>provided</scope> </dependency>

 

Translate
Level 3
Jul 26, 2024 3:39 AM UTC

Ah maybe that's it, I added the dependency but i did not embed the bundle, I will give that a try.  Thanks all.

Translate
Level 2
Oct 24, 2024 8:20 AM UTC

add this in core bundle pom as well as embed it in all pom

<bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*
Export-Package: com.mysie.*
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin,org.apache.sling.bnd.models.ModelsScannerPlugin
-includeresource: org.apache.sling.resource.filter-1.0.0.jar;lib:=true

 

Translate
EstebanBustamante
Adobe Champion and Community Advisor
EstebanBustamanteAdobe Champion and Community AdvisorAccepted solution
Adobe Champion and Community Advisor
Jul 25, 2024 1:46 PM UTC

Hi

 

This is an external bundle, so you need to wrap it into your bundle to deploy it along with your code. Please check this thread: 

https://blogs.perficient.com/2018/10/09/resource-streams-in-apache-sling/ 

 

Hope this helps

Translate
Esteban Bustamante
Level 2
Oct 24, 2024 8:21 AM UTC

the solution is missing this step 

<bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0,*
Export-Package: com.mysite.*
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin,org.apache.sling.bnd.models.ModelsScannerPlugin
-includeresource: org.apache.sling.resource.filter-1.0.0.jar;lib:=true
Translate