Mar 26 2008

Gwt-Ext screencasts on showmedo.com

Tag: Ext,Gwt,Java,Programming,Ubuntu,WebAbhijeet Maharana @ 11:23 pm

In addition to hosting the Gwt-Ext screencasts at http://gwt-ext.com/screencasts/, Sanjiv has also made them available at showmedo.com. So you can watch them online without having to download first.

Here are the direct links:

  1. Setup GWT and Cypal studio in Eclipse on Ubuntu
    http://showmedo.com/videos/video?name=2040000;fromSeriesID=204

  2. Add Ext and Gwt-Ext to the project
    http://showmedo.com/videos/video?name=2040010&fromSeriesID=204

  3. Add basic client side regex validation, remote service and save form data in Oracle database
    http://showmedo.com/videos/video?name=2040020&fromSeriesID=204

Download Eclipse projects shown in the screencasts from Gwt-Ext.com or Rapidshare.

Thanks Sanjiv for the appreciation. And more importantly, for putting in lots of hard work to produce Gwt-Ext.


Mar 17 2008

Gwt-Ext screencasts for beginners

Tag: Ext,Gwt,Java,Javascript,Links,Linux,Maps,Programming,Ubuntu,WebAbhijeet Maharana @ 8:51 pm

I have started out with Gwt-Ext and thought I will record some screencasts. These are for beginners who may need a hand when they are starting out and are anxious to jump right into code. The screencasts have been recorded on Ubuntu Feisty with Eclipse Europa.

There are 3 screencasts in avi and ogg format.

  1. First screencast shows the installation of Gwt 1.4 and Cypal Studio for Gwt. Cypal Studio is an Eclipse plugin that automates most of the tasks associated with GWT like adding a module and adding a remote service. In the screencast, I create a Gwt project using this plugin.
  2. Second screencast shows how to add the ExtJS Javascript library (2.0) and Gwt-Ext Java library (2.0.1) to the project. In the screencast, I create a simple Ext form with some text fields and a button.
  3. Third screencast (added on March 22) shows how to send form data back to the server. In the screencast, I validate form fields using regular expressions / Ext Vtype, add a remote service and then save form data in an Oracle database using the remote service.

    You can read this post for installing Oracle 10g XE on Ubuntu Feisty.

All screencasts are hosted at Rapidshare. Sanjiv Jivan, the author of Gwt-Ext has offered to host them at gwt-ext.com. I think the files are quite big and I am not well-versed with audio/video formats and parameters. If you know any way to reduce file size while maintaining the quality of screencasts, do let me know.

Download screencasts from Rapidshare.
Download Eclipse projects shown in the screencasts from Gwt-Ext.com or Rapidshare.

Update:
Sanjiv has been kind to host them at http://www.gwt-ext.com/screencasts/.
I have also edited the gwt-ext wiki accordingly. (See comments)

Related links:
Google Web Toolkit
ExtJS Javascript library
Gwt-Ext
Cypal Studio for Gwt


Dec 22 2007

Oracle 10g XE + Java on Ubuntu Feisty

Tag: Database,Java,Linux,Programming,UbuntuAbhijeet Maharana @ 3:30 pm

I needed a basic database on my Ubuntu Feisty system and decided to try out Oracle 10g Express Edition. The installation is pretty straightforward. Below is a log of what I did to get it running along with Java code to access the database.

My Setup:

  • AMD 3600+ 64 bit running Ubuntu 7.04 32 bit
    (2.6.20-15-generic kernel)
  • 2GB RAM

Download the .deb file for Oracle Database 10g Express Edition for Linux x86. I have oracle-xe_10.2.0.1_i386.deb which is a bit old now. The official installation guide is located here.

The installation steps are as follows:

  • Step1: Requirements and installation
    In short: 1.5 GB of disk space, 512 MB of RAM with 1GB swap. The Express Edition can use a maximum of 1GB of RAM even if more is available. The minimum and recommended requirements for installation can be found here . The installation went fine on my machine with 2GB of RAM and no swap space.

    Run the .deb. You may need to be connected to the Internet for the dependencies. The installation creates shortcuts under the Applications menu. However, we don’t need to use any at the moment.

    screenshot

  • Step2: Configuring the database
    Run

    sudo /etc/init.d/oracle-xe configure

    Use the default settings for Oracle Application Express (8080) and the database listener (1521) or change the ports if you have other servers using these ports.

    Enter the SYS/SYSTEM password. I used ‘manager’.

    Select ‘n’ for the option for starting the database at boot time since we can conveniently do the same using the created menu items. [See the troubleshooting section below]

    screenshot

    The user starting or stopping the database must be a member of the ‘dba’ group. This can be done from [Gnome Menu] >> System >> Administration >> Users and groups >> Manage groups. Select ‘dba’ and click on properties. Select user(s) to add them to this group.

  • Step3: Administration using the web interface
    Log into Application Express by hitting the URL http://127.0.0.1:8080/apex
    Enter SYSTEM / [password you had entered earlier]. There is a built-in user account HR which needs to be unlocked before it can be used. But, we will create a new account for our use.
    Goto Administration >> Database users >> Create user
    Enter ‘scott’ / ‘tiger’ for the username / password and click Create.

    screenshot 1 | screenshot 2

    Log out and log in again as scott.

  • Step4: Create test tables
    Create a table

    • using the object browser
      Object browser >> create >> table

      screenshot 1 | screenshot 2

    • using a SQL Query
      SQl >> SQL Commands >> Enter Command
      You can enter multiple statements in the editor and execute one statement at a time by selecting a statement and hitting CTRL + ENTER.
      CTRL + ENTER works out of the box on Firefox 2.0.0.3. On Opera 9.24, you may need to change some settings. At this point I can’t say what.

      screenshot 1 | screenshot 2 | screenshot 3

  • Step5: Access database from Java

    Save the following code as OracleJdbcDemo.java. It prints values from the first column.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    import java.sql.*;
     
    public class OracleJdbcDemo
    {
    	public OracleJdbcDemo() throws Exception
    	{
    		Class.forName("oracle.jdbc.OracleDriver");
    		String connString = "jdbc:oracle:thin:@localhost:1521:XE";
    		Connection conn = DriverManager.getConnection(connString, "scott", "tiger");
    		Statement stmt = conn.createStatement();
    		ResultSet rs = stmt.executeQuery("select * from student");
    		while(rs.next())
    		{
    			System.out.println(rs.getString(1));
    		}
    	}
     
    	public static void main(String args[]) throws Exception
    	{
    		new OracleJdbcDemo();
    	}
    }

    Compile and run the code by supplying the ojdbc14.jar file in the classpath:

    $ javac OracleJdbcDemo.java
    $ java -cp "/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc14.jar":. OracleJdbcDemo

    If you have downloaded and installed a JDK yourself, make sure the compiler and interpreter are both from the same installation.
    I have JDK1.6.0 installed on my system and this is the entry in my /home/abhijeet/.bashrc

    export JAVA_HOME="/apps/java/jdk1.6.0"
    export PATH=${JAVA_HOME}/bin:${PATH}



Troubleshooting


I came across a situation where just after the installation everything worked fine but after a reboot, neither http://localhost:8080/apex nor the Java program worked. However, the database was starting and stopping from the menu options as I was able to connect using the “Run SQL Command Line” utility found in the menu. First few lines of the exception thrown by the program are shown below:

Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
...

I had answered “no” to start the database at boot time since I didn’t want it running when I am not using it. This may or may not be related to the problem above and I did not reinstall selecting “yes” to check.

After searching a little, this is what worked.
Register environment variables and start TNSLISTENER:

$ . /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh
$ sudo /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/tnslsnr

If you get the following error after the first command

/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 114: [[: not found
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh: 114: [[: not found

then edit /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh and change the first line from

#!/bin/sh

to

#!/bin/bash

Wait for sometime after starting the listener and both the web interface and Java program should start working.

[Reference: Oracle forums]


Oct 28 2007

Writing a gTalk (Jabber/XMPP) client in Java

Tag: Java,ProgrammingAbhijeet Maharana @ 12:17 am

Screenshot

From its Wikipedia entry, “Extensible Messaging and Presence Protocol (XMPP) is an open, XML-inspired protocol for near-real-time, extensible instant messaging (IM) and presence information (a.k.a. buddy lists). It is the core protocol of the Jabber Instant Messaging and Presence technology. The protocol is built to be extensible and other features such as Voice over IP and file transfer signaling have been added.”

There are a large number of XMPP server and client implementations and code libraries. We will use the Smack open source Java library to implement a simple client that can connect to any Jabber service. Google’s messaging service uses the same protocol and we will use it for the example.

Create a folder for your project. Create a “lib” subfolder.
Download the Smack library and extract the following files to the lib folder:

smack.jar

  • smackx.jar (for the extensions)
  • smackx-debug.jar (for the enhanced debugger)
    Debugger screenshots: 1 | 2 | 3 | 4

    As of this writing, the Smack API is in version 3.0.4 (build date: June 12, 2006). Create ChatClient.java and use the code snippets below for the methods of this class. You can also download the project files from the link at the end of this post.

    The code below shows how to connect to the gTalk service:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    // import org.jivesoftware.smack.ConnectionConfiguration;
    // import org.jivesoftware.smack.XMPPConnection;
     
    ConnectionConfiguration config = 
    	new ConnectionConfiguration("talk.google.com", 
    					5222, 
    					"gmail.com");
    connection = new XMPPConnection(config);
    connection.connect();
    connection.login(your_username, your_password);


    “talk.google.com” is the host. 5222 is the port number and “gmail.com” is the service name. Although they are different here but usually, the service name is same as the hostname. Let us now get hold of the buddy list:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    // import org.jivesoftware.smack.Roster;
    // import org.jivesoftware.smack.RosterEntry;
     
    Roster roster = connection.getRoster();
    Collection<RosterEntry> entries = roster.getEntries();
     
    System.out.println("nn" + entries.size() + " buddy(ies):");
    for(RosterEntry r:entries)
    {
    	System.out.println(r.getUser());
    }


    We can also send a message to a buddy by using the Chat class:

    1
    2
    3
    4
    
    //import org.jivesoftware.smack.Chat;
     
    Chat chat = connection.getChatManager().createChat(to, this);
    chat.sendMessage(message);

    The first argument is quite obvious. The second argument is an instance of a class that implements the org.jivesoftware.smack.MessageListener interface. This listener receives incoming chat messages and calls the interface method

    1
    
     public void processMessage(Chat chat, Message message)

    to process the message. We can now disconnect from the messenger service:

    1
    
    connection.disconnect();

    Thus, we have a bare-bones Jabber client. The complete program looks like this. You can download the project (see update below) with instructions on compiling and running it. It has a hard-coded username and password which will have to be changed. You will also need to enter the email address of your gTalk buddy before sending any message. The person you are trying to communicate with should already be in your buddy list.

    Update (10 July 2009):
    Check this out for SASL authentication errors: http://server.everfine.com.tw/blog/archives/2009/06/smack-api.html

    Update (30 December 2009):
    I no longer have a copy of the original project archive that I posted.
    However, a modified version is available here: http://groups.google.com/group/jujuyjug/files?pli=1

    Update (16 May 2010):
    Just stumbled across this excellent article on using the XMPP support in Google App Engine: http://gaejexperiments.wordpress.com/2009/09/25/gaej-xmpp-and-rolling-your-own-agent/


  • « Previous Page