Servet not getting resolved | Community
Skip to main content
pallavis8124480
Level 3
January 31, 2018
Solved

Servet not getting resolved

  • January 31, 2018
  • 11 replies
  • 3817 views

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

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 Feike_Visser1

Can you the OSGi annotations?

Example here: htl-examples/SimpleServlet.java at master · heervisscher/htl-examples · GitHub

11 replies

Feike_Visser1
Adobe Employee
Adobe Employee
January 31, 2018

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

pallavis8124480
Level 3
January 31, 2018

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.

Feike_Visser1
Adobe Employee
Adobe Employee
January 31, 2018

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

pallavis8124480
Level 3
January 31, 2018

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.

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
January 31, 2018
kautuk_sahni
Community Manager
Community Manager
January 31, 2018

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 using AJAX

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
smacdonald2008
Level 10
January 31, 2018

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

smacdonald2008
Level 10
January 31, 2018

TO see a Servlet work - so you can follow the steps - watch this video --

Scott's Digital Community: Submitting Adobe Experience Manager form data to custom Sling Servlets

pallavis8124480
Level 3
February 1, 2018

Yes the bundle is active

pallavis8124480
Level 3
February 2, 2018

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