Category Archives: AJAX

Implementing Gmail-alike Web Mail Client by Java2Script

WeMail, this to-be-implemented Gmail-alike web mail client, is based on technologies of Java, SWT, JavaMail and Java2Script.

Before going into designing and implementing details, here are some background information.

Java2Script (J2S) Pacemaker provides an Eclipse Java to JavaScript compiler plugin and an implementation of JavaScript version of Eclipse Standard Widget Toolkit (SWT) with other common utilities, such as java.lang.* and java.util.*. You can convert your SWT-base Rich Client Platform (RCP) into Rich Internet Application (RIA) by Java2Script Pacemaker.

JavaMail is a Java API used to receive and send email via SMTP,POP3 and IMAP. JavaMail is built into the Java EE platform, but also provides an optional package for use in Java SE.

SWT is an open source widget toolkit for Java designed to provide efficient, portable access to the user-interface facilities of the operating systems on which it is implemented.

Google Web Toolkit (GWT) is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files.

Why implementing another Gmail-alike web mail client?

When GWT is released, lots of developers ask whether GWT will be used in Google’s major products, like Gmail, Google Reader or other products. Yeas went by, but there is still no Gmail powered by GWT. So using Java-to-JavaScript technology to build another Gmail web client should be fun for technical geeks. I choose Java2Script to build this web mail client, hoping it would help improving Java2Script toolkit.

I like Gmail UI, but I can not use its UI for other mail providers, like Hotmail or Yahoo! Mail. So I believe WeMail will help users doing their email jobs like receiving, composing and replying emails, in Gmail-alike UI for all mail providers. And it will sure increase their daily email processing efficiency.

And there are lots of companies that might block web access to Gmail, Yahoo! Mail or other mail providers. In these cases, a web mail client for general POP/IMAP & SMTP will help those users accessing emails even behind firewalls.

So I finally made up my mind to build it. And it was my two weeks’ fun.

Dang, dang, dang! Here it comes WeMail – Web Mail Client for Gmail/Hotmail/Live Mail/Yahoo! Mail/AOL Mail.

Configureing mail servers and login:
wemail-web-login

WeMail main window, listing emails:
wemail-list

Viewing an email:
Click for large view of wemail-message-viewer

Composing an email:
wemail-composing

How is this Gmail alike web mail client being implemented?

I use WindowsBuilder Pro (formerly known as SWTDesigner) to design all the UI elements. Here are screenshots of its UI components being designed:

Overview of WeMail in designer:
wemail-design-overview

Designing top menu bar:
Click for large view of wemail-menubar

Designing logo and search bar:
wemail-toolbar

Designing left side widget:
wemail-widget

Designing email selector bar:
wemail-selector

Designing email message header:
wemail-mail-header

Designing email message viewer:
wemail-viewer

Designing email composer:
wemail-composer

Designing footer panel:
wemail-footer

Designing login window:
wemail-login-window

Designing mail server configuring window:
wemail-configure-window

Designing and adjust user interfaces causes lots of time.

And what about the receiving and sending emails? I use JavaMail to do email jobs. Between SWT UI and JavaMail, Java2Script’s Simple RPC technology is used. Those mail jobs are separated into following RPCs:
1. CheckMails
2. DiscardEmails
3. FetchMailContent
4. ListFolderMails
5. MarkMailAsRead
6. SaveDraft
7. SendMail

UI events will trigger those RPCs being called in separate threads and UI will be updates after their jobs are done.After RPCs get woven into UI elements. It is ready to be run as a native Java desktop application. So it is:

wemail-desktop

Running, debugging, testing, bug-fixing, all take times. But up until now, all I do is native Java developments. No HTML, no JavaScript technologies is needed.

After the Java desktop version of WeMail is OK, it will be ready for being converted in an AJAX based web browser application. That is the Java2Script job (I am not going into Java2Script details, more information can be found on Java2Script at Sourceforge.net.): Install Java2Script Eclipse plugin and convert existed project into a Java2Script project. All those *.java files will be compiled int JavaScript automatically. Then pack all necessary files into a Servlet *.war file and deploy it into Java Servlet container server like Tomcat. And work is done. WeMail is available at http://webuzz.im/mail/ .

So it is my WeMail’s development log. Having fun.

Posted in AJAX, Java, Java2Script | Tagged , , , , , | 5 Comments

Challenging Myself: Find 1st k-Digits Prime Number

Here is a task to challenge myself: Find the first k digits prime number. And k would be 16, 32, 64, 256, 1024, 8096, 65536, or even bigger.

And the most challenging thing would be most of key calculations will be performed in JavaScript engine hosted inside browsers. And a distributed algorithm will be designed. Algorithm which is similar to Google’s Map/Reduce will be designed. And Apache Hadoop’s Map/Reduce is also in references.

Any comments about this challenge? Or join me to design the algorithm! Or join the distributed computing game.

Keep tuned for how big the number k would be!

PS: After searching around Internet for existed prime number theories, I find out that k=16 is already a challenge for me! There are algorithms to find prime number in format of 2^p+1, whose digits may be bigger than 1000000. But there are not the 1st k-digits algorithms. According to theories, I should have to find out all prime numbers less than given n. But the count of prime numbers less than n is about n / ln (n), which is huge number already for k=16! So my first challenge would be 16.

Posted in AJAX, Challenge, Java, JavaScript | Comments Off on Challenging Myself: Find 1st k-Digits Prime Number

Google Talk Client’s Java SWT Desktop Copy

Actually, Google Talk Client’s Java SWT desktop copy is the original source for Google Talk Client’s JavaScript copy.

And now it is available for download. Please take a trial.

Sources of Java2Script Google Talk will be available in the next week. Keep tuned.

Posted in AJAX, Google Talk, Java, Java2Script | 8 Comments

Google Talk Client’s JavaScript Copy

http://demo.java2script.org/gtalk/

Here is the screenshot:

Click for Large Screenshot: Google Talk Client’s JavaScript Copy

En, in beta …

Posted in AJAX, Google Talk, Java2Script | 5 Comments

Ridiculous mod_jk Problem with Flush Method

I am writing Java2Script’s Google Talk, and it uses a mode of continuation (also known as “Comet” application). In order to implement continuum data transfer between browser and server ( Tomcat in the backend ), I kept the HTTP connection blocked waiting for data to be available. In the middle, Apache httpd server is used and mod_jk is used to connect the two server.

But I met a ridiculous problem between servlet container and http server. When the browser is assigned to connect servlet directly, it can obtain data from the connection, but it can not obtain a bit when it is piped through Apache httpd server.

I tried to add “Transfer-Encoding: chunked” or “Content-length: 0” but with no helps. And I modified jk.conf with “JkOptions +FlushPackets”, still with no helps. Finally, I remove a line of “writer.flush();” from my servlet source, and things all went correctly.

The line of “writer.flush();” was located in the the line when there is no data written to the response. And I considered that when there are no data in the response, calling flush method will hang mod_jk connector up. And the whole later data transfer will be disturbed.

More details about mod_jk, I recommend you to read “Tunning apache and tomcat for web 2.0 comet application“.

Update:
Finally I found out that “JkOptions +FlushPackets” works for me. #flush method problem is a fake problem. Only after I restart both Tomcat and Apache server do “JkOptions +FlushPackets” begin to work.

Posted in AJAX, httpd, Tomcat | Comments Off on Ridiculous mod_jk Problem with Flush Method