Friday, March 4, 2016

Abort instances in EM Console using Java code soa 11g

Basically whatever we see in EM console and whatever do in EM console can be achieved via JAVA code too(using the facade API's). Below is the sample code to abort the instance for any composite in EM console by passing the instance id.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.facade.CompositeInstance;
import java.util.List;

public class abortInstance
{
public static void main(String arg[]) throws Exception
{
Hashtable jndi = new Hashtable();
jndi.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndi.put(Context.PROVIDER_URL, "t3://Host:port");
jndi.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndi.put(Context.SECURITY_CREDENTIALS, "password");

jndi.put("dedicated.connection","true");
Locator locator = null;
String instanceID="4432123"; /// pass the composite Instance Id you want to Abort
try
{
locator =LocatorFactory.createLocator(jndi);
CompositeInstanceFilter filter =new CompositeInstanceFilter();
filter.setId(instanceID);
List<CompositeInstance> compositeInstances = locator.getCompositeInstances(filter);
((CompositeInstance)compositeInstances.get(0)).abort();
System.out.print("Instance aborted Successfully: "+instanceID);
locator.close();
}catch(Exception e)
{
locator.close();
e.printStackTrace();
}
finally {
        try {
            if (locator != null){                
            locator.close();            
            }
             } catch (Exception e) { }
    }
}

}

The same code can altered with other functions like delete the instance as well.

No comments:

Post a Comment