How to call activate method of Parent class

Avatar

Avatar

Ankur_Khare

MVP

Avatar

Ankur_Khare

MVP

Ankur_Khare
MVP

02-05-2019

Hi Team,

I am trying to extend OOB QRCodeGenerator servlet & here i am trying to initialize the parameters in activate method of OOB QRcodeGenerator Servlet whenever my custom servlet is called-

My Servlet-

@Component(service = Servlet.class, property = {"sling.servlet.paths=/bin/qrcode", "sling.servlet.extensions=png", "sling.servlet.methods=GET"})

@Designate(ocd = QRCodeGeneratorServlet.Configuration.class)

public class QRCodeGeneratorServlet extends QRCodeImageGenerator {

   protected void activate(Configuration config) {

        dataNameWhitelist = config.dataNameWhitelist();

    }

}

QRCodeGenerator Servlet-

@Component(metatype=true,

           label="AEM WCM QR-Code Generator Servlet",

           immediate=true)

@Service(value=Servlet.class)

@Properties( {

        @Property(name=Constants.SERVICE_DESCRIPTION,

                  value="QR Code Image Generator"),

        @Property(name="sling.servlet.paths",

                  value="/libs/wcm/mobile/qrcode",

                  propertyPrivate=true),

        @Property(name="sling.servlet.extensions",

                  value="png",

                  propertyPrivate=true),

        @Property(name="sling.servlet.methods",

                  value="GET",

                  propertyPrivate=true)

    } )

@SuppressWarnings("serial")

public class QRCodeImageGenerator extends AbstractImageServlet {

    protected void activate(ComponentContext componentContext) {

        Dictionary<String, Object> properties = componentContext.getProperties();

        dataNameWhitelist = OsgiUtil.toStringArray(properties.get(DATA_NAME_WHITELIST));

        if (externalizer != null) {

            author = externalizer.authorLink(null, "");

            publish = externalizer.publishLink(null, "");

        }

    }

}

Now here whenever i am calling my custom servlet -

These params are coming null-

        if (externalizer != null) {

            author = externalizer.authorLink(null, "");

            publish = externalizer.publishLink(null, "");

        }

author,publish & externalizer.

Is there any way by which we can initialize these params whenever my custom servlet is called?

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

942

Correct Reply

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

942

Correct Reply

1.0K
Jörg_Hoh
Employee

02-05-2019

Please don't inherit from product servlets. The fact, that this class is exported from the bundle, is problemtic, and with updated versions it will definitely go away. Typically the servlet classes are not exported to the classpath available by you, and the fact that it's done here, is an issue.

Answers (2)

Answers (2)

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

02-05-2019

Joerg is correct - you should not be using a Servlet like this.

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

02-05-2019

Are you trying to read OSGI config values?