RE: Need help in implementing Sling Context Aware Configuration

2016-11-17 Thread Stefan Seifert
you do not need org.apache.sling.caconfig.bnd-plugin as direct reference in 
your - it's only useful as dependency for maven-bundle-plugin or other tooling 
that used bnd to generate the OSGi SCR metadata, see [1] as an example.

but this should not be the source of your problem - did you deploy the bundles 
org.apache.sling.caconfig.impl, org.apache.sling.caconfig.api, 
org.apache.sling.caconfig.spi to your application instance, and are they 
running (check OSGi console)?

if yes, can you give us the full stack trace?

stefan


[1] 
http://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html#context-aware-configuration-bnd-plugin


>-Original Message-
>From: Gopal Agarwal [mailto:gagar...@adobe.com]
>Sent: Thursday, November 17, 2016 4:00 PM
>To: users@sling.apache.org
>Subject: Need help in implementing Sling Context Aware Configuration
>
>Hi,
>
>I am looking to use Sling Context Aware Configuration.
>https://sling.apache.org/documentation/bundles/context-aware-
>configuration/context-aware-configuration.html
>
>I have added these in the POM file
>
>org.apache.sling
>org.apache.sling.caconfig.impl
>1.0.0
>
>
>org.apache.sling
>org.apache.sling.caconfig.api
>1.0.0
>
>
>org.apache.sling
>org.apache.sling.caconfig.spi
>1.0.0
>
>
>org.apache.sling
>org.apache.sling.caconfig.bnd-
>plugin
>1.0.0
>
>
>
>Java code
>ResourceResolver resourceResolver = request.getResourceResolver();
>Resource contentResource = (Resource)
>resourceResolver.getResource("/content/ubi/test");
>ValueMap props =
>contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();
>String param1 = props.get("param1", String.class);
>
>Issue:
>ConfigurationBuilder Class is not getting resolved.
>
>Am I missing something?  Any help is appreciated..
>
>
>Regards,
>Gopal
>




RE: Need help in implementing Sling Context Aware Configuration

2016-11-18 Thread Gopal Agarwal
Hi All,

I managed to resolve the dependency issue by embedding these jars.
Now I am getting issue @ line 3

ResourceResolver resourceResolver = request.getResourceResolver();
Resource contentResource = (Resource) 
resourceResolver.getResource("/content/ubi/test");
ValueMap props = 
contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();

com.adobe.beagle.servlet.ContextAwareConfigReader [Exception]
java.lang.NullPointerException: null

Any help is appreciated.

Regards,
Gopal




From: Gopal Agarwal
Sent: Thursday, November 17, 2016 8:30 PM
To: 'users@sling.apache.org' 
Subject: Need help in implementing Sling Context Aware Configuration

Hi,

I am looking to use Sling Context Aware Configuration.
https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html

I have added these in the POM file

org.apache.sling
org.apache.sling.caconfig.impl
1.0.0


org.apache.sling
org.apache.sling.caconfig.api
1.0.0


org.apache.sling
org.apache.sling.caconfig.spi
1.0.0


org.apache.sling
org.apache.sling.caconfig.bnd-plugin
1.0.0



Java code
ResourceResolver resourceResolver = request.getResourceResolver();
Resource contentResource = (Resource) 
resourceResolver.getResource("/content/ubi/test");
ValueMap props = 
contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();
String param1 = props.get("param1", String.class);

Issue:
ConfigurationBuilder Class is not getting resolved.

Am I missing something?  Any help is appreciated..


Regards,
Gopal




Re: Need help in implementing Sling Context Aware Configuration

2016-11-18 Thread Justin Edelson
Embedding the JARs is surely not the right solution. These need to be
deployed as OSGi bundles (as Stefan wrote).

Regards,
Justin

On Sat, Nov 19, 2016 at 4:56 AM Gopal Agarwal  wrote:

> Hi All,
>
> I managed to resolve the dependency issue by embedding these jars.
> Now I am getting issue @ line 3
>
> ResourceResolver resourceResolver = request.getResourceResolver();
> Resource contentResource = (Resource)
> resourceResolver.getResource("/content/ubi/test");
> ValueMap props =
> contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();
>
> com.adobe.beagle.servlet.ContextAwareConfigReader [Exception]
> java.lang.NullPointerException: null
>
> Any help is appreciated.
>
> Regards,
> Gopal
>
>
>
>
> From: Gopal Agarwal
> Sent: Thursday, November 17, 2016 8:30 PM
> To: 'users@sling.apache.org' 
> Subject: Need help in implementing Sling Context Aware Configuration
>
> Hi,
>
> I am looking to use Sling Context Aware Configuration.
>
> https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html
>
> I have added these in the POM file
> 
> org.apache.sling
> org.apache.sling.caconfig.impl
> 1.0.0
> 
> 
> org.apache.sling
> org.apache.sling.caconfig.api
> 1.0.0
> 
> 
> org.apache.sling
> org.apache.sling.caconfig.spi
> 1.0.0
> 
> 
> org.apache.sling
> org.apache.sling.caconfig.bnd-plugin
> 1.0.0
> 
>
>
> Java code
> ResourceResolver resourceResolver = request.getResourceResolver();
> Resource contentResource = (Resource)
> resourceResolver.getResource("/content/ubi/test");
> ValueMap props =
> contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();
> String param1 = props.get("param1", String.class);
>
> Issue:
> ConfigurationBuilder Class is not getting resolved.
>
> Am I missing something?  Any help is appreciated..
>
>
> Regards,
> Gopal
>
>
>


Re: Need help in implementing Sling Context Aware Configuration

2016-11-20 Thread Bertrand Delacretaz
On Fri, Nov 18, 2016 at 8:36 AM, Gopal Agarwal  wrote:
...
> ResourceResolver resourceResolver = request.getResourceResolver();
> Resource contentResource = (Resource) 
> resourceResolver.getResource("/content/ubi/test");
> ValueMap props = 
> contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();...

You should check whether contentResource is null before using it: as
per [1] getResource(..) returns null if the resource is not present or
cannot be read.

-Bertrand

[1] 
https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html


Re: Need help in implementing Sling Context Aware Configuration

2016-11-21 Thread Nicolas Peltier
Hi Guys,

thanks for your help, it was indeed a deployment issue. 

now we’d need to know how to properly implement a “complex” but rather current 
case with country and language subnodes. 

Am i right to assume if we want to use default context path strategy we should 
add a sling:configRef property to each locale of the content (e.g. 
/content/mysite/country/language@sling:configRef), and then manage in the 
configuration the fallback mechanism?

Nicolas




> On Nov 21, 2016, at 7:23 AM, Bertrand Delacretaz  
> wrote:
> 
> On Fri, Nov 18, 2016 at 8:36 AM, Gopal Agarwal  wrote:
> ...
>> ResourceResolver resourceResolver = request.getResourceResolver();
>> Resource contentResource = (Resource) 
>> resourceResolver.getResource("/content/ubi/test");
>> ValueMap props = 
>> contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();...
> 
> You should check whether contentResource is null before using it: as
> per [1] getResource(..) returns null if the resource is not present or
> cannot be read.
> 
> -Bertrand
> 
> [1] 
> https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceResolver.html



RE: Need help in implementing Sling Context Aware Configuration

2016-11-21 Thread Stefan Seifert
please have also a look on the documentation [1] [2]

it should work the way you describe having a sling:configRef property on 
country node and on each language node.

stefan

[1] 
http://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html
[2] 
http://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration-default-implementation.html



>-Original Message-
>From: Nicolas Peltier [mailto:npelt...@adobe.com]
>Sent: Monday, November 21, 2016 1:54 PM
>To: users@sling.apache.org
>Cc: Gopal Agarwal
>Subject: Re: Need help in implementing Sling Context Aware Configuration
>
>Hi Guys,
>
>thanks for your help, it was indeed a deployment issue.
>
>now we’d need to know how to properly implement a “complex” but rather
>current case with country and language subnodes.
>
>Am i right to assume if we want to use default context path strategy we
>should add a sling:configRef property to each locale of the content (e.g.
>/content/mysite/country/language@sling:configRef), and then manage in the
>configuration the fallback mechanism?
>
>Nicolas
>
>
>
>
>> On Nov 21, 2016, at 7:23 AM, Bertrand Delacretaz 
>wrote:
>>
>> On Fri, Nov 18, 2016 at 8:36 AM, Gopal Agarwal 
>wrote:
>> ...
>>> ResourceResolver resourceResolver = request.getResourceResolver();
>>> Resource contentResource = (Resource)
>resourceResolver.getResource("/content/ubi/test");
>>> ValueMap props =
>contentResource.adaptTo(ConfigurationBuilder.class).asValueMap();...
>>
>> You should check whether contentResource is null before using it: as
>> per [1] getResource(..) returns null if the resource is not present or
>> cannot be read.
>>
>> -Bertrand
>>
>> [1]
>https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/Resou
>rceResolver.html