Friday, March 13, 2015

Oracle MAF Hello world using Web Service and JAVA client (Programmatic way to implement web service)

Hi Developers,

Before proceeding with this tutorial, have a look(detailed look) over the below mentioned tutorial :

http://oracle-maf-nakul.blogspot.in/2015/02/oracle-mafadf-mobile-hello-world-using.html

Also, complete the tutorial mentioned in the link till Step 8(Part 2) :  After completion of wizard your data control should look as shown below :





Now we are ready to implement our programmatic implementation of hello world WSDL Solution.

Step 1 : Create a JAVA class and name it as HelloWorldDC.java. Paste the following code :

-----------------------------------------------------------------------------------------------------------------

package com.oracle.mobile.hello;

import java.util.ArrayList;
import java.util.List;

import oracle.adfmf.framework.api.AdfmfJavaUtilities;
import oracle.adfmf.framework.exception.AdfInvocationException;
import oracle.adfmf.util.GenericType;

public class HelloWorldDC {
    public HelloWorldDC() {
        super();
    }

    public String  callHelloWSDL(String input) {
              List pnames = new ArrayList();
              List pvals = new ArrayList();
              List ptypes = new ArrayList();
              GenericType result;
              String response = null;
                pnames.add("arg0");
                ptypes.add(String.class);
                pvals.add(input);
               
     
        try {
            response = (String) AdfmfJavaUtilities.invokeDataControlMethod("Hello_WS", null, "sayHello", pnames, pvals, ptypes);
       
        } catch (AdfInvocationException e) {
        }
        return response;
    }
   
}


-----------------------------------------------------------------------------------------------------------------


Follow below mentioned link to get in depth knowledge of the invokeDataControlMethod :

http://docs.oracle.com/cd/E35521_01/apirefs.111230/e27204/oracle/adfmf/framework/api/AdfmfJavaUtilities.html#invokeDataControlMethod_java_lang_String__java_lang_String__java_lang_String__java_util_List__java_util_List__java_util_List_

Parameters explanation :

dcName(The Data control we created) - The name of the DataControl on which the method (or the nested object that declares the method) is declared.
instanceName - The name of the nested object on the DataControl that declares the method (can be null if the method is on the root DC).
methodName(In our case sayHello is the method/operation) - The name of the method to invoke.
parameterNames - The names of any named parameters. Required, elements must be of type java.lang.String.
parameters - The parameter values. Elements can be of any type.
     parameterTypes - The parameter types. Elements must be of type java.lang.Class. Can be null if          the data control implementation does not require parameter types for invocation. 


Step 2 :  Create a data control :

      Right click the HelloWorldDC.java  and select Create Data Control. Once the wizard is ready you can see data control section modified as shown below :




NOTE : It is fine if you do not have "HelloWorld_WS" in your list.

Step 3 : Drag the callHelloWSDL(String) on to a page and perform the same steps mentioned from                     Step 9 as in : http://oracle-maf-nakul.blogspot.in/2015/02/oracle-mafadf-mobile-hello-world-using.html

Step 4 : Deploy and test result :























Thursday, March 5, 2015

Oracle MAF Error : java.lang.Integer cannot be cast to oracle.adfmf.util.GenericType

Hi Developers,

I faced the following error when I was implementing a tutorial :
http://www.ateam-oracle.com/going-mobile-with-adf-programmatically-invoking-soap-web-services-with-complex-types/



The detail analysis for this error can be found out on following link :

https://community.oracle.com/thread/3647460

But if you want to quickly solve the error modify the DepartmentService.java file as described below :

-------------------------------------------------------------------------------------------------------------------------
package oracle.ateam.mobile.soapdemo.model;

import java.util.ArrayList;
import java.util.List;

import oracle.adfmf.framework.api.AdfmfJavaUtilities;
import oracle.adfmf.framework.api.GenericTypeBeanSerializationHelper;
import oracle.adfmf.framework.exception.AdfException;
import oracle.adfmf.util.GenericType;

public class DepartmentService {
    List departments = new ArrayList();

    public DepartmentService() {
        super();
        findAll();
    }

    public Department[] getDepartments() {
        Department[] departmentArray = (Department[]) departments.toArray(new Department[departments.size()]);
        return departmentArray;
    }

    public void findAll() {
        try {
            GenericType result =
                (GenericType) AdfmfJavaUtilities.invokeDataControlMethod("HRSOAPService", null, "findDepartments",
                                                                         new ArrayList(), new ArrayList(),
                                                                         new ArrayList());
            result = result.getParent(); // this line will solve error
            for (int i = 0; i < result.getAttributeCount(); i++) {
                GenericType entityGenericType = (GenericType) result.getAttribute(i);

                Department department =
                    (Department) GenericTypeBeanSerializationHelper.fromGenericType(Department.class,
                                                                                    entityGenericType);
                departments.add(department);
            }
        } catch (Exception e) {
            throw new AdfException(e.getLocalizedMessage(), AdfException.ERROR);
        }
    }
}
------------------------------------------------------------------------------------------------------------------------

NOTE :   Following code actually solves the problem of your life :

                 result = result.getParent();

That is it, now enjoy your life with programmatic implementation of WSDL using JAVA in MAF.