Managing Discovery Job Methods

import java.net.URL;
import java.rmi.RemoteException;

import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;

import com.hp.schemas.ucmdb._1.types.CmdbContext;
import com.hp.schemas.ucmdb.discovery._1.params.ActivateJobRequest;
import com.hp.schemas.ucmdb.discovery._1.params.ActivateJobRequestDocument;
import com.hp.schemas.ucmdb.discovery._1.params.DeactivateJobRequest;
import com.hp.schemas.ucmdb.discovery._1.params.DeactivateJobRequestDocument;
import com.hp.schemas.ucmdb.discovery._1.params.DispatchAdHocJobRequest;
import com.hp.schemas.ucmdb.discovery._1.params.DispatchAdHocJobRequestDocument;
import com.hp.schemas.ucmdb.discovery._1.params.GetDiscoveryJobsNamesRequest;
import com.hp.schemas.ucmdb.discovery._1.params.GetDiscoveryJobsNamesRequestDocument;
import com.hp.schemas.ucmdb.discovery._1.params.GetDiscoveryJobsNamesResponse;
import com.hp.schemas.ucmdb.discovery._1.params.GetDiscoveryJobsNamesResponseDocument;
import com.hp.schemas.ucmdb.discovery._1.params.IsJobActiveRequest;
import com.hp.schemas.ucmdb.discovery._1.params.IsJobActiveRequestDocument;
import com.hp.schemas.ucmdb.discovery._1.params.IsJobActiveResponse;
import com.hp.schemas.ucmdb.discovery._1.params.IsJobActiveResponseDocument;
import com.hp.ucmdb.generated.DiscoveryServiceStub;
import com.hp.ucmdb.generated.UcmdbFault;


public class TestJob {
	static final String HOST_NAME = "<my_hostname>";
    static final int PORT = 8080;
    private static final String PROTOCOL = "http";
    private static final String FILE = "/axis2/services/DiscoveryService";
    private static final String PASSWORD = "admin";
    private static final String USERNAME = "admin";
    public static CmdbContext cmdbContext = CmdbContext.Factory.newInstance();
	
	public static void activateJob(String jobName) throws RemoteException, UcmdbFault{
		 DiscoveryServiceStub serviceStub = getService();
		 cmdbContext.setCallerApplication("activateJob");
		 ActivateJobRequest activateJobRequest = ActivateJobRequest.Factory.newInstance();
		 activateJobRequest.setCmdbContext(cmdbContext);
		 activateJobRequest.setJobName(jobName);
		 ActivateJobRequestDocument activateJobRequestDocument = ActivateJobRequestDocument.Factory.newInstance();
		 activateJobRequestDocument.setActivateJobRequest(activateJobRequest);
		 serviceStub.activateJob(activateJobRequestDocument);
		
	}
	public static void deActivateJob(String jobName) throws RemoteException, UcmdbFault{
		 DiscoveryServiceStub serviceStub = getService();
		 cmdbContext.setCallerApplication("deActivateJob");
		 DeactivateJobRequest deactivateJobRequest = DeactivateJobRequest.Factory.newInstance();
		 deactivateJobRequest.setCmdbContext(cmdbContext);
		 deactivateJobRequest.setJobName(jobName);
		 DeactivateJobRequestDocument deactivateJobRequestDocument = DeactivateJobRequestDocument.Factory.newInstance();
		 deactivateJobRequestDocument.setDeactivateJobRequest(deactivateJobRequest);
		 serviceStub.deactivateJob(deactivateJobRequestDocument);
		
	}
	public static void isJobActive(String jobName) throws RemoteException, UcmdbFault{
		DiscoveryServiceStub serviceStub = getService();
		 cmdbContext.setCallerApplication("isJobActive");
		 IsJobActiveRequest isJobActiveRequest = IsJobActiveRequest.Factory.newInstance();
		 isJobActiveRequest.setCmdbContext(cmdbContext);
		 isJobActiveRequest.setJobName(jobName);
		 IsJobActiveRequestDocument isJobActiveRequestDocumentt = IsJobActiveRequestDocument.Factory.newInstance();
		 isJobActiveRequestDocumentt.setIsJobActiveRequest(isJobActiveRequest);
		 IsJobActiveResponseDocument isJobActiveResponseDocument =  serviceStub.isJobActive(isJobActiveRequestDocumentt);
		 IsJobActiveResponse isJobActiveResponse = isJobActiveResponseDocument.getIsJobActiveResponse();
		 System.out.println(isJobActiveResponse.toString());
	}
	
	public static void getDiscoveryJobsNames() throws RemoteException, UcmdbFault{
		DiscoveryServiceStub serviceStub = getService();
		 cmdbContext.setCallerApplication("getDiscoveryJobsNames");
		 GetDiscoveryJobsNamesRequest getDiscoveryJobsNamesRequest = GetDiscoveryJobsNamesRequest.Factory.newInstance();
		 getDiscoveryJobsNamesRequest.setCmdbContext(cmdbContext);
		 GetDiscoveryJobsNamesRequestDocument getDiscoveryJobsNamesRequestDocument = GetDiscoveryJobsNamesRequestDocument.Factory.newInstance();
		 getDiscoveryJobsNamesRequestDocument.setGetDiscoveryJobsNamesRequest(getDiscoveryJobsNamesRequest);
		 GetDiscoveryJobsNamesResponseDocument getDiscoveryJobsNamesResponseDocument =  serviceStub.getDiscoveryJobsNames(getDiscoveryJobsNamesRequestDocument);
		 GetDiscoveryJobsNamesResponse getDiscoveryJobsNamesResponse = getDiscoveryJobsNamesResponseDocument.getGetDiscoveryJobsNamesResponse();
		 System.out.println(getDiscoveryJobsNamesResponse.toString());
	}
	//
	public static void dispatchAdHocJob(String probeName,String jobName,String CIID,Long timeout) throws RemoteException, UcmdbFault{
		  DiscoveryServiceStub serviceStub = getService();
		 cmdbContext.setCallerApplication("dispatchAdHocJob");
		DispatchAdHocJobRequest dispatchAdHocJobRequest = DispatchAdHocJobRequest.Factory.newInstance();
		dispatchAdHocJobRequest.setCmdbContext(cmdbContext);
		dispatchAdHocJobRequest.setProbeName(probeName);
		dispatchAdHocJobRequest.setJobName(jobName);
		dispatchAdHocJobRequest.setCIID(CIID);
		dispatchAdHocJobRequest.setTimeout(timeout);
		DispatchAdHocJobRequestDocument dispatchAdHocJobRequestDocument =DispatchAdHocJobRequestDocument.Factory.newInstance();
		dispatchAdHocJobRequestDocument.setDispatchAdHocJobRequest(dispatchAdHocJobRequest);
		serviceStub.dispatchAdHocJob(dispatchAdHocJobRequestDocument);
	
		
	}
	

    public static DiscoveryServiceStub getService() {

        DiscoveryServiceStub serviceStub=null;
        try {

            URL url = new URL(PROTOCOL, HOST_NAME, PORT, FILE);
            serviceStub = new DiscoveryServiceStub(url.toString());

            HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
            auth.setUsername(USERNAME);
            auth.setPassword(PASSWORD);
            serviceStub._getServiceClient().getOptions()
                    .setProperty(HTTPConstants.AUTHENTICATE, auth);

        } catch (Exception e) {
            e.printStackTrace();

        }

        return serviceStub;
    }
	public static  void main (String[] args) throws Exception{
		//activateJob("Range IPs by ICMP");
		//deActivateJob("Range IPs by ICMP");
		//isJobActive("Range IPs by ICMP");
		//getDiscoveryJobsNames();
		//some error
		//dispatchAdHocJob("GDLITVM0136","Range IPs by ICMP","21c90f8a46b3f7bb9aff055b461476a4",10000L);
		
	}

}