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.




Thursday, February 26, 2015

Oracle MAF Hello world using Web Service

Hi Developers,

I decided to write this blog after googling a lot and finding nothing concrete for sample Hello world implementation for Oracle MAF(Mobile Application Framework) using Web services.

The sample is divided in two half:

1. Create Web Service using Oracle ADF fusion web application.
2. Create an Oracle MAF project to incorporate the web service and create app for the same.

1. Create Web Service using Oracle ADF fusion web application:
 
          It is not necessary to use Oracle ADF for developing the web service, you can use Oracle SOA, java web service or any web service development platform on this planet. Ultimately what we need is a WSDL(Google w3c schools for more information on WSDL).

Lets get started :

Step 1 : Create a Oracle ADF Fusion Web Application.
Step 2 : Name : HelloWorldService
Step 3 : Click Finish to complete a wizard

After step 3 you can see following structure in you Jdeveloper :


    Step 4 : Right Click Model->New->From Gallery, in search window type JAVA and from the list select JAVA Class:

   Step 5 : Create a JAVA file with name : HelloWorld.java(keep rest all default and complete the wizard), add following code to the file :
-----------------------------
    public String sayHello(String input) {
        return "Hello "+ input;
    }
----------------------------
Your code should look similar to following :



  Step 6 :  Right click the HelloWorld.java and select Create Web Service option. Select following option click Next and Finish.


Step 7 : Once the wizard is complete you can see the changed code as shown below :

   


Step 8 : Right Click the HelloWorld.java and click Test web service. Web logic server will start,once the server is up and web service is ready you will see the following :



Test your web service and if you get correct output(as shown below) our first job is done :



  2. Create an Oracle MAF project to incorporate the web service and create app for the same:
     
     Step 1 :   Create a new project and Select Mobile Application Framework Application,click            Ok.Follow the screen shot below to create the application :


  keep rest things default and finish the wizard.

   Step 2 : Open the maf-feature.xml file :



  Step 3 : Select the feature Hello, go to content tab, click Plus(+) symbol and select AMX page, create the page with name HelloClient.amx.



     Step 4 : Open the HelloClient.amx:


    Step 5 : Right click View Controller, Select New->From Galary-> Search Web service ->          select Web Service Data Control(SOAP/REST)(Data Controls).
 Following wizard will open :


Step 6 : Copy the web service created in first section( make sure to have IP address and not host name) , Name the data source as Hello_WL and paste the WSDL in URL field as shown below :

   

Step 7 : Drag Process into Left side and click Finish :

 

   Step 8 : After completion of wizard your data control should look as shown below :



Step 9 : Select sayHello(String) and drag it on to the page. Once you drop it Jdeveloper ask you for number of options. Select Method->MAF Button :


Step 10 : Keep arg0 as blank and click Ok:


Step 11 : Make sure following figure matches with your code :


We have just created a command button which will call the web service.


Step 12 : Now drag String on to the page and select details as shown below :

   In this step we created an Input box which accepts the value such as "Nakul" or "Peter" etc. That is it all development done.

  Step 13 :  Complete the deployment :


Let us check output now : click HelloWorldClientMAF


Set value in Input value field and click submit, if you get response as shown below, yes we have won our first battle.