Tuesday, August 11, 2009

GAE with jtwitter

Considerations:

A. You have active Google App Engine Account.
B. You have already created an application for this project in your Google App Engine Account.
C. You have already downloaded the "jtwitter.jar" from
http://www.winterwell.com/software/jtwitter.php



First add the plug in of GAE in your Eclipse. For that follow the below steps:


A. Open the Eclipse (mine was Eclipse Ganymede).

B. Go to Help -> Software Updates...

C. After opening the "Software Updates and Add-ons" window click on the button "Add Site...".

D. Put the address as per your flavor of Eclipse.

a) Eclipse 3.3 (Europa): http://dl.google.com/eclipse/plugin/3.3

b) Eclipse, for Eclipse 3.4 (Ganymede): http://dl.google.com/eclipse/plugin/3.4

c) Eclipse, for Eclipse 3.5 (Galileo): http://dl.google.com/eclipse/plugin/3.5


E. After clicking "OK" you can see the "Google Plugin for Eclipse" is on the list of "Available Software". Check on the Checkbox and click on the "Install" button.


It will install the plug in in the Eclipse now follow the below steps:


1. Open the Eclipse (mine was Eclipse Ganymede). Then go to File. Under the "File" click on the "New" then click on to the "Web Application Project".

This window will appear:




2. Fill up the form as per below screen-shot.



The Project Name is : "GAEproj" and Package is "packTwitt". We are not going to build this project with Google Web Toolkit, so please uncheck the "Use Google Web Toolkit". Also make sure your default SDK for this project is "App Engine". Now click on "Finish".

3. You can see the "GAEproj" is on your Package Explorer of Eclipse.

4. Right now we want to test this project at our local server.

5. Select the Project. Click on the "Build Project" under "Project Menu". It will build your project. Now go to "Run" Menu and choose "Run as", then select "Web Application".

6. Look into the console you can see the message "The server is running at http://localhost:8080". (Address may change according to your setting).



7. Open your browser and type the address mentioned on the console and you can see the below page.



This is the "index.html" file under the /war/WEB-INF/ folder.

8. Now click on the link "GAEproj". You will be navigated to this page which is the servlet "GAEprojServlet.java" under the package "packTwitt".




9. You have already downloaded the "jtwitter.jar" from the address http://www.winterwell.com/software/jtwitter.php. We have to add this .jar in our project. For that, select the project "GAEproj", right click on it and click to the "Properties". Select the "Java Build Path" in the left hand side navigation bar. Now click on the "Libraries" tab. Here you can find the button "Add External JARs...". Click on that and select the "jtwitter.jar" from your disk. Now click on "OK". The "jtwitter.jar" file is now included into our project.



10. ok, the project configuration has been done. Now we will move on to the coding section. Open the "index.html" file and modify the code like the below one.



Here, I have introduced a html form with the following properties:
name="ff" (don't ask why), method="POST", action="/gaeproj"

created two text fields one for UserID and another for Password, and finally a Submit button.

11. Open the "GAEprojServlet.java" file and modify the code like the below one.


Here, first and most important thing is I have changed the "doGet" method to "doPost" method because I have made the form method = "POST" in my "index.html" file. Now import "winterwell.jtwitter.*".

I've made an object 't' like this and pass the userid and password to the constructor.

Twitter t = new Twitter(req.getParameter("u_id"),req.getParameter("u_pass"));

By the method getStatus(String) I've print my last update on Twitter:

resp.getWriter().println(t.getStatus(req.getParameter("u_id")));

12. Build the project and Run. Enter your Twitter UserID and Password and click on "Submit".
You can see the last update in your Twitter account.

NB1: Make sure before login that your profile in Twitter is not Locked.

NB2: Refer the Twitter.class or jTwitter javaDoc for more exiting functions.

13. Its time for deploying the application in your GAE account. For that click on the "Deploy App Engine Project" in Eclipse (Right most icon in the below screen-shot).



An window will appear. Project Name is already there in our case it is "GAEproj". Now type your gmail address and password by which you have created an application in the GAE site.

Click on the "App Engine project settings...". Give the application ID as your application name in GAE site. As it is first time for you Revision should be 1. Click on "OK" and click on "Deploy". It will deploy your application to your GAE account.

Bang!!! Now you can show your own Twitter tricks to the whole world ....

Sunday, August 9, 2009

HOWTO : Setup Java Development Environment on Ubuntu

Packages to be installed: JDK 6, JRE 6, Eclipse (Ganymede – 3.4.2), Tomcat 6

A. Install JDK and JRE:

1. Open the terminal
2. Type sudo apt-get install sun-java6-jdk sun-java6-jre

It will install the JDK and JRE on your system.
Now you can check the version by typing javac -version

3. Set the $JAVA_HOME
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.10"


B. Install Eclipse:


1. Download the latest release of the Eclipse (In my case that was Eclipse Ganymede 3.4.2) from eclipse website. http://www.eclipse.org/downloads/packages/release/ganymede/sr2

2. Now extract the .tar.gz in your home directory
tar -xzvf eclipse-jee-ganymede-SR2-linux-gtk.tar.gz

3. To check the Eclipse is opening or not go to the /eclipse directory
cd eclipse

4. Now type the command ./eclipse
The eclipse will open. Now close the eclipse for the time being.


C. Time for Tomcat 6

1. download the copy of Tomcat 6 from apache website http://tomcat.apache.org/download-60.cgi .... it should be a .tar.gz under Core (in my case that was apache-tomcat-6.0.20.tar.gz)

2. Extract the .tar.gz in your home directory
tar -xzvf apache-tomcat-6.0.20.tar.gz

3. Now we have to move it to the /usr/local/tomcat directory. Type this command to do that:
sudo mv apache-tomcat-6.0.20 /usr/local/tomcat

4. Setup Tomcat to Boot on Startup
a) sudo nano /etc/init.d/tomcat

b) Copy and paste this script, making sure to either configure or remove CATALINA_BASE and CATALINA_OPTS:

------------------------------------------------------
#!/bin/bash

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export CATALINA_BASE=/path/to/catalina/base
export CATALINA_OPTS="-server -Xmx512m"
case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

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

c) Press Ctrl+X to exit, and answer Yes to save.


5. Now make the above script executable, and install it as a startup script:

sudo chmod 755 /etc/init.d/tomcat
sudo update-rc.d tomcat defaults


6. Type sudo /etc/init.d/tomcat start and your tomcat will be up.


So, your Java Environment is ready to rock with your code!!!!!

Friday, August 7, 2009

Nokia Phone Modem Internet connection in ubuntu

There are two ways to do that:


For newbies:
  • 1. Connect your phone to the PC via USB.
  • 2. Select “PC Suite” in phone.
  • 3. Ubuntu will detect your phone
  • 4. Click on the Configure button and a window will appear, click on “Forward” then you can see names of Mobile Connection Provider. If you can see your Mobile Connection Provider is on the list, select that one. If your Mobile Connection Provider is not on the list (like in my case - AirCel) then select any one of them (I choose AirTel).

NB: If your Mobile Connection Provider is not on the list then please follow the steps from 6 to 10.

  • 5. Click on Finish
  • 6. Go to the Network icon and right click on that and then click on “Configure/Edit Connection”.
  • 7. It will leads you to a window. Go to the "Mobile Broadband" tab and select the Connection name (in my case it was "Airtel") and then Click on "Edit".









  • 8. Then the below screen will appear:
  • 9. Now you have to customize these properties as your Connection Provider. (In my case I changed the APN only).
  • 10. Change the Connection Name as you like. Press “OK”.
  • 11.Now click on the network icon and select the connection name what you have gave.
  • 12. That’s it……. connected!!!
For Terminal Lovers:


  • 1. Connect your phone to the PC via USB.
  • 2. Select “PC Suite” in phone.
  • 3. Go to Terminal
  • 4. type "lsusb"
  • You will get like this:
  • Bus 001 Device 004: ID 0421:00e9 Nokia Mobile Phones
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  • 5. sudo /sbin/modprobe usbserial vendor=0x0421 product=0x00e9
  • The Vendor ID and Product ID must match with the result of "lsusb"
  • 4. sudo wvdialconf /etc/wvdial.conf
  • 5.you may find this:
  • ttyS0<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud

    ttyS0<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud

    ttyS0<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.

    Modem Port Scan<*1>: S1 S2 S3

    WvModem<*1>: Cannot get information for serial port.

    ttyACM0<*1>: ATQ0 V1 E1 -- OK

    ttyACM0<*1>: ATQ0 V1 E1 Z -- OK

    ttyACM0<*1>: ATQ0 V1 E1 S0=0 -- OK

    ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK

    ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK

    ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK

    ttyACM0<*1>: Modem Identifier: ATI -- Nokia

    ttyACM0<*1>: Speed 4800: AT -- OK

    ttyACM0<*1>: Speed 9600: AT -- OK

    ttyACM0<*1>: Speed 19200: AT -- OK

    ttyACM0<*1>: Speed 38400: AT -- OK

    ttyACM0<*1>: Speed 57600: AT -- OK

    ttyACM0<*1>: Speed 115200: AT -- OK

    ttyACM0<*1>: Speed 230400: AT -- OK

    ttyACM0<*1>: Speed 460800: AT -- OK

    ttyACM0<*1>: Max speed is 460800; that should be safe.

    ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK



    Found an USB modem on /dev/ttyACM0.

    Modem configuration written to /etc/wvdial.conf.

    ttyACM0: Speed 460800; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"

  • 6. To see the conf file type "cat /etc/wvdial.conf" and you may find this:
  • [Dialer Defaults]

    Init1 = ATZ

    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0

    Modem Type = USB Modem

    ; Phone =

    ISDN = 0

    ; Password =

    New PPPD = yes

    ; Username =

    Modem = /dev/ttyACM0

    Baud = 460800

  • 7. Now we have to edit this wvdial.conf file according to our Service Provider. I've edited my file just like this:
  • a) uncomment the below line and put target phone no in it like *99#

    ; Phone =

  • Phone = *99#
  • b) uncomment the below line and don't keep it blank, put anything like:

  • ; Password =

  • Password = A
  • c) uncomment the below line and don't keep it blank, put anything like:
  • ; Username =

  • Username = B
  • d) Add the below line:
  • Stupid Mode = 1
  • 8. Type "sudo wvdial" and get connected!!!