Friday, November 14, 2014

Executing BAM webservices using ADF proxy

In this blog we are going to create ADF proxy to execute BAM service and then expose it as a datacontrol. Here are the steps

1. Make sure wsdl url is accessible: Acess wsdl url as http://<server>:<port>/OracleBAMWS/WebServices/DataObjectOperationsByName?WSDL

You will be asked for username/password. Provide it and see wsdl is appearing fine.

2. Create proxy for wsdl: Follow these steps in your model project

  


 
    Select next next next in other screens. No need to select any security policy.

3. Create a class to execute service:


import com.oracle.xmlns.bam.BAMWebServiceException_Exception;
import com.oracle.xmlns.bam.DataObjectOperationsByName;
import com.oracle.xmlns.bam.DataObjectOperationsByName_Service;

import java.util.Map;

import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;

import weblogic.wsee.jws.jaxws.owsm.SecurityPoliciesFeature;

public class BAMServiceDC {
    private static String USERNAME = "weblogic";
    private static String PASSWORD = "weblogic1";
   
    public BAMServiceDC() {
        super();
    }
   
    public String invokeBAMGetService(String keyCSV,String xmlPayLoad){
        DataObjectOperationsByName_Service dataObjectOperationsByName_Service = new DataObjectOperationsByName_Service();
        DataObjectOperationsByName dataObjectOperationsByName = dataObjectOperationsByName_Service.getDataObjectOperationsByName();
        // Add your code to call the desired methods.
        Map<String, Object> reqContext = ((BindingProvider) dataObjectOperationsByName).getRequestContext(); 

//I would recommend to get username/password from credential store.
               reqContext.put(BindingProvider.USERNAME_PROPERTY, USERNAME ); 
               reqContext.put(BindingProvider.PASSWORD_PROPERTY, PASSWORD ); 
                       
               String response = "";
               try {
                   response = dataObjectOperationsByName.get(keyCSV,xmlPayLoad);
                   System.out.println(response);
                  
                  
                  
               } catch (BAMWebServiceException_Exception e) {
                   e.printStackTrace();
               }
              
               return response;
    }



    public String invokeBAMInsertService(String xmlPayLoad){
        DataObjectOperationsByName_Service dataObjectOperationsByName_Service = new DataObjectOperationsByName_Service();
        DataObjectOperationsByName dataObjectOperationsByName = dataObjectOperationsByName_Service.getDataObjectOperationsByName();
        // Add your code to call the desired methods.
        Map<String, Object> reqContext =  ((BindingProvider)dataObjectOperationsByName).getRequestContext();
        reqContext.put(BindingProvider.USERNAME_PROPERTY, USERNAME);
        reqContext.put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);

        String response = "";
        try {
            dataObjectOperationsByName.insert(xmlPayLoad);
            System.out.println("Inserted successfully.");
            response = "SUCCESS";

        } catch (BAMWebServiceException_Exception e) {
            e.printStackTrace();
            return "ERROR: " + e.getMessage();
        }

        return response;
    }



    public static void main(String [] args)
    {       
        BAMServiceDC bs = new BAMServiceDC();
        //GET       
String keyCSV = "EmployeeID,Name,EmployeeTypeCode";            
String xmlPayLoad = "<DataObject Name=\"Employee\" Path=\"/Sanjeev\"> <Contents>\n" +  
           " <Row>\n" +        
           "      <Column Name=\"EmployeeID\" Value=\"2\" />\n" +    
           "    </Row>\n" +     
           "</Contents></DataObject>";   
String response = bs.invokeBAMGetService(keyCSV,xmlPayLoad);       
System.out.println(response);
       
       
        //INSERT
//        String xmlPayLoadIns = "<DataObject Name=\"Employee\" Path=\"/Sanjeev\"> <Contents>\n" +
//        " <Row>\n" +
//        "      <Column Name=\"Name\" Value=\"B\" />\n" +
//        "      <Column Name=\"EmployeeTypeCode\" Value=\"APPLICANT\" />\n" +
//        "    </Row>\n" +
//        "</Contents></DataObject>";
//        bs.invokeBAMInsertService(xmlPayLoadIns);


}

We can run this class and also expose it as a datacontrol to execute BAM webservices.



No comments: