Expand my Community achievements bar.

SOLVED

Servet not getting resolved

Avatar

Level 4

Hi ,
I tried to create a sample servlet in aem 6.3 .


Please see below for the piece of code :

// all the import statements

@SlingServlet(

paths={"/bin/customservlet"}

)

public class Test extends SlingAllMethodsServlet {

private static final long serialVersionUID = 1L;

protected static final Logger LOGGER = LoggerFactory.getLogger(Test.class);

    @Override

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

    LOGGER.info("ENTERED THE SERVLET");

    }  

}

When I am trying to hit the servlet using locahost:4502/bin/customservlet  - it is giving the following message 

Resource at '/bin/customservlet' not found: No resource found

RequestURI=/bin/customservlet

Servlet= /apps/sling/servlet/errorhandler/404.html

I am not sure why  I am getting this error.I checked error logs as well which is giving the following error :

31.01.2018 11:01:08.475 *INFO* [0:0:0:0:0:0:0:1 [1517376668472] GET /bin/customservlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Resource /bin/customservlet not found

31.01.2018 11:01:08.478 *ERROR* [0:0:0:0:0:0:0:1 [1517376668472] GET /bin/customservlet HTTP/1.1] org.apache.sling.servlets.resolver.internal.SlingServletResolver Calling the error handler resulted in an error

java.lang.Error: Unresolved compilation problems:

Only a type can be imported. com.adobe.cq.sightly.WCMUse resolves to a package

WCMUse cannot be resolved to a type

The method activate() of type ResponseStatus must override or implement a supertype method

The method getResponse() is undefined for the type ResponseStatus

at apps.sling.servlet.errorhandler.ResponseStatus.<init>(ResponseStatus.java:18)

Please let me know how I will be able to resolve it.

Thanks,

Pallavi

1 Accepted Solution

Avatar

Correct answer by
Employee
11 Replies

Avatar

Employee

When you open your bundle in /system/console, do you see your servlet there listed as a service?

Avatar

Level 4

I am not able to see the servlet in the bundle .I created the sample servlet under we-retail project only (I can see CartEntryServlet).
Not sure what went wrong.

Avatar

Employee

Then your servlet is not properly registered. Do you see any warnings during the maven-deploy?

Avatar

Level 4

Yes there are some warnings ,Please find it below :

[WARNING] Bundle com.adobe.cq.sample:we.retail.core:bundle:2.0.5-SNAPSHOT : Split package, multiple jars provide the same package:we/retail/core/productrelationships

Use Import/Export Package directive -split-package:=(merge-first|merge-last|error|first) to get rid of this warning

Package found in   [Jar:., Jar:uber-jar]

Class path         [Jar:., Jar:org.apache.felix.scr.annotations, Jar:bndlib, Jar:osgi.core, Jar:osgi.cmpn, Jar:osgi.annotation, Jar:jsr305, Jar:javax.inject, Jar:slf4j-api, Jar:jcr, Jar:servlet-api, Jar:commons-lang3, Jar:commons-collections, Jar:org.apache.sling.models.api, Jar:core.wcm.components.core, Jar:uber-jar]

[WARNING] Bundle com.adobe.cq.sample:we.retail.core:bundle:2.0.5-SNAPSHOT : aQute.bnd.annotation.Version annotation used in class we.retail.core.package-info. Bnd versioning annotations are deprecated as of Bnd 3.2 and support will be removed in Bnd 4.0. Please change to use OSGi versioning annotations.

[WARNING] Bundle com.adobe.cq.sample:we.retail.core:bundle:2.0.5-SNAPSHOT : aQute.bnd.annotation.ProviderType annotation used in class com.adobe.cq.commerce.api.CommerceServiceFactory. Bnd versioning annotations are deprecated as of Bnd 3.2 and support will be removed in Bnd 4.0. Please change to use OSGi versioning annotations.

[WARNING] Bundle com.adobe.cq.sample:we.retail.core:bundle:2.0.5-SNAPSHOT : aQute.bnd.annotation.ProviderType annotation used in class com.adobe.cq.commerce.api.ProductRelationshipsProvider. Bnd versioning annotations are deprecated as of Bnd 3.2 and support will be removed in Bnd 4.0. Please change to use OSGi versioning annotations.

Avatar

Correct answer by
Employee

Avatar

Administrator

Apart from what Feike mentioned, if you still want to use this article:- Adobe Experience Manager Help | Developing AEM components that display WordPress information

Or

Adobe Experience Manager Help | Creating an AEM HTML Template Language Component that posts data usi...

OR

Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets

package com.adobe.cq.sling;

import <all libs>

@SlingServlet(paths="/bin/myWordPress", methods = "GET", metatype=true)

public class HandleWordPress extends org.apache.sling.api.servlets.SlingAllMethodsServlet  

{

    

    /** Default log. */

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

    

    

    private ArrayList<String> posts ;

    

    

    @Override

     protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {

       

      try

      {

         //Your Code

        response.setContentType("text/html");

            response.getWriter().write(listString);

      }

      catch(Exception e)

      {

          e.printStackTrace();

      }

    }

    

}

Or you can use OSGi annotations.

-Kautuk



Kautuk Sahni

Avatar

Level 10

You have to make sure that the OSGi bundle (In which the servlet exists) - is in an Active State.

Avatar

Level 4

Hi Feike ,

Sorry for delay in reply.
I tried using OSGI annotations as well but still it is giving same issue(Resource at '/bin/customServlet' not found: No resource found).

I used the following code :

//import packages

/**

* Test Servlet

*/

@Component(service = Servlet.class,

property =

{ SLING_SERVLET_PATHS + "=/bin/customServlet",

  SLING_SERVLET_METHODS + "=GET",

})

public class Test extends SlingAllMethodsServlet {

    /**

*

*/

private static final long serialVersionUID = 1L;

protected static final Logger LOGGER = LoggerFactory.getLogger(Test.class);

    @Override

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

    LOGGER.info("ENTERED THE SERVLET");

    }

   

}

@kautuksahni  :
Thanks for the links.
I tried using felix SCR annotations as well instead of OSGI annotation(org.osgi.service.component.annotations),but still it is giving the error message -
Resource at '/bin/customServlet' not found: No resource found


I am not sure If I have to anything additionally.Please let me know.

Thanks,
Pallavi

Avatar

Employee

Can you build this project: GitHub - heervisscher/htl-examples: AEM HTL examples and compare?

What version do you have of this plugin?

                <plugin>

                    <groupId>org.apache.felix</groupId>

                    <artifactId>maven-bundle-plugin</artifactId>

                    <version>3.3.0</version>

                    <inherited>true</inherited>

                </plugin>