Re: Getting started with Sling

2014-12-28 Thread Henry Saginor
Hi Sylvain,

I hope I understand what you are trying to do. But here is what I would suggest.
1) Think about how you are going to structure your blog content ahead of time. 
I would suggest something like /content/blog/year/month/post/comments. This way 
your archive script does not need to query the repository but will simply know 
how to construct a path to a specific year (and month).
2) You could use a Sling URL selector for the year (example: 
/content/archives.2014.html where /content/archives has sling:resourceType = 
“blog/year-archive”). Sling provides API for getting URL selectors from 
request. This way /etc/map stuff is not needed. But either way your script will 
still have to extract the year from request. I don’t see any way around this. 
The selector based approach is an alternative to your /etc/map bridge if you 
don’t like it. But, actually, selectors seem to be less intuitive for end users 
in this case. You could also use suffixes (i.e. /content/archives.html/2014).
3) I would not actually store content with any particular markup. Just use 
default JCR backed Resource implementation and think of a blog post in terms of 
JCR nodes/properties (or resources/properties if you prefer higher level of 
abstraction :)). You should have a resource type like /apps/blog/post with 
scripts for rendering different markups if you want. Alternatively you could 
have just html rendering script (html.esp ?) and use Sling rewriter pipeline 
(http://sling.apache.org/site/output-rewriting-pipelines-orgapacheslingrewriter.html)
 to generate other markups. A resource like /content/blog/year/month/post 
should have sling:resourceType = “blog/post”. You don’t need an observation 
listener that generates and stores different markups. It’s also quite a bit of 
extra content you don’t need to store if you render markup when it’s requested.
4) You also don’t need separate authoring and publish areas if you structure 
posts content as I suggested. All new posts should be created under 
/content/blog/currentYear/currentMonth/ anyway. This is both your blog’s 
authoring and publish/archive area. A basic implementation of an authoring 
script can be just an HTML form that does a POST to sling repository using 
default Sling Post Servlet - 
http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html.
 You have a lot of control over how you structure content via this mechanism.

I hope this helps.

Henry


On Dec 27, 2014, at 11:46 AM, Sylvain Wallez sylv...@apache.org wrote:

 Hi all,
 
 I'm discovering Sling these days (it's never too late!), and as a playground 
 I'm trying to implement a blog engine that goes further than the espblog 
 sample, with support for archive pages, comments and writing content in 
 different markup languages (html, markdown and asciidoc).
 
 I quite like the resource-centric approach, which makes it easy to quickly 
 create content and presentation scripts, but I didn't find an obvious 
 solution for archive pages which are synthetic content resulting from a query 
 in the content repository. I'd be grateful if you guys could provide some 
 best practices.
 
 Here's how I implemented it :
 
 - a mapping /etc/map/year-archive with properties:
  - sling:match = .*/archives/[0-9]+
  - sling:internalRedirect = /archives/year-archive.html
 
 - a resource /archive/year-archive with sling:resourceType = 
 blog/year-archive
 
 - a script /app/blog/year-archive/html.esp that extracts the year from 
 request.pathInfo and uses that information to query the repository for 
 matching posts and builds the archive list.
 
 It works but sounds a bit hacky to me : /archive/year-archive is used only 
 as a bridge between the redirect and the script, and the script has to re-do 
 pathInfo pattern matching to extract the year number. Is there a simpler way 
 to implement this ?
 
 Next I'm wondering how to implement multiple markup formats for content: 
 markdown and asciidoc end up being translated to html and formated using the 
 same template as raw html content, but how/where to implement the markup - 
 html transformation?
 
 From what I understand a content resource cannot be transformed before being 
 fed to the template script, so I thought to have two separate areas in the 
 content repository :
 - an authoring area where the original content is stored
 - an observer listens to that area, transforms the markdown/asciidoc content 
 to html and is stores it in a publish area
 - the publish area is the one that is actually rendered and published on 
 the web.
 
 Is this the way to go? Also, is it possible to write such an observer as a 
 script, or does it have to be a Java class packaged in a new bundle?
 
 Thanks in advance for your guidance and sorry for these noob questions :-)
 
 Sylvain
 
 -- 
 Sylvain Wallez - http://bluxte.net
 



Re: Getting started with Sling

2014-12-29 Thread Henry Saginor
Hmm … That is obvious I guess. :) It’s just the only thing I could think of. 
Seems maven sling plugin is getting a 404. And I just installed espblog this 
way myself.
But if you can access the web console you can also upload/install the bundle 
manually from there (from http://localhost:8080/system/console/bundles), just 
to get going. 

On Dec 29, 2014, at 3:10 PM, Sylvain Wallez sylv...@apache.org wrote:

 Sorry, I forgot to state the obvious: yes, Sling is started and the console 
 works fine!
 
 I started it from launchpad/builder/target by running
   java -jar org.apache.sling.launchpad-8-SNAPSHOT-standalone.jar
 
 Sylvain
 
 Le 30/12/2014 00:02, Henry Saginor a écrit :
 Hi Sylvian,
 
 Can you access Felix Web Console at http://localhost:8080/system/console? 
 How are you starting your Sling instance?
 
 Henry
  On Dec 29, 2014, at 2:30 PM, Sylvain Wallez sylv...@apache.org wrote:
 
 Le 29/12/2014 08:17, Bertrand Delacretaz a écrit :
 Hi Sylvain,
 
 Good to see you here ;-)
 Hi Bertrand ! Looking at the list archives, I've seen quite a few familiar 
 names ;-)
 
 On Sun, Dec 28, 2014 at 8:54 PM, Sylvain Wallez sylv...@apache.org wrote:
 ...I thought of having an authoring area that would store content in its
 original format (html, asciidoc or markdown) and have an observer that
 converts this content to html and stores it in the publishing area under
 /content/blog/year/month/post...
 That does match the Sling way of doing things, and that might also
 solve your archive URL issue, if you put your converted posts at paths
 like /posts/2014/12/25/merryxmas.
 
 By setting the same resource type on all nodes from 2014 down you can
 use the same rendering script for all of those URLs, that recursively
 collects all children and renders them.
 
 You don't need queries then, any URL like /posts/2014.html or
 /posts/2014/12.html will do the right thing, and generating the
 archive navigation is just walking down the tree.
 
 You could also omit the authoring area, directly store your content
 under /posts and use a Sling Model PostConstruct method [1] to convert
 the post's markup to HTML on the fly. Using access control to hide
 posts that shouldn't be public yet can make staging transparent,
 you'll just see the posts that belong to you when authoring as a
 logged in user, and they are invisible on the public website which
 uses the anonymous user.
 
 Hope this helps, and if you're able to contribute your blog code as an
 example that would be fantastic!
 Sounds interesting, but I'm facing a newbie problem: I tried to install the 
 espblog by following the instructions in samples/espblog/README.txt, and 
 installing fails with this message:
 
 $ mvn install -P autoInstallBundle
 ...
 [INFO] --- maven-bundle-plugin:2.5.3:install (default-install) @ 
 org.apache.sling.samples.path-based.rtp ---
 [INFO] Local OBR update disabled (enable with -DobrRepository)
 [INFO]
 [INFO] --- maven-sling-plugin:2.1.0:install (install-bundle) @ 
 org.apache.sling.samples.path-based.rtp ---
 [INFO] Installing Bundle 
 org.apache.sling.samples.path-based.rtp(/Users/sylvain/dev/apache.org/sling/sling/samples/path-based-rtp/target/org.apache.sling.samples.path-based.rtp-2.0.5-SNAPSHOT.jar)
  to http://localhost:8080/system/console via POST
 [ERROR] Installation failed, cause: Not Found
 
 This is for path-based-rtp, and the same happens for espblog.
 
 I suspect this must be related to obrRepositoryNONE/obrRepository in 
 parent/pom.xml but I don't know what to do with it.
 
 Thanks for any help, I'm feeling stupid :-)
 
 Sylvain
 
 -- 
 Sylvain Wallez - http://bluxte.net
 
 
 
 
 -- 
 Sylvain Wallez - http://bluxte.net
 



Re: SPNEGO authentication

2016-01-04 Thread Henry Saginor
Hi Jalal,

I don’t know anything about SPNEGO. But you can implement your own 
authentication handlers.
https://sling.apache.org/documentation/the-sling-engine/authentication/authentication-framework.html
 

https://sling.apache.org/documentation/the-sling-engine/authentication/authentication-authenticationhandler.html
 


I hope this helps.

Henry

> On Dec 31, 2015, at 12:43 AM, Jalal Almutawa  wrote:
> 
> Hello,
> 
> We are evaluating Sling and it looks very promising so far. We are just
> hitting a couple of hurdles, a major one is the user authentication.
> 
> We have a TomEE server that uses SPNEGO to
> authenticate users for our normal applications, how can we use that to
> authenticate Sling requests when running Sling on TomEE?
> 
> 
> Regards,
> Jalal Almutawa



Re: Create rep:SystemUser

2016-02-10 Thread Henry Saginor
Hi

Not sure if anyone has replied to you yet. But there is currently some work 
being done on this [1]. The ticket also discusses some options available to you 
now.
You can also create system users programmatically in the bundle activator.

[1] https://issues.apache.org/jira/browse/SLING-5355 


Henry

> On Feb 9, 2016, at 4:45 PM, Júnior  wrote:
> 
> Hi,
> 
> How can we create a rep:SystemUser with Sling?
> 
> Is there any tool we can use for that?
> 
> Thanks
> 
> -- 
> Francisco Ribeiro
> *SCEA|SCJP|SCWCD|IBM Certified SOA Associate*



Re: Call JSP Directly on Apache Sling

2016-08-12 Thread Henry Saginor
Hi Junior

Apache Sling is a resource based framework. You create a content node such as a 
web page (usually as JCR node in a JCR repository) with a property 
sling:resourceType that is mapped to a location of your scripts and other 
content properties that maybe specific to your application requirements.The URL 
you call is a URL to that resource. The framework then uses the resource type 
and information in the URL (like selectors and extension) to map it to a script 
(or servlet) that knows how to render it.
This is how sling separates content from code that renders it. You could map a 
Servlet deployed as OSGi service to a specific URL. But I don’t consider that 
good practice.

See Sling documentation for derails on how resource resolution works.
https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html
 

https://sling.apache.org/documentation/the-sling-engine/servlets.html 


I hope this helps.

Henry
  
> On Aug 9, 2016, at 6:55 AM, Júnior  wrote:
> 
> Hi Jason,
> 
> Thanks for you reply.
> 
> By "calling directly" I mean to be processed as it was being called in a
> web container. So the scriptlets and tags would be processed.
> 
> As I understood it correctly, I would need to have a servlet or component
> that would be responsible for calling that JSP, right?
> 
> Thanks
> 
> 
> 2016-08-09 10:50 GMT-03:00 Jason Bailey :
> 
>> This really depends on what you mean by 'calling directly'
>> 
>> if you put a jsp file under the /apps directory. You are putting a file
>> there. You can access that file directly as a file. If you are looking at
>> accessing  the functionality that the jsp provides, the servlet, you need
>> to point to something that says
>> 
>> 1. compile that jsp over there that the meta data is aware of into a
>> servlet
>> 2. pass the arguments from the called object into that servlet
>> 
>> That's the whole basis of the sling design with the separation of logic
>> and content that represents that logic. If you feel really compelled to do
>> something where you want to put a jsp and then be able to call that as
>> servlet from the location you put it, in my understanding, that would be a
>> custom implementation where you would need to create your own extension or
>> selector so that when you requested the jsp file it would be handled in the
>> manner that you want.
>> 
>> -Jason
>> 
>> 
>> From: Júnior 
>> Sent: Tuesday, August 9, 2016 9:10 AM
>> To: users@sling.apache.org
>> Subject: Call JSP Directly on Apache Sling
>> 
>> Hi,
>> 
>> Is there any way to call a JSP directly on Apache Sling?
>> 
>> I'd like to call a JSP that is deployed on Apache Sling.
>> 
>> Any tips are welcome.
>> 
>> Thanks
>> --
>> Francisco Ribeiro
>> *SCEA|SCJP|SCWCD|IBM Certified SOA Associate*
>> 
> 
> 
> 
> -- 
> Francisco Ribeiro
> *SCEA|SCJP|SCWCD|IBM Certified SOA Associate*



Re: import and export JCR data

2017-02-07 Thread Henry Saginor
Hi Lance,

I sometimes use this simple shell script [1] with file vault to import content 
from one AEM instance to another. I am happy to share if it helps. I am not 
sure if you are doing this between 2 sling instances though. But you should be 
able to change it to use export instead of rcp. Of course you would also need 
to change the command URL since it has /crx/.

Also, this just a guess, but see if your Sling instance has these bundles 
active. I think your guess is correct. The error indicates that the repository 
you are connecting to does not support the protocol you are using - WebDav in 
this case.
Jackrabbit WebDAV Library org.apache.jackrabbit.jackrabbit-webdav
Apache Sling Simple WebDAV Access to repositories org.apache.sling.jcr.webdav
Apache Sling DavEx Access to repositories org.apache.sling.jcr.davex

[1]
#!/bin/sh

help() {
echo
echo "parameters: user:password@sourceHost user:password@destHost cqPath"
echo “example: $0 admin:admin@localhost:4502  
admin:admin@localhost:4503  /content/mysite"
echo
}

case $1 in
--help | -h | -help | -hlep)
help
;;
*)
if [ `echo $@ | wc -w` -gt 2 ]
then
  vlt -v rcp -b 1000 -t 1 -r http://$1/crx/-/jcr:root$3 
http://$2/crx/-/jcr:root$3
  echo "Done!"
  echo
else
  help
fi;;
esac
> On Feb 7, 2017, at 3:18 PM, lancedolan  wrote:
> 
> If it's not composum, then it's file-vault or JCR related, which is even more
> concerning. 
> 
> I'm pretty confident this isn't user error. I've given consulting
> demonstrations, teaching others the ins and outs of file-vault XML-to-node
> translation, the various complex rules one can combine, and also written
> code that dynamically assembles valid file vault packages to be POSTed to
> CRX package manager, which I believe also uses file vault under the hood...
> I'm really quite aware, in general, of how this thing should work. Of course
> I could be missing something, but if this is user error, then it's something
> esoteric and imperceptible, something very different than the CRX and file
> vault I'm used to.
> 
> Here's what I'm doing:
> 
> 1) click "+" to create new package
> 2) click filter tab and "+" to create new filter
> 3) give root path "/content" and save with default Replace Import Mode and
> empty filter set
> 4) Click Build
> 
> Result: empty content directory in the package. Nothing in the log file. 
> 
> I suppose as a next step I can split all com.composum logs to a separate log
> and set that to DEBUG level and watch for things... Maybe do the same with
> org.apache.jackrabbit.vault. 
> 
> One plausible possibility seems that my /content data might be in some
> invalid state such that file vault can't/won't read it?? I'm really grasping
> at possibilities at this point.
> 
> 
> 
> --
> View this message in context: 
> http://apache-sling.73963.n3.nabble.com/import-and-export-JCR-data-tp4069390p4070161.html
> Sent from the Sling - Users mailing list archive at Nabble.com.



Re: How to create Rest APIs for non-JCR data in Sling 8??

2017-01-31 Thread Henry Saginor

I apologize. I think I missed the “serving up large number of virtual 
resources” part of your requirements.
You can use JCR nodes just to create resources that map to your resource type 
and still get your data from anywhere.
But if resource path itself needs to be dynamic or it’s difficult to manage JCR 
nodes for those resources then a better approach would be create a “fake” 
resource as you are doing.
You may have such a use case. This is probably the part of your requirement 
that I missed.

BTW I do apologize if I came across like I was questioning your experience. I 
did not mean it that way at all. I do have a lot of experience with Sling and 
CQ/AEM as well. :)  

> On Jan 31, 2017, at 12:57 PM, lancedolan <lance.do...@gmail.com> wrote:
> 
> Henry Saginor-2 wrote
>> Hi Lance,
>> 
>> I think a better practice is to register your servlet with a resource type
>> instead of path.
> 
> This requires creating a node per resource. Please see my prior post where I
> disqualify all solutions that involve creating nodes. My entire requirement
> is that I'm creating a service that serves data that isn't in the JCR. I
> truly do appreciate your taking the time out of your day to try to help me,
> though, so I hope you don't feel slighted! :) I have been lead AEM Architect
> on Sling applications that serve millions of users globally and am already
> familiar with the fundamentals of Sling resource and script resolution :) 

> This is just my first time needing to serve up "virtual" resources of very
> large number like this, such that a dynamic-URL service is absolutely the
> only solution.
> 
> Update: I've made progress with the ResourceProvider solution! It seems the
> 403 response I was getting was actually result of my ResourceProvider
> successfully returning SyntheticResource, which Sling then responded with a
> 403 for...  It seems all I need to learn is how to properly instantiate a
> Resource object and return it :)
> 
> It seems I need to learn about this ResourceWrapper class and how to create
> ResourceMetadata
> 
> 
> 
> --
> View this message in context: 
> http://apache-sling.73963.n3.nabble.com/How-to-create-Rest-APIs-for-non-JCR-data-in-Sling-8-tp4069947p4070022.html
> Sent from the Sling - Users mailing list archive at Nabble.com.



Re: How to create Rest APIs for non-JCR data in Sling 8??

2017-01-31 Thread Henry Saginor
Oh you beat to it.:)  I had a similar approach for aggregating page specific 
JavaScript via a fake resource and was going to provide a skeleton of it. But I 
am glad you got it to work.

I want to add that Sling could probably benefit from Jersey-like ability to 
generate web services from simple POJOs. Maybe some day something like that can 
be implemented on top of Sling Models. :)
I think this is mainly what developers are looking for when they talk about 
such integration.

> On Jan 31, 2017, at 1:25 PM, lancedolan  wrote:
> 
> Aha! Solved Here's my solution for posterity.
> 
> While Jersey would have been a preferred, more feature-rich solution, I just
> couldn't get the OSGI-Jersey stuff working.
> 
> The solution: 
> 
> - ResourceProvider listens for all requests to a particular path, and
> returns a false "Resource" object, which doesn't actually exist in the JCR,
> but it does have a resourceType
> 
> - A Servlet registers to render that resourceType.
> 
> Between these two, you've essentially got a Servlet that listens to a all
> requests that fall under a particular Path :)
> 
> Registering a Servlet for a resourceType is pretty elementary, but for
> posterity looking to get this ResourceProvider working in Sling 8, here's
> how I did it. I expect there are better ways, but this is demonstrative:
> 
> 
> /**
> * Created by lancedolan on 1/27/17.
> */
> @Component
> @Service(value=ResourceProvider.class)
> @Properties({
>@Property(name = ResourceProvider.ROOTS, value = "service/image"),
>@Property(name = ResourceProvider.OWNS_ROOTS, value = "true")
> })
> public class ImageResourceProvider implements ResourceProvider  {
> 
> //@Override
>public Resource getResource(ResourceResolver resourceResolver, String
> path) {
> 
>AbstractResource abstractResource;
>abstractResource = new AbstractResource() {
>@Override
>public String getResourceType() {
>return ImageTypeServlet.RESOURCE_TYPE;
>}
> 
>@Override
>public String getResourceSuperType() {
>return null;
>}
> 
>@Override
>public String getPath() {
>return path;
>}
> 
>@Override
>public ResourceResolver getResourceResolver() {
>return resourceResolver;
>}
> 
>@Override
>public ResourceMetadata getResourceMetadata() {
>return new ResourceMetadata();
>}
>};
> 
>return abstractResource;
>}
> 
> //@Override
>public Resource getResource(ResourceResolver resourceResolver,
> HttpServletRequest httpServletRequest, String path) {
>return getResource(resourceResolver , path);
>}
> 
> //@Override
>public Iterator listChildren(Resource resource) {
>return null;
>}
> }
> 
> And then you just create your own servlet, analogous to my ImageTypeServlet
> which contains a static final String RESOURCE_TYPE
> 
> 
> 
> --
> View this message in context: 
> http://apache-sling.73963.n3.nabble.com/How-to-create-Rest-APIs-for-non-JCR-data-in-Sling-8-tp4069947p4070023.html
> Sent from the Sling - Users mailing list archive at Nabble.com.



Re: How to create Rest APIs for non-JCR data in Sling 8??

2017-01-27 Thread Henry Saginor
Can’t you just create sling servlet registered to some resource type? 
You can then simply create JCR node(s) mapped to your resource type. 
You can also use a SynthaticResource via custom resource provider, which is the 
track you’re on and what Steven is suggesting. 
But I find that in most cases just creating a JCR node is more convenient and 
you can apply JCR ACLs to it control access if you need it. 

> On Jan 27, 2017, at 9:34 PM, Steven Walters  wrote:
> 
> On Sat, Jan 28, 2017 at 6:27 AM, lancedolan  wrote:
>> Hi friends,
>> 
>> I've tried routing questions through stackoverflow to cut down my mails to
>> this list. I'm losing lots of time on this one, though, and am stuck.
>> 
>> I need to create APIs which don't represent Sling Resources. Example:
>> /services/images/123123123
>> that image will exist somewhere else.
>> 
>> Bertrand suggests creating a ResourceProvider, as in the example here [1].
>> However, that uses the spi package which is not in version 2.9.0 of
>> org.apache.sling.api, and thus, not available to me in Sling 8.
>> 
>> I did find a ResourceProvider interface to implement though, and created
>> this code:
>> 
>> /**
>> * Created by lancedolan on 1/27/17.
>> */
>> @Component
>> @Service(value=ResourceProvider.class)
>> @Properties({
>>@Property(name = ResourceProvider.ROOTS, value = "things"),
>>@Property(name = ResourceProvider.OWNS_ROOTS, value = "true")
>> })
>> public class ImageResourceProvider implements ResourceProvider {
>> 
>>/** If this provider required a context this would be more elaborate,
>> *  but for this simple example we don't need one.
>> */
>>public static class DoesNotNeedAContext {
>>};
>> 
>>@Override
>>public Resource getResource(ResourceResolver resourceResolver, String
>> path) {
>>Resource returnResource = new SyntheticResource(resourceResolver,
>> path, "edlio/microservice/image");
>>returnResource.getValueMap().put("myProp" , "myValue");
>>return returnResource;
>>}
>> 
>>@Override
>>public Resource getResource(ResourceResolver resourceResolver,
>> HttpServletRequest httpServletRequest, String path) {
>>return getResource(resourceResolver , path);
>>}
>> 
>>@Override
>>public Iterator listChildren(Resource resource) {
>>return null;
>>}
>> }
>> 
>> 
>> The result is that I get a 403 response. How do I control the authentication
>> for resources that don't actually exist? The fact that I'm not getting 404
>> means that my ResourceProvider is at least registering successfully.
>> 
>> Finally, I'd much prefer to use Jersey if possible... Anybody have success
>> getting Jersey to work in Sling 8? I dumped a bunch of time into it and gave
>> up after class not found errors for classes that should be found [2].
>> 
>> The ultimate goal is just to provide a restful API in Sling 8 and the
>> static-path-declaration of SlingSafeMethodsServlet just doesn't cut it.
>> 
>> Thanks a million guys...
> 
> The Sling paradigm for this is to create resources through the
> resource provider,
> and then create/register a servlet to respond to the resource type
> you're creating (not a static path).
> 
> So from your above code, you'd create an additional servlet registered
> to the resourceType "edlio/microservice/image" (instead of registered
> to a static path) and implement GET inside it.
> 
> Without the corresponding servlet, this is most likely being served by
> the default GET servlet, which will not particularly understand how to
> deal with these resources, thus the errors.



Re: How to create Rest APIs for non-JCR data in Sling 8??

2017-01-28 Thread Henry Saginor
In my opinion Sling is first and foremost a REST framework specifically 
designed for this kind of thing. It’s not only to serve JCR content.
The paradigm Steven described earlier in this thread is EXACTLY the way to 
implement it. In the Sling world the resource IS the RESTful object addressable 
via a URI. The only thing I can add, as I wrote before, is that it’s not 
necessary to implement a custom resource provider.
You can simply create JCR nodes/resources to map to your resource type via 
sling:resourceType. And what your servlet returns is up to you and your 
requirements. That works in most cases. 
You can easily integrate your servlet with existing OSGi service via 
declarative services and use any framework/library you need internally 
(provided you can make it available in OSGi container) to integrate with your 
data where it adds value.
But in my opinion it does not make sense integrating Sling with other 
framework, such as Spring, which follow different paradigms to do the same 
things as Sling + Declarative Services. It increases complexity and does not 
add value.

My advice is don’t shoot yourself in the foot and keep things as simple as 
possible. Just implement a servlet, integrate with existing service via DS if 
needed, and format and return the response based on your requirements. Then 
create a resource (JCR or custom ResourceProvider), map it to your servlet via 
sling:resourceType. This is how I have always implemented RESTful services in 
Sling without many limitations. The framework is specifically designed for this.

Henry  
 
> On Jan 28, 2017, at 7:57 AM, Jason E Bailey  wrote:
> 
> 
> Its my understanding that the question on ACL's depends on where it is
> inheriting the ACL from. Taking your code as literal, you've declared
> that you own everything under /things and it would inherit the ACL of /.
> So if you put your ROOT as /content/remote/things You could set JCR ACLs
> on /content/remote.
> 
> Theoretically I assume that your resource could provide an ACL as the
> ACL is just a resource in the tree.
I am not sure if you can do this since ACLs are at JCR level and are checked 
via JCR. 
> 
> As others suggested using a resource provider in this way may not be the
> best solution. As the whole point of Sling is to manage content and
> splitting it into different pieces can be awkward.
> 
> I'm assuming that you don't need to do POST operations, and that using
> Oak with an S3 file storage configuration is out.
> 
> If you can tell Sling what's on the remote store, you could just use a
> reference to the data. In the same way that in AEM, an image component
> doesn't necessarily have the image, rather it can have a pointer to the
> image.  So your renderer can just go out and retrieve the image and
> return it.
> 
> Or, the Sling Resource Merger
> https://sling.apache.org/documentation/bundles/resource-merger.html
> 
> In this case you can merge your resource provider with a JCR Path. So
> that your resource provider provides the remote content while the
> associated meta data can be stored in the JCR. Haven't tried this myself
> though.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --
> Jason
> 
> On Fri, Jan 27, 2017, at 04:27 PM, lancedolan wrote:
>> Hi friends,
>> 
>> I've tried routing questions through stackoverflow to cut down my mails
>> to
>> this list. I'm losing lots of time on this one, though, and am stuck.
>> 
>> I need to create APIs which don't represent Sling Resources. Example:
>> /services/images/123123123
>> that image will exist somewhere else.
>> 
>> Bertrand suggests creating a ResourceProvider, as in the example here
>> [1].
>> However, that uses the spi package which is not in version 2.9.0 of
>> org.apache.sling.api, and thus, not available to me in Sling 8.
>> 
>> I did find a ResourceProvider interface to implement though, and created
>> this code:
>> 
>> /**
>> * Created by lancedolan on 1/27/17.
>> */
>> @Component
>> @Service(value=ResourceProvider.class)
>> @Properties({
>>@Property(name = ResourceProvider.ROOTS, value = "things"),
>>@Property(name = ResourceProvider.OWNS_ROOTS, value = "true")
>> })
>> public class ImageResourceProvider implements ResourceProvider {
>> 
>>/** If this provider required a context this would be more elaborate,
>> *  but for this simple example we don't need one.
>> */
>>public static class DoesNotNeedAContext {
>>};
>> 
>>@Override
>>public Resource getResource(ResourceResolver resourceResolver, String
>> path) {
>>Resource returnResource = new SyntheticResource(resourceResolver,
>> path, "edlio/microservice/image");
>>returnResource.getValueMap().put("myProp" , "myValue");
>>return returnResource;
>>}
>> 
>>@Override
>>public Resource getResource(ResourceResolver resourceResolver,
>> HttpServletRequest httpServletRequest, String path) {
>>return getResource(resourceResolver , path);
>>}
>> 
>>@Override

Re: Adding jcr:created date to resource

2016-09-20 Thread Henry Saginor
I believe jcr:created is a protected JCR property which means it can only be 
set by the repository. This constraint is enforced by JCR implementation, not 
by Sling.
As Steven suggested remove the line that explicitly sets it and it should work. 
If you have a use case that requires setting a “created” date explicitly you 
should define an application specific property that your application should be 
able to interpret.  

> On Sep 20, 2016, at 6:25 AM, Steven Walters  wrote:
> 
> A) Sling expects the mixin types to passed as their raw String values
> and not as the JCR NameValue type.
> 
> The fact that the JCR NameValue type is being utilized instead is
> causing the error you are seeing as the Sling functionality converted
> it to a String (incorrectly) causing it to become invalid to the JCR
> expectations causing an exception on trying to add the corrupted mixin
> type.
> 
> B) jcr:created is specifically handled by the JCR system, so Sling
> refuses to be the writer/modifier of the property, silently ignoring
> any attempts at setting/modifying the value.
> 
> Therefore, once you remove the attempt at setting jcr:created and
> correct the jcr:mixinTypes value, you should be allowed to create the
> resource.
> From there, the JCR system should automatically add the jcr:created
> due to the mixin Type.
> 
> On Tue, Sep 20, 2016 at 9:46 PM, Roy Teeuwen  wrote:
>> Hello all,
>> 
>> I am trying to create an nt:unstructured resource programatically, which 
>> contains a jcr:created property, but I don’t seem to find a way to add this 
>> programatically, nor how to add a jcr:mixinType (which would make it 
>> possible).
>> 
>> I tried the following, but it isn’t working:
>> 
>> Resource myResource = resourceResolver.getResource("/myresource");
>> Map properties = new HashMap();
>> properties.put("jcr:primaryType", "nt:unstructured”);
>> properties.put("jcr:mixinTypes", new NameValue[] 
>> {NameValue.valueOf("mix:created")});
>> properties.put(“jcr:created”, Calendar.getInstance());
>> Resource dummy = resourceResolver.create(myResource, "dummy", properties);
>> resourceResolver.commit();
>> 
>> I get the following exception:
>> 
>> java.lang.IllegalArgumentException: Value can't be stored in the repository: 
>> org.apache.jackrabbit.value.NameValue@0
>> 
>> 
>> Can anyone tell me on how to add this on creation time?
>> 
>> Thanks!
>> Roy



issue with sling models injection

2016-09-19 Thread Henry Saginor
Hi All,

Today we had a production issue with multiple null pointer exceptions in our 
sling models. 
Multiple fields with @Inject annotations were just not getting injected even 
though they were not declared optional. Some of these field were content 
properties and some common sling objects like resource resolver.
The issue fixed itself after deleting all application bundles, redeploying 
them, and then restarting and refreshing sling models bundles.

I am curious if anyone else has seeing this. Is this a known issue? 
Sling Models version is 1.1.0.

Henry

Re: issue with sling models injection

2016-09-20 Thread Henry Saginor
Hi Santiago,

Thank for a reply.

To clarify this is not a build issue. Fields were just not injected at runtime. 
In most cases this resulted in null pointer exception in post constructor 
method or code calling adaptTo to get the required model. It gets the models 
class and gets NPE on the field it expects to be there. Note that the model 
gets instantiated. The injection just does not occur even though the fields to 
be injected are available. If it did not get instantiated because of a missing 
field (missing content property) that would be expected behavior. It’s like the 
framework just fails to detect that there is a field that needs to be injected. 

Also, this is not a sightly integration issue. We have some sightly components. 
But in this case in all instances I found it was in a JSP or a servlet calling 
adaptTo.

> On Sep 20, 2016, at 2:27 AM, Santiago Garcia Pimentel 
> <santiago.pimen...@netcentric.biz> wrote:
> 
> Hi Henry,
> 
> I’ve seen this behavior when building the model fails (because of a failed 
> injection or an exception in @PostConstruct ) and then sightly falls back to 
> the regular  java pojo Use provider, which does not support injection (so all 
> fields are null). Check your logs or debug to see if this is the case.
> 
> If that is the problem I recommend you to install 
> org.apache.sling.scripting.sightly.models.provider, which uses the 
> ModelFactory service instead of adaptTo to build Sling models. This will make 
> errors more apparent and you won’t get a fallback to the pojo provider.
> 
> Santiago García Pimentel| Sr Software Engineer
> Netcentric Ibérica SLU
> M: +34687915463
> santiago.pimen...@netcentric.biz | www.netcentric.biz
> 
>> On Sep 20, 2016, at 6:53 AM, Henry Saginor <hsaginor.apa...@gmail.com> wrote:
>> 
>> Hi All,
>> 
>> Today we had a production issue with multiple null pointer exceptions in our 
>> sling models. 
>> Multiple fields with @Inject annotations were just not getting injected even 
>> though they were not declared optional. Some of these field were content 
>> properties and some common sling objects like resource resolver.
>> The issue fixed itself after deleting all application bundles, redeploying 
>> them, and then restarting and refreshing sling models bundles.
>> 
>> I am curious if anyone else has seeing this. Is this a known issue? 
>> Sling Models version is 1.1.0.
>> 
>> Henry
> 



esx ScriptEngine + react.js

2017-08-17 Thread Henry Saginor
Hi,

I would like to run some server side react.js components in Sling. I was 
experimenting with the esx engine [1]  which works like a NodeJs loader and 
allows you to load any valid Node module.
I am able to run the demo examples that come with that bundle. So, I installed 
react npm module and it’s dependencies under /libs/esx/node_modules. But when I 
try to load react based script in sling I get an exception at [2].
I see “process” properties declared in SlingBabel.js and when I debug I see 
that the transpile step works for my initial script (one sling:resourceType 
points to).

I know this esx engine is considered experimental according to JIRA ticket [3]. 
But I was still curious if anyone else has tried this or can help out.

If I can successfully load react I would like to work on some tests suggested 
in JIRA and see if I can contribute to this module. Therefor I thought it 
appropriate to send this to dev list. 
I apologize in advance for spam if that’s not correct.  

Regards, 

Henry

[1] https://github.com/apache/sling/tree/trunk/contrib/scripting/esx 


[2] jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "process" is 
not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at 
jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
at 
jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
at 
jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1441)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39714$173AA$warning.L:2(/libs/esx/node_modules/fbjs/lib/warning.js:25)
at 
java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at 
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:651)
at 
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at 
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at 
jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117)
at org.apache.sling.scripting.esx.Module.runScript(Module.java:249)
at org.apache.sling.scripting.esx.Module.require(Module.java:670)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39711$349A$ReactNoopUpdateQueue.L:2#require(/libs/esx/node_modules/react/lib/ReactNoopUpdateQueue.js:2)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39710$187AA$ReactNoopUpdateQueue.L:2(/libs/esx/node_modules/react/lib/ReactNoopUpdateQueue.js:14)
at 
java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at 
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:651)
at 
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at 
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at 
jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117)
at org.apache.sling.scripting.esx.Module.runScript(Module.java:249)
at org.apache.sling.scripting.esx.Module.require(Module.java:670)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39704$345A$ReactBaseClasses.L:2#require(/libs/esx/node_modules/react/lib/ReactBaseClasses.js:2)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39703$183AA$ReactBaseClasses.L:2(/libs/esx/node_modules/react/lib/ReactBaseClasses.js:17)
at 
java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at 
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:651)
at 
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at 
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at 
jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117)
at org.apache.sling.scripting.esx.Module.runScript(Module.java:249)
at org.apache.sling.scripting.esx.Module.require(Module.java:670)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39696$334A$React.L:2#require(/libs/esx/node_modules/react/lib/React.js:2)
at 
jdk.nashorn.internal.scripts.Script$Recompilation$39695$172AA$React.L:2(/libs/esx/node_modules/react/lib/React.js:16)

[3] https://issues.apache.org/jira/browse/SLING-6680