Default Sling Servlet | Community
Skip to main content
Xena_bcn
New Participant
October 16, 2015
Solved

Default Sling Servlet

  • October 16, 2015
  • 17 replies
  • 6070 views

Hi

My Logout Servlet is defined as

 

@Component(enabled = true)
@Service(Servlet.class)
@Properties({
    @Property(name="resourceTypes", value="sling/servlet/default"),
    @Property(name="methods", value="POST"),
    @Property(name="selectors", value="ourlogout"),
    @Property(name="extensions", value="html"),
    @Property(name="service.pid", value="package.LogoutServlet", propertyPrivate=false),
})

 

After compaling and using VLT to commit changes to the repository.  i see it in http://localhost:4502/system/console/components

but not in http://localhost:4502/system/console/services

 

what is problem here?

How else I can test from Adobe AEM this default Sling Servlet ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by edubey

Here is a good documentation for sling servlets: [1] and Read this as well [2]

You are able to see it  because you have enabled (@Component(enabled = true))  .

You can access this servlet via path which you have given or properties which you have defined.

Example. A servlet defined as 

@Service(Simple.class) @SlingServlet(paths = { "/bin/simple/adobe" }, generateComponent = false) @Component(label = "Simple adobe component", enabled = true, immediate = true, metatype = false) public class Simple extends SlingSafeMethodsServlet { }

Will be accessed via path 

/bin/simple/adobe

 

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

[2] http://stackoverflow.com/questions/8886430/what-is-the-difference-between-osgi-components-and-services

17 replies

Employee
October 16, 2015

Why are you not using a maven project to build and deploy your servlet? I haven't heard of using vlt to commit code changes to AEM.

[1]https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

edubey
edubeyAccepted solution
New Participant
October 16, 2015

Here is a good documentation for sling servlets: [1] and Read this as well [2]

You are able to see it  because you have enabled (@Component(enabled = true))  .

You can access this servlet via path which you have given or properties which you have defined.

Example. A servlet defined as 

@Service(Simple.class) @SlingServlet(paths = { "/bin/simple/adobe" }, generateComponent = false) @Component(label = "Simple adobe component", enabled = true, immediate = true, metatype = false) public class Simple extends SlingSafeMethodsServlet { }

Will be accessed via path 

/bin/simple/adobe

 

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

[2] http://stackoverflow.com/questions/8886430/what-is-the-difference-between-osgi-components-and-services

edubey
New Participant
October 16, 2015
When invoking your servlet, are you seeing anything in log any error?       
smacdonald2008
New Participant
October 16, 2015

For a logout - i would have a button and when its clicked - i would invoke a Sling Servlet by using binding by path. 

As shown in this Sling topic - both are valid: https://sling.apache.org/documentation/the-sling-engine/servlets.html.

However - if you want to bind the servlet by resource type - here is an article:

Binding Adobe Experience Manager Servlets to ResourceTypes @ https://helpx.adobe.com/experience-manager/using/resourcetypes.html.

Now for using the vault tool - you use that to sync code between your IDE ( for example, Eclipse) and the JCR - not to build and deploy servlets - you use Maven for that - as shown in the above article

Xena_bcn
Xena_bcnAuthor
New Participant
October 16, 2015

thank you, @edubey

Meanwhile I was reading about Servlets called by resource type and default servlet.

Even though I can see this servlet in Components, and in the 2nd link you provided, it is said : "A component may publish itself as an OSGi service."

in publish instance "Logout" button is not working.

The post action just changes the URL to:   /content/<site>/<path>/<html_name>.ourlogout.html

But the logout servlet hasn't been called.

Where did I leave something?

Xena_bcn
Xena_bcnAuthor
New Participant
October 16, 2015

smacdonald2008 wrote...

For a logout - i would have a button and when its clicked - i would invoke a Sling Servlet by using binding by path. 

As shown in this Sling topic - both are valid: https://sling.apache.org/documentation/the-sling-engine/servlets.html.

However - if you want to bind the servlet by resource type - here is an article:

Binding Adobe Experience Manager Servlets to ResourceTypes @ https://helpx.adobe.com/experience-manager/using/resourcetypes.html.

Now for using the vault tool - you use that to sync code between your IDE ( for example, Eclipse) and the JCR - not to build and deploy servlets - you use Maven for that - as shown in the above article

 

 


thank you.

I can do that

But problem is that this Servlet is not listed in Services.

here

https://forums.adobe.com/thread/1113958

 

It is written "ExampleServlet must be visible in the bundle in the Services list"

But my servlet is inside the whole project JAR ( OSGI-INF)

Maybe i am doing something wrong.

 

This servlet is visible in Components only.

Xena_bcn
Xena_bcnAuthor
New Participant
October 16, 2015

Opkar Gill wrote...

Why are you not using a maven project to build and deploy your servlet? I haven't heard of using vlt to commit code changes to AEM.

[1]https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

 


yes I use Maven.... 

https://docs.adobe.com/docs/en/cq/5-5/developing/developmenttools/developing_with_eclipse.html

here it is written to use VLT too.

Xena_bcn
Xena_bcnAuthor
New Participant
October 16, 2015

edubey wrote...

When invoking your servlet, are you seeing anything in log any error?

 


how to invoke the default servlet?

In 4503 on clicking  logout button no traces in log.

Xena_bcn
Xena_bcnAuthor
New Participant
October 16, 2015

I read this page even before asking  custom-sling-servlets.html

But they use paths of the servlet.

But I would like to know why my logout doeas't work  with this default servlet with resource type.

smacdonald2008
New Participant
October 16, 2015

WHen you define a servlet - you should not be using @Component and @Service. For a Servlet - use @SlingServlet:

@SlingServlet(methods = {"GET"},
    metatype = true,
    resourceTypes = {"services/powerproxy"},
    selectors = {"groups"})