Saturday, February 28, 2015

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

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;
      }
}



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

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;
      }
}



Thursday, February 19, 2015

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

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

This post will explain how to check the replication status through java API in Adobe Experiance Manager(AEM)/Adobe CQ5

Maven dependency:

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>

API's:

@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()


Wednesday, February 18, 2015

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

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

While we are deploying the scheduler in Adobe Experience Manager(AEM), 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

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