custom wcmcommand | Community
Skip to main content
New Participant
October 16, 2015
Solved

custom wcmcommand

  • October 16, 2015
  • 3 replies
  • 2108 views

I have a class RequestCommand implementing WCMCommand (com.day.cq.wcm.api.commands.WCMCommand).

When trying to implement the performCommand method, the return type (org.apache.sling.api.servlets.HtmlResponse) is deprecated and when I try to update it to the preferred type (org.apache.sling.servlets.post.HtmlResponse) shows the error "The return type is incompatible with WCMCommand.performCommand(WCMCommandContext, SlingHttpServletRequest, SlingHttpServletResponse, PageManager)"

I know I can probably use the deprecated class for now, but is there another way to do what I'm looking for potentially? 

Thanks

... public class RequestCommand implements WCMCommand { public String getCommandName() { return "requestPage"; } public HtmlResponse performCommand(WCMCommandContext commandContext, SlingHttpServletRequest request, SlingHttpServletResponse response, PageManager pageManager) { ...
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 joerghoh

Hi,

Well, you can use it as you like. But as you already found out, the product itself is using deprecated classes :-)

I would rather implement the servlets in your own namespace (/bin/myapp/doSomething). But binding servlets to a path (like /bin/wcmcommand) isn't the way servlets are supposed to work. In most (all?) cases you have a resource you want to modify. And in that case it makes sense to bind such a modification command as a selector to a specific resource type. See [1] as a good reference, plus it lists the pro's quite well.

Jörg

 

[1] http://stackoverflow.com/questions/22949317/cq5-5-accessing-a-referring-resource-in-a-osgi-servlet

3 replies

joerghoh
Employee
October 16, 2015

Hi,

why do you want to implement the WCMCommand interface? When you want to implement server-side functionality you can call from your Javascript, you can use a simple servlet. No need to implement the WCMCommand interface.

Jörg

BenSt10Author
New Participant
October 16, 2015

My main thinking was to try to keep as much code in this project's maven bundle as possible. I already have an interface built to manage these pages (marking them as trash/untrash, commenting, updating statuses). I was following the lead of the lock/unlock actions (/libs/cq/gui/components/authoring/clientlibs/editor/js/actions/lockMode.js).

Can you point me in the direction of what you're suggesting re:using a servlet?

joerghoh
joerghohAccepted solution
Employee
October 16, 2015

Hi,

Well, you can use it as you like. But as you already found out, the product itself is using deprecated classes :-)

I would rather implement the servlets in your own namespace (/bin/myapp/doSomething). But binding servlets to a path (like /bin/wcmcommand) isn't the way servlets are supposed to work. In most (all?) cases you have a resource you want to modify. And in that case it makes sense to bind such a modification command as a selector to a specific resource type. See [1] as a good reference, plus it lists the pro's quite well.

Jörg

 

[1] http://stackoverflow.com/questions/22949317/cq5-5-accessing-a-referring-resource-in-a-osgi-servlet