Saturday, February 28, 2015

How to subscribe the Contact to a EmailGroup through Java API in Eloqua

This post explains how to create the contact in Eloqua through java.

Create the required model classes.

public class EmailGroup
{
public String type;
public String id;
public String depth;
public String description;
public String name;
public String updatedAt;
public String updatedBy;
}

public class Subscription
{
public EmailGroup emailGroup;
public String isSubscribed;
public String contactId;
public String  type;
}

RestClient class to connect to Eloqua.

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

public class RestClient
{
    private String authToken;
    private String baseUrl;      
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;            
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());          
    }            
                         
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {          
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                        
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          System.out.println(authToken);
          conn.setRequestProperty("Authorization", authToken);        
                 
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                     
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line;
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }          
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}

The Helper class to subscribe the contact to EmailGroup– Change the Eloqua credential accordingly.

import com.google.gson.Gson;
import models.EmailGroup;
import models.Subscription;

public class SubsceiptionHelper
{
   private RestClient client;
        
   public SubsceiptionHelper(String site, String user, String password, String baseUrl)
   {
      client = new RestClient(site + "\\" + user, password, baseUrl);
   }                
            
              
    public void subscribe(String contactid,String emailGroupId) throws Exception{
       try {                     
           String response = null;
           EmailGroup emailGroup = new EmailGroup();
      emailGroup.type = "EmailGroup";
      emailGroup.id = emailGroupId;
      emailGroup.depth = "minimal";
      emailGroup.name = "Corporate";
   
      Subscription subscription = new Subscription();
      subscription.contactId = contactid;
      subscription.emailGroup = emailGroup;
      subscription.isSubscribed = "true";
      subscription.type = "ContactEmailSubscription";

      Gson gson = new Gson();
      String contactRequest = gson.toJson(subscription);
      response = client.execute("/data/contact/"+contactid+"/email/group/"+emailGroupId+"/subscription","PUT",contactRequest);
           if(response==null)
           {
          throw new Exception("Not able to subscribe");
           }
                              
        } catch (Exception e) {
           throw e;
        }  
  
     }           
              
     public static void main(String[] args) {
                              
    SubsceiptionHelper helper=new SubsceiptionHelper("companyname", "username", "password", "https://secure.p03.eloqua.com/api/rest/1.0");
        try {
            helper.subscribe("6336","3");
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
         }
                              
   }

}




How to get the Subscriptions of a Contact through through Java API in Eloqua

This post explains how to create the contact in Eloqua through java.

Create the required  model classes.

public class SubscriptionResponse
{
public List<Subscription> elements;
}

public class Subscription
{
public EmailGroup emailGroup;
public String isSubscribed;
}

public class EmailGroup
{
public String type;
public String id;
public String depth;
public String description;
public String name;
public String updatedAt;
public String updatedBy;
}

RestClient class to connect to Eloqua.

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

public class RestClient
{
    private String authToken;
    private String baseUrl;      
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;            
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());          
    }            
                         
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {          
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                        
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          System.out.println(authToken);
          conn.setRequestProperty("Authorization", authToken);        
                 
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                     
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line;
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }          
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}

The Helper class to get the contact subscriptions– change the Eloqua credential accordingly.

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import models.SubscriptionResponse;
import .models.Subscription;

public class SubsceiptionHelper
{
   private RestClient client;
        
   public SubsceiptionHelper(String site, String user, String password, String baseUrl)
   {
      client = new RestClient(site + "\\" + user, password, baseUrl);
   }                
            
              
    public Map<String,String> getSubscriptionList(String contactid) throws Exception{
      Map<String,String> emailIdMap = new HashMap<String, String>();                    
     try {                     
           String response = null;
           Gson gson = new GsonBuilder().serializeNulls().create();                           
           response = client.execute("/data/contact/"+contactid+"/email/groups/subscription","GET",null);
           System.out.println(response);
           if(null!=response){
           SubscriptionResponse searchResponse = gson.fromJson(response, SubscriptionResponse.class);      
           List<Subscription> subscriptionList = searchResponse.elements;
           for(Subscription subscription :subscriptionList){
            if(null !=subscription.isSubscribed){
            if((subscription.isSubscribed.equals("true"))){
            emailIdMap.put(subscription.emailGroup.id, subscription.emailGroup.name);
            }
            }
           }      
            }
                              
        } catch (Exception e) {
           throw e;
        }  
     
     return emailIdMap;
     }           
              
     public static void main(String[] args) {
                              
    SubsceiptionHelper helper=new SubsceiptionHelper("companyname", "username", "password", "https://secure.p03.eloqua.com/api/rest/1.0");
        try {
            System.out.println(helper.getSubscriptionList("1"));
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
         }
                              
   }

}






Thursday, February 19, 2015

How to check the replication status through java API in Adobe CQ5

This post will explain how to check the replication status through java API in Adobe CQ5

Add the following dependency to the pom.xml

<dependency>
<groupId>com.adobe.granite</groupId>
<artifactId>com.adobe.granite.replication.core</artifactId>
<version>5.12.2</version>
<scope>provided</scope>
</dependency>

@Reference
Replicator replicator;

@Reference
SlingRepository repository;

Session  session = repository.loginAdministrative(null);
ReplicationStatus status=replicator.getReplicationStatus(session, “nodepath”);

status.isDelivered();//Checks if the content is delivered

Other methods to get the different status

isActivated()
isDeactivated
isPending()



How to execute the Quartz scheduler job only in master author node - Adobe CQ5

While we are deploying the scheduler in CQ5, the scheduler will be active in master/slave author nodes and all the publish nodes(based on our deployment configuration).

But sometimes there will be scenario the scheduled job should be only executed in master author node.

The below code snippet can be used to restrict the job getting executed only in master author node.

@Reference
SlingRepository repository;
private void sampleScheduledJob() {
       if(isRunMode("author") && isMasterRepository()){
            //execute the job functionality here
       }
}

private Boolean isRunMode(String mode) {
        Set<String> runModes = slingSettings.getRunModes();
        for (String runMode : runModes) {
                if (runMode.equalsIgnoreCase(mode)) {
                         log.debug("Current Runmode is : " + runMode);
                         return true;
                 }
        }
        return false;
}
               
public boolean isMasterRepository(){
          final String isMaster = repository.getDescriptor("crx.cluster.master");
          log.debug("isMaster.."+isMaster);
          return StringUtils.isNotBlank(isMaster) && Boolean.parseBoolean(isMaster);
}
               


  



The Admin console is not up/accessible – Oracle SOA Suite

We were facing a strange issue in our Oracle SOA Suite production server in Solaris, we could not able to access the admin console even though the server is started properly and there is no error in the log file.

We were able to telnet the admin server listen address from Admin server node but not able to do it from other nodes.

The root cause of the issue is with Gateway server, the admin server listen address is not listed on the Gateway - the gateway server is not online (the servers listen address is configured in Gateway).

After Solaris admin team made the Gateway server online, we were able to see the admin server listen address listed on the gateway.

After restarting the admin server we were able to access the console page.

The following command can be used for checking the Gateway server status

 netstat –r  



Sunday, February 15, 2015

org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet - Asobe CQ5

I was getting the below exception while invoking the servlet from Adobe CQ5 bundle.

15.02.2015 20:58:11.615 *ERROR* [FelixDispatchQueue] FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet) org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:332)
at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:219)
at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:320)
at org.apache.felix.framework.Felix.getService(Felix.java:3556)
at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:468)

 The root cause of the problem is different versions of servlet API classes are loaded by two different class-loaders.

To fix the issue make sure <scope>provided</scope> is added for the Servlet API dependency in POM.xml

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
</dependency>







Saturday, February 14, 2015

com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle - AEM

I was able compile and  deploy the bundle successfully with gson dependency but the bundle is not getting started with the error "com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle" in Adobe Experience Manager

The root cause of the problem is the gson jar is not available in the server for bundle access.

This issue can be resolved  by following any of the below approach.

1. Export the gson  package - com.google.gson.*

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>com.sample.activator.Activator</Bundle-Activator>
<Import-Package>*,com.sample.*</Import-Package>
<Export-Package>com.sample.*,com.google.gson.*</Export-Package>
<Bundle-SymbolicName>com.sample</Bundle-SymbolicName>
<Bundle-Vendor>Sample</Bundle-Vendor>
<Bundle-Category>Sample</Bundle-Category>
<Embed-Directory>dependencies</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

2. Add the gson jar in the bundle class path

Specify the gson dependency scpes as compile or runtime(compile is the default scope)

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency

The gson jar will be included in the bundle classpath.

The dependencies with what are all the scopes are included in the bundle classpath is configured in maven-bundle-plugin

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>



3. Install the gson jar as bundle from felix console

The above two approaches the gson jar will be only available for the bundle but in this approach the jar will be available for all the bundles.

Go to http://localhost:4502/system/console/bundles
Click on Install/Update
Select Start Bundle and choose the gson jar.
Click on Install or Update.



How to create the contact in Eloqua through java

This post explains how to create the contact in Eloqua through java.

Create the model class for Contact:-

public class Contact
{
 public String accountName;
 public String address1;
 public String address2;
 public String address3;
 public String businessPhone;
 public String city;
 public String country;
 public String firstName;
 public String emailAddress;
 public String id;
 public boolean isBounceback;
 public boolean isSubscribed;
 public String lastName;
 public String salesPerson;
 public String title;
 public String type;
 public String name;

}

RestClient class to connect to Eloqua.

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

public class RestClient
{
 private String authToken;
 private String baseUrl;

 public RestClient(String user, String password, String url)
 {
  baseUrl = url;
  String authString = user + ":" + password;
  authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());        }

 public String execute(String uri, String method, String body)  throws Exception
 {
  String response ="";
  try
  {
   URL url = new URL(baseUrl + uri);
   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 
   conn.setInstanceFollowRedirects(false);
   conn.setRequestMethod(method.toString());
   conn.setRequestProperty("Content-Type", "application/json");
   conn.setRequestProperty("Accept", "application/json");
         conn.setRequestProperty("Authorization", authToken);    
       
         if (method == "POST" || method == "PUT")
         {
          if(null != body){
    conn.setDoOutput(true);
          final OutputStream os = conn.getOutputStream();
                os.write(body.getBytes());
                os.flush();
                os.close();
          }
         }
       
         InputStream is = conn.getInputStream();
         BufferedReader rd = new BufferedReader(new InputStreamReader( is));

          String line;
         while ((line = rd.readLine()) != null)
         {
             response += line;
         }        
         rd.close();
         conn.disconnect();
  }
  catch (Exception e)
  {
   throw e;
  }
        return response;
 }
}


The Helper class to create the contact– change the Eloqua credential accordingly.

import com.google.gson.Gson;

public class ContactHelper {

private RestClient client;

 public ContactHelper(String site, String user, String password, String baseUrl)
 {
  client = new RestClient(site + "\\" + user, password, baseUrl);
 }
 public void createContact(Contact contact) throws Exception{
   try {
  String response = null;
  Gson gson = new Gson();
  String contactRequest = gson.toJson(contact);
   response = client.execute("/data/contact","POST",contactRequest);
   System.out.println(response);
   if(null==response){      
       throw new Exception("Not able to get the campaign");
   }
 
   } catch (Exception e) {
    throw e;
   }
 }

 public static void main(String[] args) {
  ContactHelper helper=new ContactHelper("companyname", "username", "password", "https://secure.p03.eloqua.com/api/rest/2.0");
  try {
     Contact contact = new Contact();
     contact.firstName = "Albin";
     contact.lastName = "Issac";
     contact.isSubscribed = true;
     contact.type = "Contact";
     contact.emailAddress = "albinsharp@gmail.com";
   
     helper.createContact(contact);
   
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}




Wednesday, February 11, 2015

Expected a string but was BEGIN_ARRAY at line 1 column

I was receiving "Expected a string but was BEGIN_ARRAY at line 1 column" error while deserializing the json string to java object using Gson.

Model class:

public class EmailGroup{
private String type;
private String id;
private String name;
private String permissions;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPermissions() {
return permissions;
}
public void setPermissions(String permissions) {
this.permissions = permissions;
}
}

JSON Response:

{"emailGroup":{"type":"EmailGroup","id":"1","depth":"minimal","description":"","name":"sample","permissions":[2,5,4,3]}}

Gson gson = new Gson();
EmailGroup obj = gson.fromJson(jsonstring, EmailGroup.class)

The root cause of the exception is the permissions attribute defined in the model class is of type String but the type of permissions in the jsonstring is List.

To fix the issue convert the type of permissions in the model class to List<String>(type string will change based on the type of the list entries)

public class EmailGroup{
private String type;
private String id;
private String name;
private List<String> permissions;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getPermissions() {
return permissions;
}
public void setPermissions(List<String> permissions) {
this.permissions = permissions;
}
}




Saturday, February 7, 2015

How to retrieve the pages created with particular template using Query Builder API - Adobe CQ5

This post will explain how to retrieve the pages created with particular template using Query Builder API in Adobe CQ5

@Reference
QueryBuilder queryBuilder;

Session session = repository.loginAdministrative(null);

String resourcePath="/content/sample/site-demo/en";

Map<String, String> searchMap = new HashMap<String, String>();
searchMap.put("type", "cq:Page");
searchMap.put("path", resourcePath);
searchMap.put("property", "jcr:content/cq:template");
searchMap.put("property.value", "/apps/common/templates/sampleview");
searchMap.put("p.limit", "-1");

Query query = queryBuilder.createQuery(PredicateGroup.create(searchMap),session);

SearchResult result = query.getResult();
for(Hit hit:result.getHits()) {

    String pagePath = hit.getPath();
    Node pageNode = hit.getNode
}



How to activate the Campaign in Eloqua through java

This post explains how to activate the Eloqua campaign through java.

RestClient class to connect to Eloqua.

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

public class RestClient
{
    private String authToken;
    private String baseUrl;       
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;             
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());           
    }             
                          
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {           
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                         
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          conn.setRequestProperty("Authorization", authToken);         
                  
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                      
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line; 
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }           
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}

The Helper class to activate the campaign– change the Eloqua credential accordingly.

public class CampaignHelper
{
   private RestClient client;

   public CampaignHelper(String site, String user, String password, String baseUrl)
   {
      client = new RestClient(site + "\\" + user, password, baseUrl);
   }

   public void activateCampaign(String campaignId) throws Exception{

       try {
     String response = null;
     response = client.execute("/assets/campaign/"+campaignId,"GET",null);
     if(null!=response){      
        response = client.execute("/assets/campaign/active/"+campaignId,"POST", response);  
        if(null == response){
     throw new Exception("Not able to activate the campaign");
  }
       }else
       {
    throw new Exception("Not able to get the campaign");
       }

     } catch (Exception e) {
  throw e;
     }
     }

     public static void main(String[] args) {
 CampaignHelper helper=new CampaignHelper("companyname", "username", "password", "https://secure.p03.eloqua.com/api/rest/2.0");
 try {
  helper.activateCampaign("143");
  } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }

      }
}



How to update the html content of Email template in Eloqua through java

This post explains how to update the html content of the Eloqua email through java.

Create the model class for Email:-

public class Email
{            
public int emailGroupId;
public RawHtmlContent htmlContent;
public Integer id;
public boolean isPlainTextEditable;
public String name;
public String plainText;
public boolean sendPlainTextOnly;
public String subject;
}
public class RawHtmlContent
{
 public String type;
 public String html;
}

Create the html template with place holder for dynamic content and place the template in the same location of the below java classes.

sample-template.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <body>
      ${content}
   </body>
</html>

RestClient class to connect to Eloqua.

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

public class RestClient
{
    private String authToken;
    private String baseUrl;      
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;            
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());          
    }            
                         
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {          
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                        
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          conn.setRequestProperty("Authorization", authToken);        
                 
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                     
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line;
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }          
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}

The Helper class to update the email – change the Eloqua credential accordingly.

import java.io.BufferedInputStream;
import java.io.InputStream;
import models.Email;
import models.RawHtmlContent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class EmailHelper
{
   private RestClient client;
       
   public EmailHelper(String site, String user, String password, String baseUrl)
   {
      client = new RestClient(site + "\\" + user, password, baseUrl);
   }                    
           
             
    public void updateHtmlContent(String emailId,String content) throws Exception{
                             
     try {                    
           String response = null;
           InputStream stream = EmailHelper.class.getResourceAsStream("sample-template.html");                  
           StringBuffer buffer = new StringBuffer();
           BufferedInputStream input = new BufferedInputStream(stream);
           int data = input.read();
           while (data != -1) {
              buffer.append((char) data);
              data = input.read();
            }
           String templateString = buffer.toString();        
           templateString = templateString.replace("${content}", content);        
           System.out.println("templateString"+templateString);
           Gson gson = new GsonBuilder().serializeNulls().create();                          
           response = client.execute("/assets/email/"+emailId,"GET",null);
           if(null!=response){
             Email email = gson.fromJson(response, Email.class);  
             RawHtmlContent rawHtmlContent = new RawHtmlContent();
             rawHtmlContent.type = "RawHtmlContent";
             rawHtmlContent.html = templateString;
             email.htmlContent = rawHtmlContent;
             String requestbody = gson.toJson(email);    
             response = client.execute("/assets/email/"+emailId,"PUT", requestbody);
                                 
             if(null == response){
                throw new Exception("Not able to update the Template");
             }
            }
                             
        } catch (Exception e) {
           throw e;
        }                          
     }          
             
     public static void main(String[] args) {
                             
      EmailHelper helper=new EmailHelper("companyname", "username", "password", "https://secure.p03.eloqua.com/api/rest/2.0");
        try {
            helper.updateHtmlContent("73","Albsample1");
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
         }
                             
   }

}




Monday, February 2, 2015

Console Exception:Error opening /com/bea/alsb/console/oam/module/Module.jpf - Oracle OSB

We were getting the exception "Error opening /com/bea/alsb/console/oam/module/Module.jpf. An unexpected error occurred" while opening OSB console.


The following exception was displayed in the AdminServer error log.

<02-Feb-2015 09:53:42 o'clock GMT> <Error> <netuix> <BEA-423137> <There was an error loading the requested URI /com/bea/alsb/console/oam/module/Module.jpf.>
<02-Feb-2015 09:53:42 o'clock GMT> <Error> <netuix> <BEA-423223> <There was an error while running a lifecycle stage :: Lifecycle: UIControl.render :: for the control :: null ::.
com.bea.netuix.nf.UIControlException: com.bea.portlet.adapter.scopedcontent.ActionLookupFailedException: javax.servlet.ServletException: com.bea.alsb.console.common.base.SBConsoleAccessException: The current login role is not authorized to use the console action: "/sbSubModules"
        at com.bea.netuix.servlets.controls.content.PageFlowContent.checkPreRenderExceptions(PageFlowContent.java:130)
        at com.bea.netuix.servlets.controls.content.NetuiContent.beginRender(NetuiContent.java:343)
        at com.bea.netuix.nf.ControlLifecycle$7.visit(ControlLifecycle.java:485)
        at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:518)
        at com.bea.netuix.nf.ControlTreeWalker.walkRecursiveRender(ControlTreeWalker.java:529)
        Truncated. see log file for complete stacktrace

<02-Feb-2015 09:55:56 o'clock GMT> <Error> <ALSB Console> <BEA-494002> <Internal error occured in OSBConsole : The current login role is not authorized to use the console action: "/ViewChangeCenter"
com.bea.alsb.console.common.base.SBConsoleAccessException: The current login role is not authorized to use the console action: "/ViewChangeCenter"
        at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.processActionPerform(SBConsoleRequestProcessor.java:88)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processInternal(PageFlowRequestProcessor.java:556)
        at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.process(PageFlowRequestProcessor.java:853)
        at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.process(SBConsoleRequestProcessor.java:191)
        Truncated. see log file for complete stacktrace

The OSB console page was opening properly and stopped working suddenly.

The root cause of the problem is corruption of the embedded LDAP user store.

Resolving the issue:

Stop all servers in the domain and backup the <<SERVER_HOME>>/data/ldap for all the servers including managed server.

Copy the ldap folder from the previous server backup or other working environment from same location to all the servers.

Restart the servers.



Sunday, February 1, 2015

Changing the log level for a package - Adobe CQ5

This post explains the steps required to change the log level for a package in Adobe CQ5(the version referred here is 5.6.1)

We can enable the log level of a package in two level - Global level, Package level.

Global level:

Login to /system/console/configMgr and go to OSGI -->Configuration
Search for "Apache Sling Logging Configuration"
Change the log level accordingly


Save the configuration

Package level:

Login to /system/console/configMgr and go to OSGI -->Configuration
Search for "Apache Sling Logging Logger Configuration" and click on "+" to add new configuration.


Provide the package name in the Logger and Save the configuration.



To change the logger level open the configured Logger from the "Apache Sling Logging Logger Configuration" and change log level.


Save the configuration.



Contact Form

Name

Email *

Message *