Sunday, December 14, 2014

how to create the page through Java API in Adobe Experience Manager(AEM)

how to create the page through Java API in Adobe Experience Manager(AEM)

This post will explain how to create a page through Java API in Adobe Experience Manager(AEM)

Create the API service

This service create a sample page in Adobe Experience Manager(AEM).

import javax.jcr.Node;
import javax.jcr.Session;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.ComponentContext;

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;

@Component(immediate = true, label = "Create Page Service", description = "Create Sample Page", metatype = true)
@Service(value = CreateSamplePage.class )
public class CreateSamplePage   {

@Reference
private ResourceResolverFactory resolverFactory;
private ResourceResolver resourceResolver;
 
private void createPage() throws Exception {
String path="/content/poc";
String pageName="samplePage";
String pageTitle="Sample Page";
String template="/apps/geometrixx/templates/homepage";
String renderer="geometrixx/components/homepage";

this.resourceResolver = this.resolverFactory.getAdministrativeResourceResolver(null);
    Page prodPage = null;
    Session session = this.resourceResolver.adaptTo(Session.class);
    try {
    if (session != null) {

    // Create Page    
    PageManager pageManager = this.resourceResolver.adaptTo(PageManager.class);
    prodPage = pageManager.create(path, pageName, template, pageTitle);
    Node pageNode = prodPage.adaptTo(Node.class);

Node jcrNode = null;
if (prodPage.hasContent()) {
jcrNode = prodPage.getContentResource().adaptTo(Node.class);
} else {                
jcrNode = pageNode.addNode("jcr:content", "cq:PageContent");
}
          jcrNode.setProperty("sling:resourceType", renderer);
     
     
         Node parNode = jcrNode.addNode("par");
         parNode.setProperty("sling:resourceType", "foundation/components/parsys");

 Node textNode = parNode.addNode("text");
 textNode.setProperty("sling:resourceType", "foundation/components/text");
 textNode.setProperty("textIsRich", "true");
 textNode.setProperty("text", "Test page");

session.save();
        session.refresh(true);
 }
       
} catch (Exception e) {
throw e;

   }    
}






Saturday, December 13, 2014

java.net.ConnectException,Bootstrap to server failed while deploying the compoite - Orace SOA Suite

 java.net.ConnectException,Bootstrap to server failed while deploying the compoite - Orace SOA Suite

Sometimes we may receive the following exception while deploying the composite to Oracle SOA Suite server using even though the sever is running fine and reachable.

oracle.rc.asadapter.connection.ConnectionException
at oracle.rc.asadapter.weblogic.connection.spi.Weblogic10JndiProvider.getPresentation(Weblogic10JndiProvider.java:86)

Caused by: javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://127.0.0.1:8000: Bootstrap to localhost/127.0.0.1:8000 failed. It is likely that the remote side declared peer gone on this JVM]
at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:40)

Caused by: java.net.ConnectException: t3://127.0.0.1:8000: Bootstrap to localhost/127.0.0.1:8000 failed. It is likely that the remote side declared peer gone on this JVM

Caused by: java.rmi.ConnectException: Bootstrap to localhost/127.0.0.1:8000 failed. It is likely that the remote side declared peer gone on this JVM
at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:334)


This issue can be resolved by configuring valid machine IP or complete name of the machines, including the domain extension as listen address in weblogic server.



Thursday, December 11, 2014

Can not write to the specified destfile - Error while deploying through jenkins

Can not write to the specified destfile - Error while deploying through jenkins

Some times we may receive the following error "Can not write to the specified destfile"  while performing the deployment through Jenkins.


The error is due to the user running the Jenkins(the user installed the Jenkins) is not having the permission to write the content to the specified file.

To fix the issue make the owner of the file/folder to the user running the Jenkins

chown -R jenkins:jenkins hybris

Provide the required permission to the file/folder

chmod 777



Tuesday, December 9, 2014

Implementing Internationalization with i18n in Adobe CQ5

Implementing Internationalization with i18n in Adobe CQ5

This post will explain how to implement Internationalization with i18n in Adobe CQ5

Configuring i18 keys:

Create a sling:folder i18n inside apps or apps/<<application>> or inside the components folder based on the scope. e.g. /apps/i18n or apps/myapp/i18n or apps/myapp/global/components/mycomponent/i18n


Create a folder for each language inside 118n folder
Assign mixin to the language folders created in the previous step (e.g. en, ar etc) from crx console mix:language
For the language nodes (e.g. en, ar etc) add String property jcr: language, value = ISO language code (en, es etc)

Create nodes of type sling:MessageEntry for each field label
Add 2 properties sling:key = <keyname> and sling:message = <message>


Save all the changes

Using the i18n keys in JSP:

<%@page session="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@page import="java.util.Locale,java.util.ResourceBundle,com.day.cq.i18n.I18n"%>
<%@include file="/libs/foundation/global.jsp"%>
<cq:setContentBundle/>
<%
final Locale pageLocale = currentPage.getLanguage(false);
final ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLocale);
I18n i18n = new I18n(resourceBundle);
%>
<%= i18n.get("cartItem") %>


Thursday, December 4, 2014

how to Invoke the SOAP services from Adobe CQ5

how to Invoke the SOAP services from Adobe CQ5

This post will explain how to invoke the SOAP services from Adobe CQ5

Configure wsimport  plugin to POM.xml:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxws-maven-plugin</artifactId>
   <version>1.12</version>
   <executions>
      <execution>
         <goals>
            <goal>wsimport</goal>
         </goals>
      </execution>
   </executions>
   <configuration>
      <verbose>true</verbose>
      <args>
         <arg>-B-XautoNameResolution</arg>
      </args>
      <wsdlUrls>
         <wsdlUrl>http://localhost:8080/services/AddressService_1.0.wsdl</wsdlUrl>
      </wsdlUrls>
      <sourceDestDir>src/main/java/</sourceDestDir>
      <packageName>com.ws.address.validation</packageName>
   </configuration>
</plugin>

Change the wsdlurl,sourceDestDir and packageName accordingly.