Wednesday, June 27, 2012

Part II: Mobile Application with REST services

Application Download: https://www.dropbox.com/s/7d0k9cqhf2sqhoj/MobileApp.zip 


Use Case Scenario

This is part II of the “Verify User – JSON REST API” we created and previously deployed. This is just a simple HTML5 jQuery mobile application wrapped as a standard J2EE application and deployed onto the same server as the REST service.

It is a simple login page that invokes the REST service to determine whether the user is authenticated or not. It doesn’t encrypt/decrypt the password. It’s just to demonstrate that you can leverage these REST services in any type of application. We could easily use this same REST service in our ADF portal application or a standard portlet. It doesn’t matter …

In this application you can enter any user in the HR schema Employees table with the password “welcome1” and it will authenticate. In this demonstration we’ll use SKING (mixed case works fine). If authentication fails it takes them to an ERROR dialog page (still inside the same page). If it passes the user is taken to a private page “welcome.jsp” (This is not really protected).

If you’ve kept up with ADF Mobile the next release (PS6) is supposed to support a better HTML5, JQuery, PhoneGap, etc. etc. to provide a quicker template solution for mobile development within the ADF techstack.

Part II: The Mobile App

I started out by creating a “Generic Application” and a “Generic Project” with Java, JSP and Servlet technology added to it.



I created a couple of standard JSP pages:
  • Login.jsp
    • I’m using a standard HTML5 JQuery Mobile template layout to leverage multiple display sections in a single page. If you look through the code you’ll notice:
      • Main Content
        • This is my main page displayed to the user and has the username, password, and submission button.
      • Content Dialog
        • This is the dialog section that notifies the user that there was an issue with their login. Once they return to the main content the fields that are required are highlighted.
      • Content Error Dialog
        • This is the dialog section that notifies the user that there was an issue with their login. If the user is not found they must enter the username/password again.
      • Content Transition
        • If your REST service takes a while (this shouldn’t) this portion of the content will display with an animated gif to show the user the transaction is in progress.
  • /priv/welcome.jsp
    • This is a standard page that lets the user know that the login was successful and they can log out if they wish to do so.
Below is a screenshot of the application layout.


Once you deploy the application you should be able to run it using the URL below:

http://localhost:7101/MobileApp/login.jsp

Tuesday, June 26, 2012

Part I: Verify User – JSON REST API

Untitled Document
Application Download: https://www.dropbox.com/s/s7csgy8svcij3aj/VerifyUserJson.zip

Use Case Scenario

I wanted to be able to invoke a REST service from an application (regardless of it being ADF Mobile, ADF portal, BPEL, or a standard HTML5 JQuery Mobile app). So I built the sample application (using JDev 11.1.2.1) as a JSON REST app using JAX-RS Jersey and standard J2EE. This was deployed to my standalone WebLogic 10.3.5 server. I created a standard J2EE mobile application (using JDev 11.1.1.5 … coming in PART II) to invoke and consume the REST service. Both were deployed to the same server so they could leverage the same domain name. I will discuss more about why they need to be on the same domain (in PART II when we build the mobile app).

Part I: VerifyUserJson App

In JDev 11.1.2.1 they’ve built in support for REST Web Services projects. So we’ll go ahead and use this version of JDEV. We’re still able to package and deploy the application on a standard 10.3.5 instance of WebLogic because we include the .jar libs in our WEB-INF/lib folder (included in the sample app).


After that I created three Java classes (LoginRequest, LoginRequestHandler, and DataHandler).
  • LoginRequest()
    • This java class has the main verifyLogin method which accepts a username and password as input parameters. It returns either true or false back to the calling method.
  • LoginRequestHandler()
    • This is method invokes the LoginRequest method and returns the response as plain/text. You can also return application/xml or application/json depending on how you want to display it in your application. I also used the GET HTTP method to retrieve the “stuff” from the resource.
  • DataHandler()
    • Method to get the connection to the ORACLE XE database for the HR Schema. You can change this to point to any database that has the HR SCHEMA.
We need to modify the web.xml file to include the JERSEY servlet and servlet mapping.We open the web.xml and add these lines of codes before the closing </web-app>

1:   <servlet>  
2:    <servlet-name>jersey</servlet-name>  
3:    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>  
4:    <load-on-startup>1</load-on-startup>  
5:   </servlet>  
6:   <servlet-mapping>  
7:    <servlet-name>jersey</servlet-name>  
8:    <url-pattern>/jersey/*</url-pattern>  
9:   </servlet-mapping>  

I added these .jar libs to my WEB-INF/lib folder so that I don’t have to worry about matching any of the versions on the application server. Here is a list of the libs in the screenshot below. They are also attached to the code in this blog post. Your application structure should look similar to this: You can test the LoginRequest by running it locally in your JDev (main method) before you deploy it to your
 WebLogic server.



After I deploy the application to server we can test it by invoking this URL with the appropriate parameters.

1:  http://localhost:7101/VerifyUserJsonApp/jersey/verifyUser?p_username=SKING&p_password=welcome1  

If you have any suggestions or comments please let me know.

Monday, June 25, 2012

Oracle EMG Samples

If you've been looking for a collaboration of all of the undocumented samples in one place here is the place to go:

http://java.net/projects/smuenchadf/pages/ADFSamples#Categories

This was tweeted earlier by Frank Nimphius.

Be sure to bookmark it and re-tweet! You can follow me @ADFDeveloper !

Welcome to my Oracle ADF/Fusion Middleware Blog

I've been working with Oracle technologies for 7 years now. I started out learning Oracle database tables, pl/sql, reporting, etc. I moved into the Portal (OracleAS 10g Portal) early in my career building custom applications with PL/SQL portlets. Since my main IT background was in web development, portal development came natural to me. I was able to create nice looking portal applications that looked nothing like the standard Oracle blue and beige colors that most were use to.

I went into consulting shortly after that to expand my skill-set and knowledge of the up-and-coming Fusion Middleware that Oracle was releasing. During my consulting days my knowledge of Java expanded and I was exposed to JSR-168 portlet development, ADF 10g, and mobile development. After dabbling in ADF for a while I knew that was the technology I wanted to gain exposure to so I joined Keste, LLC. Keste specialized in Fusion Middleware Architecture. My first project was SunGard. It was one of the first implementations of the expanded Fusion Middleware tech-stack.

I worked with a team that built a complete custom ADF 11g portal that was integrated with OAM, OIM, UCM (content), and a third party SalesForce.com application. We were able to deliver the application within 4 months. It was a pretty successful project and I gained a ton of knowledge working on it.

After that I was working on a 10g ADF portal migration to ADF 11g PS2 portal for WindRiver. This was a daunting task to say the least. It was a portal built on the spring framework with EJBs. After the migration was completed we were tasked to build a completely custom portal application that would replace Oracle iSupport and Oracle Tele-Service by combining a lot of the features a in a clean ADF rich UI interface. This project used ADF BC for the model implementation with the integration interfaces coming from PL/SQL packages wrapped and exposed as web services.

After these successful launches I was recruited by an old boss to come and work at his new company to help implement a fusion middleware architecture to replace their point-to-point integrations. I will be posting some of the proof-of-concepts that I've built in hopes to help others in the webcenter / adf / mobile development field.

... More to come soon!