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-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  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 lancedolan
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-31 Thread lancedolan
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: Sling Health Checks

2017-01-31 Thread Jason Bailey
So I'm part of a team that I will characterize as being "highly resource 
optimized" We have an AppDynamics instance that we use to monitor the state of 
our instances as much as possible. One of the OOTB features is the ability to 
tie into JMX and present graphs and historical information on specific items.

We have a variety of business processes and functions in Sling that would be 
beneficial to us to monitor, and in particular graph, so that we can do 
intelligent alarming.  Where we are having problems is that collection of state 
that would allow us to do intelligent monitoring. 

Example being submission processing. If the number of submissions each instance 
is handling falls below a certain threshold or increases beyond a certain 
number, it's an issue of concern, a warning. But certain days and a particular 
time, it's a situation where need someone looking at it immediately.

Additionally having a value being returned would also allow us to track trends 
or unusual events in a historical manner so that we can hopefully identify 
issues before they happen.

-Jason

-Original Message-
From: Georg Henzler [mailto:slin...@ghenzler.de] 
Sent: Tuesday, January 31, 2017 3:24 AM
To: users@sling.apache.org
Subject: Re: Sling Health Checks

Hi Jason,

no it is not possible at the moment - but nobody stops you to make the HC 
component also provide an additional, custom MBean that shares some additional 
result properties of the HC execution to other services.

In theory the HC result could be extended to allow for custom properties (that 
are then in turn exposed via JMX), but the idea behind the HCs is that due to 
the clearly defined result type (with a clear semantic for each status) 
consumers can easily decide whether an instance is healthy or not, additional 
properties might be confusing. Could you describe your use case in a bit more 
detail?

Regards
Georg

On 2017-01-30 18:56, Jason Bailey wrote:
> Anyone know if it's possible to use the Sling Health Checks to expose 
> a value via the MBean other than the ones explicitly defined in the 
> Result Object?
> 
> Thanks
> -Jason


Re: Sling Health Checks

2017-01-31 Thread Bertrand Delacretaz
Hi.

On Tue, Jan 31, 2017 at 9:23 AM, Georg Henzler  wrote:
> ...nobody stops you to make the HC
> component also provide an additional, custom MBean that shares some
> additional result properties of the HC execution to other services

Or maybe put that additional information in its own MBean, and use HC
just to check that those values are in range - that might be a better
separation of concerns.

-Bertrand


Re: Sling Health Checks

2017-01-31 Thread Georg Henzler

Hi Jason,

no it is not possible at the moment - but nobody stops you to make the 
HC component also provide an additional, custom MBean that shares some 
additional result properties of the HC execution to other services.


In theory the HC result could be extended to allow for custom properties 
(that are then in turn exposed via JMX), but the idea behind the HCs is 
that due to the clearly defined result type (with a clear semantic for 
each status) consumers can easily decide whether an instance is healthy 
or not, additional properties might be confusing. Could you describe 
your use case in a bit more detail?


Regards
Georg

On 2017-01-30 18:56, Jason Bailey wrote:

Anyone know if it's possible to use the Sling Health Checks to expose
a value via the MBean other than the ones explicitly defined in the
Result Object?

Thanks
-Jason