Tuesday 21 November 2017

How to send back the JSON object response from a servlet??

jsonobjj is the Json Object that is sent in the response. flush() sends the binary output stream.

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.print(jsonobjj);
out.flush();

What is the difference between JSON.parse and JSON.stringify??

JSON.parse - Converts a string of JSON text into a javascript object.

JSON.stringify - Converts a javascript object into JSON text and stores that JSON text in a string.

Thursday 16 November 2017

How to call a servlet in the js??

At times we come across a requirement where we have to call a servlet in our js file. This can be achieved as shown below::

var value;
$.get('/bin/testservlet', function(data) {console.log('test',data);
                                                    value=data});

/bin/testservlet= This is the path property set in the servlet. The request looks for the servlet that has this path property set.

data=contains the response sent back from the servlet. The response returned can then be used for the needed logic.

In this example the get method is executed.

Monday 13 November 2017

How to fetch the configuration in aem cq

The Osgi configurations can be fetched programmatically to be consumed in any service.

Configuration node can be created by creating a node of Type sling:OsgiConfig.

The Osgi configurations can be accessed from http://localhost:4502/system/console/configMgr.

The following code uses ConfigurationAdmin to fetch the config.

@Reference

private ConfigurationAdmin configAdmin;

Configuration cnf=configAdmin.getConfiguration("<name-of-the-Confignode-created>");
 Dictionary<String, Object>str=cnf.getProperties(); //To get the properties stored at that node.
String val=str.get("<property-name>"); //To get the specific propert by name



Saturday 11 November 2017

What's new in AEM 6.3?

As we know that in this digital era portability is in demand. Every business associate have to be in touch with their business on the go. So to make AEM more compatible with palm devices(mobile /tablet) the drift is towards touch ui aspect of experience manager.

There are few changes to the way services, workflows are handled. SCR annotations (org.apache.felix.scr.annotations.*) are replaced by OSGi annotations(org.osgi.service.component.annotations.*).

The release notes for AEM 6.3 is available at
https://helpx.adobe.com/experience-manager/6-3/release-notes.html

Osgi Component and Service

@Component(name=”Demo Service” service=DemoService.class,immediate=true)
public class DemoService {
                     public String getValue()
  {
   return "DemoService";
  }
}

Implementing Servlets


@Component(service=Servlet.class,
          property={
                  Constants.SERVICE_DESCRIPTION + "=Demo Servlet",
                  "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                  "sling.servlet.resourceTypes="+ "com.demo.osgiannotation/components/structure/page",
                 "sling.servlet.paths="+ "/bin/servlet",
                  "sling.servlet.extensions=" + "txt"
          })
public class DemoServlet extends SlingSafeMethodsServlet {
{
@Override
  protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)throws IOException
  {
      response.getWriter().print("This get method is from the servlet");
  }
}


Implementing Workflow Process Step

@Component(service = WorkflowProcess.class, property = {"process.label=Activate Page" })
public class DemoWorkflow implements WorkflowProcess {
public void execute(WorkItem workitem, WorkflowSession wfsession,MetaDataMap metaDataMap)
{
log.info(“This execute method is from Workflow”);
}
}


extraClientlibs Usage

The purpose of property "extraClientlibs" is to selectively load client library for a dialog. This prevents the unnecessary load o...