Consuming SOAP Web Service in MAF

Tweet about this on TwitterShare on Facebook12Share on LinkedIn19Share on Google+0

Lets create a MAF application to consume the ADF-BC Application Module exposed as SOAP Web Service (Expose Application Module as SOAP Web Service). As you must know, Oracle MAF, formerly Oracle ADF Mobile, is the new Oracle Mobile solution.

In this post we will create a CRUD of employees in Oracle MAF 2.0.1. It will communicate with the ADF-BC through a SOAP Web Service. Download the sample application: MAFSOAPApp.zip.

Let’s start!
Create a Mobile Application Framework Application, and name it as MAFSOAPApp.

consuming-soap-web-services-in-maf1

In the maf-feature.xml file, create a new feature and call it as employees.

consuming-soap-web-services-in-maf2

Click the Content tab, and then click green plus button near File field, to create the EmployeesTF Task Flow.

consuming-soap-web-services-in-maf3

Create the Data Control that connect to ADF-BC SOAP Web Service.
First of all, initialize the ADF-BC SOAP Web Service.

consuming-soap-web-services-in-maf4

In the main menu, choose File > New > From Gallery.
In the New Gallery dialog, choose Business Tier > Data Controls > Web Service Data Control (SOAP/REST).
Fill in the form and click Next.

consuming-soap-web-services-in-maf5

Select all operations and click Finish.

consuming-soap-web-services-in-maf6

Create the Employee Entity.
Go to Projects panel, right-click ViewController project and choose New > Java Class.
In this application, Employee class must implement the Cloneable class.

consuming-soap-web-services-in-maf7

Copy the following code inside Employee class.

private Integer employeeId;
private String firstName;
private String lastName;
private String email;
private String phoneNumber;
private java.sql.Date hireDate;
private String jobId;
private BigDecimal salary;
private BigDecimal commissionPct;
private Integer managerId;
private Integer departmentId;

protected Object clone() throws CloneNotSupportedException {
  return super.clone();
}

Generate the accessors.
Mark this option: “Notify listeners when property changes”.

consuming-soap-web-services-in-maf8

We won’t use the HRSOAPDC Data Control within pages.
We will create a POJO Data Control that will use the operations of HRSOAPDC.
Go to Projects panel, right-click ViewController project and choose New > Java Class.

consuming-soap-web-services-in-maf9

Copy the following code inside HRSOAPPojoDC class.

private Employee employee;
private List employees = new ArrayList();

public void setEmployee(Employee employee) {
  this.employee = employee;
}

public Employee getEmployee() {
  return employee;
}

public Employee[] getEmployees() {
  return (Employee[]) employees.toArray(new Employee[employees.size()]);
}

public void initEmployeeToAdd() {
  employee = new Employee();
}

public void initEmployeeToEdit(Employee employee) throws CloneNotSupportedException {
  this.employee = (Employee) employee.clone();
}

public void findAll() {
  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "findAll", "Executing findAll Method");

  try {
    GenericType result =
      (GenericType) AdfmfJavaUtilities.invokeDataControlMethod(
        "HRSOAPDC", null, "findEmployees", new ArrayList(), new ArrayList(), new ArrayList());

    result = result.getParent();
    employees.clear();

    for (int i = 0; i < result.getAttributeCount(); i++) {
      GenericType gt = (GenericType) result.getAttribute(i);
      Employee employee = (Employee) GenericTypeBeanSerializationHelper.fromGenericType(Employee.class, gt);
      employees.add(employee);
    }

  } catch (AdfInvocationException ex) {
    if (AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
      throw new RuntimeException("Error with the server. Please try later.");
    }
  } catch (Exception e) {
    throw new AdfException(e.getLocalizedMessage(), AdfException.ERROR);
  }

  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "findAll", "End findAll Method");
}

public void update(Employee employee) {
  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "update", "Executing update Method");

  List pNames = new ArrayList();
  List pValues = new ArrayList();
  List pTypes = new ArrayList();

  pNames.add("employeesView1");
  pValues.add(employee);
  pTypes.add(Employee.class);
        
  try {
    AdfmfJavaUtilities.invokeDataControlMethod("HRSOAPDC", null, "updateEmployee", pNames, pValues, pTypes);

  } catch (AdfInvocationException ex) {
    if (AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
      throw new RuntimeException("Error with the server. Please try later.");
    }
  } catch (Exception e) {
    throw new AdfException(e.getLocalizedMessage(), AdfException.ERROR);
  }

  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "update", "End update Method");
}

public void create(Employee employee) {
  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "create", "Executing create Method");

  List pNames = new ArrayList();
  List pValues = new ArrayList();
  List pTypes = new ArrayList();

  pNames.add("employeesView1");
  pValues.add(employee);
  pTypes.add(Employee.class);

  try {
    AdfmfJavaUtilities.invokeDataControlMethod("HRSOAPDC", null, "createEmployee", pNames, pValues, pTypes);

  } catch (AdfInvocationException ex) {
    if (AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
      throw new RuntimeException("Error with the server. Please try later.");
    }
  } catch (Exception e) {
    throw new AdfException(e.getLocalizedMessage(), AdfException.ERROR);
  }

  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "create", "End create Method");
}

public void delete(Employee employee) {
  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "delete", "Executing delete Method");

  List pNames = new ArrayList();
  List pValues = new ArrayList();
  List pTypes = new ArrayList();

  pNames.add("employeesView1");
  pValues.add(employee);
  pTypes.add(Employee.class);

  try {
    AdfmfJavaUtilities.invokeDataControlMethod("HRSOAPDC", null, "deleteEmployee", pNames, pValues, pTypes);

  } catch (AdfInvocationException ex) {
    if (AdfInvocationException.CATEGORY_WEBSERVICE.compareTo(ex.getErrorCategory()) == 0) {
      throw new RuntimeException("Error with the server. Please try later.");
    }
  } catch (Exception e) {
    throw new AdfException(e.getLocalizedMessage(), AdfException.ERROR);
  }

  Trace.log(Utility.ApplicationLogger, Level.FINEST, this.getClass(), "delete", "End delete Method");
}

Create the HRSOAPPojoDC Data Control.
Go to Projects panel, right-click HRSOAPPojoDC.java file and choose Create Data Control.
In the Create Bean Data Control dialog, click Next and Finish.

consuming-soap-web-services-in-maf10

consuming-soap-web-services-in-maf11

Open the EmployeesTF.xml file.
Go to Data Controls panel and expand HRSOAPPojoDC.
Drag the findAll, initEmployeeToAdd and initEmployeeToEdit operations and drop inside the EmployeesTF.
In the Edit Action Binding dialog, set the value of employee to #{pageFlowScope.employeeSelected}.

consuming-soap-web-services-in-maf12

Drag three View and a Router components and drop inside EmployeesTF.
Connect them using the Control Flow Case component.

consuming-soap-web-services-in-maf13

Double-click all View components and click OK to create the AMX Pages.

consuming-soap-web-services-in-maf14

Click in Router component and configure it like the following image.

consuming-soap-web-services-in-maf15

Open the empList page.
Go to Data Control panel, drag the employees collection and drop inside page as MAF List View.
In the ListView Gallery, click Ok twice.

consuming-soap-web-services-in-maf16

consuming-soap-web-services-in-maf17

Change the empList page like the following image.

consuming-soap-web-services-in-maf18

Go to Bindings and edit the employees binding.
Add lastName and firstName as Display Attributes.

consuming-soap-web-services-in-maf19

Open the empDetail page.
Go to Data Control panel, drag the employees collection and drop inside page as MAF Read-only Form.
In the Edit Form Fields dialog, click Ok.

consuming-soap-web-services-in-maf20

Go to Data Control panel, drag the delete operation and drop inside the secondary facet as MAF Button.
In the Edit Action Binding, set the value of employee to #{bindings.employeesIterator.currentRow.dataProvider}.

consuming-soap-web-services-in-maf21

Change the empDetail page like the following image.

consuming-soap-web-services-in-maf22

Open the empEdit page.
Go to Data Control panel, drag the employee Structured Attribute and drop inside page as MAF Form.
In the Edit Form Fields dialog, click Ok.

consuming-soap-web-services-in-maf23

Go to Data Control panel, drag the create and update operations and drop inside secondary facet as MAF Button.
In the Edit Action Binding, set the value of employee to #{bindings.employeeIterator.currentRow.dataProvider}.

consuming-soap-web-services-in-maf24

consuming-soap-web-services-in-maf25

Change the empEdit page like the following image.

consuming-soap-web-services-in-maf26

Open the DataBindings.cpx file and add the following line.

consuming-soap-web-services-in-maf28

Go to Application Resources panel and expand Descriptors > ADF META-INF.
Open the connections.xml file and change the host to 10.0.2.2.
Android uses this host to access your localhost.

consuming-soap-web-services-in-maf27

Deploy the application and enjoy!

consuming-soap-web-services-in-maf29

consuming-soap-web-services-in-maf30

consuming-soap-web-services-in-maf31

consuming-soap-web-services-in-maf32

Tweet about this on TwitterShare on Facebook12Share on LinkedIn19Share on Google+0

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.

2 thoughts on “Consuming SOAP Web Service in MAF”

  1. I am new to oracle jdeveloper MAF. i am unable to see any contents in Application Feature and Device Feature which is under Data Controls. Please let me know weather i should any plug in for the same.

Leave a Reply

Your email address will not be published. Required fields are marked *