Tuesday, December 30, 2014

Building a executable JAR file with external libraries through JDeveloper

This post explain the different approaches to build the executable JAR file with external libraries through JDeveloper.

Referring the external libraries from JAR:

Right Click project and select properties
Click on Deployment and create new JAR deployment profile.
Select "Include Manifest File" option.
Select the main class.



Create a manifest file(any location) and add the required jar files to the Class-Path header

Class-Path.mf

Class-Path: json.jar log4j.jar

 End the Class-Path.mf file by a carriage return.


Add the Class-Path.mf file to Additional Manifest Files to Merge into Manifest.mf


Then right click on project select the profile created under deploy. Select Deploy to JAR File.
Click finish.

META-INF\MAIFEST.MF file in the generated file will have the Main-Class and Class-Path headers defined.



Executing the jar:

Place the dependent jars to the same folder where the jar file generated in the previous step exists.


java -jar TokenizerService.jar


Including the content of external libraries to JAR:

Right Click project and select properties
Click on Deployment and create new JAR deployment profile.
Select "Include Manifest File" option.
Select the main class.
Create New File Group of type Dependency Analysis


Select the Contributors under new file group you have created
Select the Libraries Tab.
Select the required libraries  and select the default option "Include Contents in Output".


Then right click on project select the profile created under deploy. Select Deploy to JAR File.
Click finish.
The content of the json.jar file will be included into the generated jar.



Executing the jar:

java -jar TokenizerService.jar



Saturday, December 20, 2014

Encrypting/Decrypting data in Adobe CQ5

com.adobe.granite.crypto.CryptoSupport service can be used to encrypt/decrypt the data in Adobe CQ5.

Add the below dependency in POM.xml

<dependency>
  <groupId>com.adobe.granite</groupId>
        <artifactId>com.adobe.granite.crypto</artifactId>
         <version>0.0.18</version>
         <scope>provided</scope>
 </dependency>

Service to encrypt/decrypt the message:

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.CryptoSupport;

@Component(immediate = true, metatype = true)
@Service(value = EncrypionService.class)
public class EncrypionService {
@Reference
private CryptoSupport cryptoSupport;

public String encrypt(String plainText) throws Exception
{
try {
return cryptoSupport.protect(plainText);
} catch (CryptoException e) {
throw e;
}
}

public String decrypt(String encryptedText) throws Exception
{
try {
return cryptoSupport.unprotect(encryptedText);
} catch (CryptoException e) {
throw e;
}
}
}




org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.LinkageError: loader constraint violation - Adobe CQ5

Sometimes we may receive the following exception while invoking the Adobe CQ5 services.

20.12.2014 11:15:31.816 *ERROR* [0:0:0:0:0:0:0:1 [1419054331815] GET /services/EmailServlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.LinkageError: loader consaint violation: when resolving interface method "com..commerce.connector.CommerceService.getSession(Ljavax/servlet/http/HttpServleequest;Ljavax/servlet/http/HttpServleesponse;)Lcom//commerce/connector/session/CommerceSession;" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, com///servlet/EmailServlet, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for resolved class, com//commerce/connector/CommerceService, have different Class objects for the type connector.CommerceService.getSession(Ljavax/servlet/http/HttpServleequest;Ljavax/servlet/http/HttpServleesponse;)Lcom//commerce/connector/session/CommerceSession; used in the signature
at com...servlet.EmailServlet.doPost(EmailServlet.java:67)
at com...servlet.EmailServlet.doGet(EmailServlet.java:56)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:268)
at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:139)

This error will be thrown while invoking the service of one bundle from another bundle.

To fix this issue, make sure the required packages from the target bundle is imported to the source bundle.





Thursday, December 18, 2014

org.apache.sling.security.impl.ReferrerFilter Rejected empty referrer header for POST request - Adobe CQ5

We will receive the following exception while testing the Adobe  CQ5 POST Servlets from Restclient.


15.12.2014 22:55:01.434 *INFO* [0:0:0:0:0:0:0:1 [1418664301434] POST /services/EmailServlet HTTP/1.1] org.apache.sling.security.impl.ReferrerFilter Rejected empty 
referrer header for POST request to /services/EmailServlet

This error is is due to the Apache Sling Referrer Filter will not allow empty Referer address by default.

For testing purpose, we can allow empty referrer by changing the Apache Sling Referrer Filter.

Go to the Felix Console - http://localhost:4502/system/console/configMgr
Search for "Apache Sling Referrer Filter"
Select "Allow Empty"


This should be only enabled for testing purpose in dev environment.




Wednesday, December 17, 2014

Sending mail through Java API with Gmail server – Adobe CQ5

This post will explain the steps required to send mail in Adobe CQ5 through Java API with Gmail server.

Configure mail service:

Go to the Felix Console - http://localhost:4502/system/console/configMgr
Search for Day CQ Mail Service
Enter the Gmail server details as shown below and Save the data.

SMTP Server Host   - smtp.gmail.com
SMTP Server Port    - 465
SMTP User              - your gmail username
SMTP Password      - your password
From Address          - your email
SMTP Use SSL      - true


You may need to enable the access for less secure apps in google account - https://www.google.com/settings/security/lesssecureapps

Email Template:

Create the email template as text file and store it in repository - /etc/email/template/emailTemplate.txt (change the path accordingly)


Create the Email servlet:

Create a servlet to send the email with the provides details.

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.jcr.Node;
import javax.jcr.Session;
import javax.mail.internet.InternetAddress;
import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.commons.mail.HtmlEmail;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.mailer.MessageGateway;
import com.day.cq.mailer.MessageGatewayService;

@SuppressWarnings({ "serial" })
@Component(metatype = false)
@SlingServlet(name = "EmailServlet", description = "EmailServlet", methods = "POST", generateComponent =false, paths = "/services/EmailServlet")
@Service(Servlet.class)
public class EmailServlet extends SlingAllMethodsServlet {

       private static final Logger LOG = LoggerFactory.getLogger(EmailServlet.class);

       @Reference
       private MessageGatewayService messageGatewayService;
       @Reference
       public SlingRepository repository;

       @Override
       protected void doGet(SlingHttpServletRequest request,
                     SlingHttpServletResponse response) throws ServletException,
                     IOException {
              doPost(request, response);
       }
   
       @Override
       protected void doPost(SlingHttpServletRequest request,
                     SlingHttpServletResponse response) throws ServletException,
                     IOException {
              String results = sendEmail(request);
              if (results != null && results.equalsIgnoreCase("success")) {
                     response.getWriter().write("success");
              } else {
                     response.getWriter().write("fail");
              }          
       }  

       public String sendEmail(SlingHttpServletRequest request) {

              ArrayList<InternetAddress> emailRecipients = new ArrayList<InternetAddress>();
              Session session = null;
              String results = "Success";
              String fromAddress=request.getParameter("fromAddress");
              String toAddress=request.getParameter("toAddress");
           
              String firstName=request.getParameter("firstName");
              String lastName=request.getParameter("lastName");
           
              String templateLink=request.getParameter("templateLink");
           
              try {
                     session = repository.loginAdministrative(null);
                     String templateReference = templateLink.substring(1)+ "/jcr:content";

                     Node root = session.getRootNode();
                     Node jcrContent = root.getNode(templateReference);
                     InputStream is = jcrContent.getProperty("jcr:data").getBinary().getStream();

                     BufferedInputStream bis = new BufferedInputStream(is);
                     ByteArrayOutputStream buf = new ByteArrayOutputStream();
                     int resultNumber = bis.read();
                     while (resultNumber != -1) {
                           byte b = (byte) resultNumber;
                           buf.write(b);
                           resultNumber = bis.read();
                     }                

                     String bufString = buf.toString();
                     LOG.info("template.."+bufString);
                     bufString = bufString.replace("${firstName}", firstName);
                     bufString = bufString.replace("${lastName}", lastName);
                     LOG.info("mesage.."+bufString);
                     HtmlEmail email = new HtmlEmail();
                 
                     emailRecipients.add(new InternetAddress(toAddress));
                     email.setCharset("UTF-8");
                     email.setFrom(fromAddress);
                     email.setTo(emailRecipients);
                     email.setSubject("This is the test mail");
                     email.setHtmlMsg(bufString);
                     MessageGateway<HtmlEmail> messageGateway = this.messageGatewayService.getGateway(HtmlEmail.class);
                     messageGateway.send(email);
                     emailRecipients.clear();                    
                 
              } catch (Exception e) {
                     results = "fail";
                     LOG.info("e.getMessage"+e.getMessage());
                     e.printStackTrace();
              } finally {
                     if(session != null) {
                           session.logout();
                     }
              }
              return results;
       }
}

The email can be send now by invoking the servlet with required details.

fromAddress=albinsharp@gmail.com
toAddress=albin.issac@tcs.com
firstName=Albin
lastName=Issac
templateLink=/etc/email/template/emailTemplate.txt



Sunday, December 14, 2014

Programmatically create a page in Adobe CQ5

This post will explain how to create a page programmatically in Adobe CQ5

Create the service to create the page.

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

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.


On client side,  enter the host entry for the server in the hosts file -C:\Windows\System32\drivers\etc





Thursday, December 11, 2014

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

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

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

Invoking the SOAP services from Adobe CQ5

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

Add the  wsimport  plug in to the 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.


Execute the generate-source target


This will generate the java code to the specified path.


Invoke the service :

AddressServiceV01_Service service = new AddressServiceV01_Service();
AddressServiceV01 port = service.getAddressServiceV01();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put("http://localhost:8080/services/AddressService");
String response = port.method(input);

Change the service and the endpoint accordingly.

Add com.sun.xml.internal.ws.* to sling.properties org.osgi.framework.bootdelegation property.

org.osgi.framework.bootdelegation=com.yourkit.*, ${org.apache.sling.launcher.bootdelegation}, com.sun.xml.internal.ws.*



Saturday, November 29, 2014

User name and password do not match error while accessing CRXDE - Adobe CQ5

Sometimes we may receive User name and password do not match error while accessing the CRXDE and also Authentication Failed error while accessing the Adobe CQ5 configMgr.




We will be receiving this error if the anonymous user account is deleted accidentally.
This can be fixed by restarting the repository, anonymous user account will be re-created upon repository restart.



Wednesday, November 12, 2014

Enabling SSL in Dispatcher with self signed certificate - Adobe CQ5

This post will explain how to Enabling SSL in Dispatcher with self signed certificate in Adobe CQ5

Generating Self signed certificate:

Create a folder ssl under /etc/httpd/ directory.
Generate server.key and server.crt file by running the following command:

openssl req -new -x509 -sha1 -newkey rsa:1024 \
-nodes -keyout /etc/httpd/ssl/server.key -out /etc/httpd/ssl/server.crt \
-subj '/O=<Organization>/OU=<Department>/CN= <Common Name>'

Change the <Organization>, <Department> and <Common Name> accordingly.

Install mod_ssl.so by running the following command
yum install mod_ssl

Modify the VirtualHost in /etc/httpd/conf.d/ssl.conf file with the host name.

<VirtualHost test.server.com:443>

Also, specify the server certificate and key path in the below properties.

SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key

Restart the Apache HTTP Server,now we can able to access the urls through https.



Configuring SAML SSO for Adobe CQ5

Configuring SAML SSO for Adobe CQ5

Navigate to the web console: http://HOST:4502/system/console/configMgr

Expand Apache Sling Referrer Filter

Add the SAML SSO server host name to the Allowed Hosts section (depending on the authoring environment you are configuring), Check the Allow Empty checkbox and Click Save.


Expand Adobe Granite SAML 2.0 Authentication Handler

Configured the required details for authentication

    Path
    /
    Service Ranking
    5002
    IPD URL
    IDP HTTP Redirect
    Unchecked - Use an HTTP Redirect to the IDP URL instead of sending an AuthnRequest-message to request credential
    Service Provider Entity ID
    Default Redirect
    /
    User ID Attribute
    UserID - The name of the attribute containing the user ID used to authenticate and create the user in the CRX repository
    Use Encryption
    Unchecked - Whether or not this authentication handler expects encrypted SAML assertions
    Autocreate CRX Users
    Unchecked - Whether or not to autocreate nonexisting users in the repository
    Add to Groups
    Unchecked - Whether or not a user should be autmatically added to CRX groups after successful authentication
    Group Membership
    <empty--no value> - The name of the attribute containing a list of CRX groups this user should be added to
    NameIDPolicy Format
    urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified - The value of the NameIDPolicy format parameter to send in the AuthnRequest message.



Click Save

Add the SAML certificate:
Log into the Authoring server using ssh .
Create a file called /tmp/idp.pem on the Authoring server, and paste the contents of certificate into the file. Save the file.
e.g.
-----BEGIN CERTIFICATE-----
v0+H34mZVykVp1QmXs6r6xPppTMZ6YbGs8l+RfmMy4pAFphTimiQz/y/eWJCpvo7
Hg+VqF/9Kong61W9ogDbkAsCzWoyQyE1OkzqjLM19N6QDmbGheUQMS70bhiPEagz
…….
-----END CERTIFICATE-----

Run this command to push the certificate into AEM, replacing PASSWORD with the admin password:
curl -u admin:PASSWORD -F idp_cert=\<idp.pem -F idp_cert@TypeHint=Binary http://localhost:4502/etc/key/saml

Browse to the AEM server (http://HOST:4502/)and you should be redirected to SSO server for authentication and send to AEM screen upon successful authentication(http://HOST:4502/)).



Monday, November 10, 2014

Referencing the services between OSGI bundles – AEM

This post explains how to refer the services between OSGI bundles in Adobe Experience Manager.

Export-Package
Bundles may export zero or more packages from the JAR to be consumable by other bundles. The export list is a comma-separated list of fully-qualified packages, often with a version attribute. If not specified, the version defaults so 0.0.0.


In the target bundle the packages contains the required services and the classes exposed to the other bundles should be exported.


Import-Package 
The Import-Package header is used to declare dependencies at a package level from the bundle. At runtime, the bundle will be wired up with whatever (compatible) bundle offers the package.

In the source bundle the packages contains the required services and classes referred from other bundle should be imported.

The following two approaches can be used to refer the services from other bundle.
Through Reference
@Reference
private CommerceServiceFactory sFactory;

Through bundle context
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
CommerceServiceImpl factoryFromBundle=(CommerceServiceImpl)bundleContext.getService(bundleContext.getServiceReference(CommerceServiceFactory.class)).getCommerceService();



Thursday, September 25, 2014

Not able to create the session in OSB console - Could not create directory /osb/config/sessions/weblogic

Sometimes we may receive the error "could not create directory <DOMAIN_HOME>/osb/config/sessions/weblogic" in the OSB console while trying to create the session.



There will be a multiple reason for this issue, in our case the root cause of the exception is the space is full for the mount  point



To resolve the issue add extra space to the mount point or clear some of the unwanted files and make the required space.



Monday, September 22, 2014

XML-22036: (Error) Cannot convert result tree fragment to NodeSet - Oracle SOA Suite 11g

We are getting the below exception in runtime while passing the parameter and accessing the same from XSLT in Oracle SOA Suite.




The following exception occurred while attempting to execute operation copy at line 139
-<exception class="com.collaxa.cube.xml.xpath.XPathException">
-<parsererror style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black">
<h3>This page contains the following errors:</h3>
<div style="font-family:monospace;font-size:12px">
error on line 7 at column 1: Extra content at the end of the document
</div>
<h3>Below is a rendering of the page up to the first error.</h3>
</parsererror>
XPath expression failed to execute.
An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc('xsl/DistinctPayload.xsl', $inputVariableLocal.payload, 'FlowSubscriberVar2', $FlowSubscriberVar2).
The XPath expression failed to execute; the reason was: javax.xml.transform.TransformerException: oramds:/deployed-composites/default/PPDSOM_EventManager_rev1.0/xsl/DistinctPayload.xsl<Line 8, Column 82>: XML-22036: (Error) Cannot convert result tree fragment to NodeSet..
Check the detailed root cause described in the exception message text and verify that the XPath query is correct.
-<stack>
<f>com.collaxa.cube.xml.xpath.BPELXPathUtil.evaluate#262</f>
<f>com.collaxa.cube.engine.ext.bpel.common.BPELWMPHelper.evalFromValue#339</f>
<f>com.collaxa.cube.engine.ext.bpel.v1.wmp.BPEL1AssignWMP.__executeStatements#137</f>
<f>com.collaxa.cube.engine.ext.bpel.common.wmp.BaseBPELActivityWMP.perform#158</f>
<f>com.collaxa.cube.engine.CubeEngine.performActivity#2543</f>
<f>com.collaxa.cube.engine.CubeEngine._handleWorkItem#1165</f>
<f>com.collaxa.cube.engine.CubeEngine.handleWorkItem#1071</f>
<f>com.collaxa.cube.engine.dispatch.message.instance.PerformMessageHandler.handleLocal#73</f>
<f>com.collaxa.cube.engine.dispatch.DispatchHelper.handleLocalMessage#220</f>
<f>com.collaxa.cube.engine.dispatch.DispatchHelper.sendMemory#328</f>
<f>com.collaxa.cube.engine.CubeEngine.endRequest#4430</f>
<f>com.collaxa.cube.engine.CubeEngine.endRequest#4361</f>
<f>com.collaxa.cube.engine.CubeEngine._createAndInvoke#698</f>
<f>com.collaxa.cube.engine.CubeEngine.createAndInvoke#555</f>
<f>com.collaxa.cube.engine.delivery.DeliveryService.handleInvoke#673</f>
<f>com.collaxa.cube.engine.ejb.impl.CubeDeliveryBean.handleInvoke#293</f>
<f>...</f>
</stack>
</exception>

The actual issue is, the xsl:param name in the XSLT is different from the parameter name send from BPEL.




The issue got resolved after changing the xsl:param in XSLT as same as the parameter name in Oracle BPEL.





Wednesday, September 17, 2014

SCAC-50012 - Oracle SOA Suite 11g

This error will occur most of time compiling the Oracle BPEL component in Oracle SOA Suite with java embedded activity, If there is any issue with the java code this exception will be thrown.

We were facing the SCAC-50012 exception with the following code.

String orderID  =  ((oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload",'/client:process/client:input')).getFirstChild().getNodeValue();
String Title=("OrderID: " +orderID);                                        
setCompositeInstanceTitle(Title);

The actual  issue with the XPATH expression specified within the single quote(copy paste issue), the compilation became successful after converting the single quotes to double quotes.

String orderID  =  ((oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload","/client:process/client:input")).getFirstChild().getNodeValue();
String Title=("OrderID: " +orderID);                                        
setCompositeInstanceTitle(Title);



Monday, September 1, 2014

Dynamic Endpoint Implementation through DB Table –Oracle SOA Suite

The below document explain the approach to store change the endpoints of the service dynamically in Oracle SOA Suite.



Download Load_Balancer_Probe_SOA-INFRA.pdf



Friday, August 29, 2014

Programmatically creating Nodes in Adobe CQ

We can programmatically create the nodes in Adobe CQ5 , the below code snippet will help us to create the nodes in Adobe CQ5.

private static final String BASE_PATH = "/etc/commerce/products"; // the folder under which the nodes should be created

//Get the Resource resolver from request - Creating the node through Servlet
ResourceResolver resolver = request.getResourceResolver();

//Get the Resource resolver through resolver factory - Creating the node through Service
@Reference
private ResourceResolverFactory resolverFactory;//Get the resolverFactory reference in the service

ResourceResolver resolver = resolverFactory.getAdministrativeResourceResolver(null);//Get the resolver

//Get the session
Session session = resolver.adaptTo(Session.class);

//Create the Node
Node node = JcrUtil.createPath(BASE_PATH+<<Node Name>>, JcrConstants.NT_UNSTRUCTURED, session);

//Set the required properties
node.setProperty("name", "sample");
node.setProperty("description", "sample");

//Save the session
session.save();

While creating the NT_UNSTRUCTURED node make sure the parent folder is sling:folder, the node will not be created if the parent node is of type nt::folder.




Friday, July 25, 2014

Handling Parallel events through OnEvent event handlers – Oracle SOA Suite

This post will explain, how to handle Parallel events through OnEvent event handlers in Oracle SOA Suite 11g



Download Handling_Parallel_events_ OnEvent_event_handlers_V1.pdf



Thursday, July 24, 2014

Cipher not initialized exception while invoking the Salesforce service through OSB

We are getting the "Cipher not initialized" exception wile invoking the Salesforce services through OSB.


We are able to invoke the login.salesforce.com URL successfully and able to receive the session id, also this exception was thrown only for a particular sandbox but the all other sandbox invocation is successful.

The "Cipher not initialized" exception will be thrown when there is no common Ciphers available between the client and server while negotiating the SSL communication.

We have raised a case with Salesforce regarding this and receive the response as "We recently upgraded our Cipher suites for SSL. To resolve the issue upgrade latest version of Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files- 6 for JDK1.6 on middleware."

After upgrading the Unlimited Strength Jurisdiction Policy Files in all the servers nodes we are able to invoke the service successfully.

Follow the below steps to resolve the issue

  • Download the Unlimited Strength Jurisdiction Policy Files from http://www.oracle.com/technetwork/java/javase/downloads/index.html(Under Additional Resources" section), for java 1.6 use http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
  • Unzip the downloaded zip 
  • Copy local_policy.jar and US_export_policy.jar to the $JAVA_HOME/jre/lib/security in all the OSB nodes.
  • Restarts the servers.
Now you will be able to invoke the service successfully.



Thursday, July 10, 2014

Integrating Adobe CQ5 with REST services

The below document explains the approach to integrate Adobe CQ5 with REST services.



Download Integrating_CQ5_with_RESTServices.pdf



Saturday, July 5, 2014

java.io.IOException: Server returned HTTP response code: 400 - While invoking the Salesforce login url from java to get the access token

I was getting the below exception while invoking the Salesforce login url to get the OAuth access_token from java.

java.io.IOException: Server returned HTTP response code: 400 for URL: https://login.salesforce.com/services/oauth2/token
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at RestCaller.execute(RestCaller.java:46)
at RestCaller.main(RestCaller.java:10)

This exception will happen normally when the values of client_id, client_security, username and password are not specified correctly while invoking the login url - https://login.salesforce.com/services/oauth2/token to get the OAuth access token.

"grant_type=password&client_id=13MVG9Y6d_xxxxxxx&client_secret=8039xxxxx&username=albinsharpxxxxx&password=Albinxxxx"

In my case, I have specified all the values properly but still it was not working, it worked after resetting the password and getting the new security token - password(password+security token)



Calling Salesforce REST based webservice from Java

This post will explain the approach to call the Salesfore REST based webservice through java.
I have exposed a Apex class as REST service from salesforce to fetch the account details.

@RestResource(urlMapping='/AccountDetails/*')
global with sharing class AccountDetails {

    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        System.debug('Account Id:'+accountId);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        return result;
    }
}

The communication is of two steps

  •  getting the access_token 
  •  invoking the service endpoint by attaching the access_token to the request.

To obtain an access token, we will send an HTTP POST request to the authentication endpoint exposed by Salesforce - https://login.salesforce.com/services/oauth2/token  with the details client_id, client_secret, username and password.This values can be get from the configured Connected Apps from salesforce.



import java.io.*;
import java.net.*;
import org.w3c.dom.*;

public class RestCaller {
public static void main(String[] args) throws Exception {

String urlParameters = "grant_type=password&client_id=3MVG9Y6d_xxxxxxxx&client_secret=80xxxxxxxx&username=albinsharpxxxxx&password=xxxxxxxxx";

String loginresponse = RestCaller.execute(
"https://login.salesforce.com/services/oauth2/token", "POST",urlParameters, "application/x-www-form-urlencoded", null);
String sessionId=getSessionId(loginresponse);
String serviceResponse =RestCaller.execute("https://ap1.salesforce.com/services/apexrest/AccountDetails","GET","0019000000AZBCNAA5","application/xml",sessionId);
System.out.println("Service Response \n" + serviceResponse);
}

public static String execute(String targetURL, String HttpMethod,
String urlParameters, String contentType, String SessionId) {
URL url;
HttpURLConnection connection = null;
try {
url = new URL(targetURL);
if (HttpMethod == "GET") {
url = new URL(url.toString() + "/" + urlParameters);
}
connection = (HttpURLConnection) url.openConnection();
if (SessionId != null)
connection.setRequestProperty("Authorization", "OAuth "+ SessionId);
connection.setRequestProperty("accept", "application/xml");
if (HttpMethod == "POST") {
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length","" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Type", contentType);
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(urlParameters);
writer.flush();
writer.close();
os.close();
}

InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
return response.toString();
} catch (Exception e) {
e.printStackTrace();
return (e.getClass().getName());
}

finally {
if (connection != null) {
connection.disconnect();
}
}

}

static String getSessionId(String loingResponse)
{
   java.io.InputStream sbis = new java.io.StringBufferInputStream(loingResponse.toString());
       javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance();
       b.setNamespaceAware(false);
       org.w3c.dom.Document doc = null;
       javax.xml.parsers.DocumentBuilder db = null;
       try {
           db = b.newDocumentBuilder();
           doc = db.parse(sbis);
       } catch (Exception e) {
           e.printStackTrace();
       }  
       org.w3c.dom.Element element = doc.getDocumentElement();
       String access_token="";
       NodeList nodeList = element.getElementsByTagName("access_token");
       if(nodeList!=null && nodeList.getLength() > 0){
        Element myElement = (Element)nodeList.item(0);
        access_token= myElement.getFirstChild().getNodeValue();
       }
       return access_token;
}
}

O/P
<?xml version="1.0" encoding="UTF-8"?>
<response xsi:type="sObject" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<type>Account</type>
<Id>0019000000AZBCNAA5</Id>
<Name>GenePoint</Name>
<Phone>(650) 867-3450</Phone>
<Website>www.genepoint.com</Website>
</response>



Friday, July 4, 2014

Ignoring the Host Name verification while invoking the HTTPS service through HttpsURLConnection

Sometimes you may receive the Host Name mismatch exception while invoking the HTTPS service from the Java client even though the valid certificate is installed to the key store.

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching <Host Name> found

The root cause of the exception is the CN name of the certificate is not matching with the host name used to connect the service.

In real scenario while the certificate is signed with third party certificate authority , the CN name will be specified as the host name of the server where the service is hosted or wildcard name will be specified e.g *.example.com to represent all sub domains in a domain. So there will not be any issue while connecting to the service.

This mismatch exception will happen most of the time communicating with self signed certificate, the certificate is signed with CN name that is not matching with the host name.

To resolve the issue, the certificate should be signed with proper CN name or we can create a custom host name verifier to customize the host name verification functionality.

We have to return true from the custom host name verifier for the host name for which the CN name is mismatching.This will connect to the service irrespective of the host name used .

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;

public class HTTPCaller {
static {
   javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
   new javax.net.ssl.HostnameVerifier(){
       public boolean verify(String hostname,
               javax.net.ssl.SSLSession sslSession) {
           if (hostname.equals("localhost")) {
               return true;
           }
           return false;
       }
   });
}

    public static String execute() {
        String targetURL="https://localhost/test"
        URL url;
        HttpURLConnection connection = null;
        try {
            url = new URL(targetURL);
            url = new URL(url.toString());              

            connection = (HttpURLConnection)url.openConnection();
            connection.setRequestProperty("accept", "application/xml"); //for GET service to return xml payload

            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            System.out.println("\n Received response" + System.currentTimeMillis());

            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();
            return response.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return (e.getClass().getName()+":"+e.getMessage().toString());
        }
        finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }




Thursday, July 3, 2014

ORABPEL-05250 Error - JDeveloper Part2

I was facing a strange issue while deploying the composite to the server but The composite was successfully build in JDeveloper but during deployment to the server received the following exception.

[02:02:37 PM] Sending archive - sca_SuppressSelectionFailure_rev1.0.jar
[02:02:49 PM] Received HTTP response from the server, response code=500
[02:02:49 PM] Error deploying archive sca_SuppressSelectionFailure_rev1.0.jar to partition "default" on server AdminServer [http://inkaban3ua-eai05:8000]
[02:02:49 PM] HTTP error code returned [500]
[02:02:49 PM] Error message from server:
There was an error deploying the composite on AdminServer: Error occurred during deployment of component: SuppressSelectionFailure to service engine: implementation.bpel, for composite: SuppressSelectionFailure: ORABPEL-05250

Error deploying BPEL suitcase.
error while attempting to deploy the BPEL component file "/fmw/config/admin/domains/SOACoreDomain/servers/AdminServer/dc/soa_1b6f358e-8947-4572-a573-e036770c0591"; the exception reported is: java.lang.Exception: BPEL 1.1 compilation failed

This error contained an exception thrown by the underlying deployment module.
Verify the exception trace in the log (with logging level set to debug mode).
.

[02:02:49 PM] Check server log for more details.
[02:02:49 PM] Error deploying archive sca_SuppressSelectionFailure_rev1.0.jar to partition "default" on server AdminServer [http://localhost:8000]
[02:02:49 PM] ####  Deployment incomplete.  ####
[02:02:49 PM] Error deploying archive file:/C:/JDeveloper/mywork/Application1/SuppressSelectionFailure/deploy/sca_SuppressSelectionFailure_rev1.0.jar
 (oracle.tip.tools.ide.fabric.deploy.common.SOARemoteDeployer)

After the analysis i could able to find the actual error in the server.

####<Jul 3, 2014 1:31:49 AM PDT> <Error> <oracle.soa.bpel.engine.compiler> <localhost> <AdminServer> <[ACTIVE] ExecuteThread: '121' for queue: 'weblogic.kernel.Default (self-tuning)'> <weblogic> <BEA1-0F722DC56FC50211E7E5> <da70686ff9c96634:-6ae98290:146610fb82a:-7ffd-0000000000bc712e> <1404376309367> <BEA-000000> <SuppressSelectionFailure.bpel(line 56): Assign activity does not have children. Empty assign is not necessary and is not supported in this version of OraBPEL PM>

The actual issue is one of the assign activity did not had the copy rules defined.

To resolve the issue either you can remove the empty assign activity or add the copy rules .




Wednesday, July 2, 2014

Encrypting XML Payload through XSLT in Spring WS

The below document explain the approach to This document will explain the approach to encrypt the critical elements of XML payload while invoking the services in Spring WS or storing the data to a database table through XSLT.



Encrypting_XML_Payload.pdf



Tuesday, July 1, 2014

Unit Testing the Velocity Templates in spring

It is painful to test the Velocity Template  by deploying to the server while doing frequent changes.
The unit testing  will help as to overcome this and do proper testing without deploying the project to the server.
This post will explain the approach to unit test the Velocity Templates through eclipse.

Create a Velocity-test.xml configuration file to configure the velocity bean - instead of creating separate configuration file we can also use the project configuration file that has the velocity bean configuration (e.g. application-context.xml)


Change the vm template path accordingly.

Create a test java class (VelocityTest.java)
import java.io.*;
import java.util.ArrayList;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.thomson.ecom.core.velocity.VelocityContextBuilder;
public class VelocityTest
{
public static void main(String[] args) throws Exception
{
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:velocity-test.xml");
ArrayList<Employee> employeeList=new ArrayList<Employee>();

Employee emp1=new Employee();
emp1.setContactNo("111111");
emp1.setDept("CSC");
emp1.setEmail("a@gmail.com");
emp1.setEmpName("Albin");
emp1.setEmpNo("1");
emp1.setLocation("Bangalore");
employeeList.add(emp1);

Employee emp2=new Employee();
emp2.setContactNo("22222");
emp2.setDept("IT");
emp2.setEmail("b@gmail.com");
emp2.setEmpName("Albin1");
emp2.setEmpNo("2");
emp2.setLocation("Bangalore");
employeeList.add(emp2);

Employee emp3=new Employee();
emp3.setContactNo("33333");
emp3.setDept("IT");
emp3.setEmail("c@gmail.com");
emp3.setEmpName("Albin2");
emp3.setEmpNo("3");
emp3.setLocation("Bangalore");
employeeList.add(emp3);

VelocityEngine engine = ctx.getBean("velocityEngine", VelocityEngine.class);
Context velocityCtx = VelocityContextBuilder.getInstance().buildContext();
velocityCtx.put("empList", employeeList);

Writer w = new FileWriter(new File("D:\\Albin\\velocity.html"));
engine.mergeTemplate("EmployeeEmailTemplate.vm", velocityCtx, w);
w.close();

System.exit(0);
}
}

Change the velocity.html file path and the vm template name accordingly.
Pass the required inputs to the velocityCtx map.
Execute the VelocityTest.java; this will generate the velocity.html file in the specified location.


I have used the sample vm file EmployeeEmailTemplate.vm as below
#macro(writeEmployeeDetails $emp)
<tr>
    <td style="text-align:center;border:1px solid black;">$emp.empName</td>
    <td style="text-align:center;border:1px solid black;">$emp.empNo</td>
    <td style="text-align:center;border:1px solid black;">$emp.email</td>
    <td style="text-align:center;border:1px solid black;">$emp.contactNo</td>
    <td style="text-align:center;border:1px solid black;">$emp.location</td>
       <td style="text-align:center;border:1px solid black;">$emp.dept</td>                 
                
</tr>
#end

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Employee Details</title>
</head>
<body>
       <div>
        <table style="width:50%;" cellspacing="0" cellpadding="0">
        <tr>
        <th style="text-align:center;border:1px solid black;"><b>Name</b></th>
        <th style="text-align:center;border:1px solid black;"><b>EmpNo</b></th>
        <th style="text-align:center;border:1px solid black;"><b>Email</b></th>
        <th style="text-align:center;border:1px solid black;"><b>ContactNo</b></th>
        <th style="text-align:center;border:1px solid black;"><b>Location</b></th>
        <th style="text-align:center;border:1px solid black;"><b>Dept</b></th>        
        </tr>        
        #foreach($emp in $empList)        
        #writeEmployeeDetails($emp)                
               #end            
        </table>
       </div>      
</body>
</html>



Contact Form

Name

Email *

Message *