Skip to main content
Xena_bcn
Level 5
Oct 16, 2015 2:28 AM UTC
Solved

Default Sling Servlet

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.
edubey
edubeyAccepted solution
Level 10
Oct 16, 2015 2:28 AM UTC

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

Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

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.

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

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.

Translate
Xena_bcn
Xena_bcnAuthor
Level 5
Oct 16, 2015 2:28 AM UTC

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?

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:28 AM UTC

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. 

Translate
edubey
Level 10
Oct 16, 2015 2:28 AM UTC
When invoking your servlet, are you seeing anything in log any error?       
Translate
edubey
edubeyAccepted solution
Level 10
Oct 16, 2015 2:28 AM UTC

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

Translate
Adobe Employee
Oct 16, 2015 2:28 AM UTC

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

Translate