Tuesday, February 23, 2010

Flex3 and Rest Webservices.

In our organization since we want leverage Oracle Bpel , i used Flex with Oracle Bpel Webserivces for creating Dashboards and other Rich Internet applications.

Recently i was developing REST webserivces for another project. it was very interesting...As we all know in flex3 we can only use the HTTP service for invoking a REST webservice.


The main reasons why i selected REST instead of BPEL to bind/post data on a flex page is

did not require an ws-security extensions..

did not require soap-header information..

am not willing to select an open source implementation for that project...


Tools required: Ganymede 3.4 and myclispse 7.5 installation (make sure it supports jsr311 implementation).

Framework: Jersey.

use case:

submit a form with firstname and last name and persist in a database

Step 1.


Create a POJO class ,annotate with @XmlRootElement


import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Employee{

private String firstName;
private String lastName;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}


public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

}

Step 2.

Create a Resource class



package com.prem.restservices;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

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


import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.sun.jersey.spi.resource.Singleton;

@Produces("application/xml")
@Path("empdetails")
@Singleton
public class CustomersResource {


String jdbcURL = "jdbc:oracle:thin:@hostname:port:SID";
String user = "username";
String passwd = "password";


public Connection getConnection() throws SQLException{

Connection conn;
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(jdbcURL, user, passwd);
return conn;

}

public CustomersResource() {
}



@POST
@Path("add")
@Produces("text/plain")
@Consumes("application/xml")
public String addEmployee(Employee employee) {

Connection conn = null;
PreparedStatement pstmt = null;

try {


conn = getConnection();

//Insert Data in your Database

} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
System.out.println("Exception in ad Employee" +customer.toString());
}finally{
try{
//Release Resources

}catch(Exception e){
//log in exception
}
}

return "employee " + employee.getFirstName() + " added";
}



Flex Code

mx:Script
![CDATA[
private function send_data():void {
userRequest.send();
}
]]

mx:Form x="22" y="10" width="493"
mx:HBox
mx:Label text="FirstName"
mx:TextInput id="firstname"
mx:HBox
mx:HBox
mx:Label text="LastName"
mx:TextInput id="lastname"
mx:HBox
mx:Button label="Submit" click="send_data()"
mx:Form



mx:HTTPService id="userRequest" url="Webservice URL" contentType="application/xml" showBusyCursor="true" useProxy="false"
mx:request xmlns=""
employee
firstName{firstname.text}firstName
lastName{lastname.text}lastName
employee
mx:request
mx:HTTPService

Saturday, February 13, 2010

Android/ JDBC

Hi,

This week i was able to develop an Android App to get data from an Oracle Database.

Here is my Code .


package com.prem.JDBCAndroid;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import android.app.Activity;
import android.database.SQLException;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;

public class JDBCAndroid extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

try {
String userName = getDataFromOraDB();
TextView tv = new TextView(this);
tv.setText(userName);
setContentView(tv);
} catch (SQLException e) {
Toast.makeText(this, e.getMessage(), 1).show();
} catch (ClassNotFoundException e) {
Toast.makeText(this, e.getMessage(), 1).show();
}

}

public String getDataFromOraDB() throws SQLException,
ClassNotFoundException {

String name = null;
String jdbcURL = "jdbc:oracle:thin:@hostname:portname:sid";
String user = "uname";
String passwd = "pwd";
// Load the Oracle JDBC driver

try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn;
ResultSet rs;
Statement stmt;
conn = DriverManager.getConnection(jdbcURL, user, passwd);
stmt = conn.createStatement();
rs = stmt.executeQuery("select USERNAME from SomeTableName");
if (rs.next()) {
name = rs.getString("USERNAME");
}
} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
System.out.println("the exception is" + e.toString());
}

Toast.makeText(getApplicationContext(), name, 1).show();
return name;
}

}





If you still have issues please check your AndroidManifest.xml file if it has the

below line

uses-permission android:name="android.permission.INTERNET"

TimeZone in Workbrain5.0.21

ETM_CLOCK_FACTOR_TIME_ZONE


Description: This parameter determines how an employee’s time zone is determined. When set to client_browser, the time zone is set by the user’s PC, although the actual date and time from the PC is not used.

When set to employee_udf, employee time zones are determined from stored values in the TIMEZONE table. If the employee does not have EMPLOYEE.TZ_ID set, then server time is used.

When set to False, all time zones are the same as the server.



Valid Values: client_browser, employee_udf, False

Default Value: False

Location: system/WORKBRAIN_PARAMETERS/

-Prem

Time out in Workbrain5.0.2.1

a.Application SessionTimeOut

This happens through registry setting

Select * from workbrain_registry where wbreg_name='timeout'



b. PageSession TimeOut


Application gives an option to the user to set their timeout on
specific pages (only sys admins can configure this.)


select * from workbrain_page gives the list of pages which are configured for a page level time out.

I changed this as we do not want this to be same as App time out for some business reasons.

A page session Time out takes Priority if it is less than Application TimeOut

-Prem

SQl Server Datasource Configuration/ORacle ESB

The below metalink note helps to configure a sql server datasource .

after which we can create a Database adapater

How To Setup Database Adapter Interfaces Using a Microsoft SQL (MSSQL) Server 2000 Database [ID 737497.1]


I was able to move the legacy data to an oracle ERP database through routing service of Oracle ESB


Thanks
Prem