Ridiculous mod_jk Problem with Flush Method

July 29th, 2007

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.

Busy Days on Java2Script Google Talk

July 29th, 2007

Ya, these days were very busy.

I had spent more than a month on rewriting Java2Script Google Talk. And today, it was almost finished. You can check it out right now.

More works are required to make it robuster and faster. Maybe Java2Script Google Talk will be publicly released in the next week.

And next release of Java2Script is on the way too. It will be a 1.0.0 RC release. Four months was a long long time since last release.

Executing is VERY Important

July 17th, 2007

Finally, I realized that ideas is much less important than executing.

You may have some brilliant ideas, but you can’t work it out? Or you can’t make your guys to work it out in a short time? You ideas will wane away.

Colleague is much important for both company’s future and one’s job career. To choose a company, one must also take partners as a factor that one should consider.

Smart people should not spend their times trying to fix the bugs left by normal or dummy people. Or your times will be wasted.

Transferring Data Between Two Human Minds

July 1st, 2007

In Steve Pavlina’s article 10 Weaknesses of Human Intelligence, he mentioned one thing:

Poor networking capabilities - Transferring data between two human minds is slow, tedious, and error-prone, and the protocols are beyond confusing. It’s a safe bet that Microsoft is involved.

It is not mentioning “Microsoft” the reason I quoted his thoughts. I think not only Microsoft is trying to improve the capabilities for transferring data between two human minds, lots of other companies are also devoting in such works. For example, QQ (tencent.com in China), MSN, AOL, Google Talk and other instant messenger company are trying to help people communicate with each other. And these days, lots of social network websites are online helping people to have a better relationship online or offline. I could say that this is a big direction for IT future.

And I am thinking about in which ways there are needs of innovations for transferring data between two human minds. IMHO, some big companies may already be on their ways.

QT Jambi

June 21st, 2007

I just tested QT Jambi. It is cool of QT widgets in Java. I like it. And it is very fast and the QT Designer is good but not as good as WindowBuilder Pro’s SWT Designer, IMO.

But there is a nasty bug for QT Jambi integration with Eclipse. QT Jambi will add a com.trolltech.qtjambi.juicBuilder to each projects in my workspace. And these modifications will mark all of my projects as SVN modified. I have to disable it and restore all my .project files! This bug is really nasty!

Failed to Download Files from FTP Servers

June 21st, 2007

Today, I came across a problem: I could not download files given by “ftp://…”. I could ping that server, but could not link to it. I was using FlashGet and I tried to change some preferences but didn’t work. At last I turned off my Windows XP’s firewall and downloading worked at once. At later, I re-open the firewall and add my FlashGet or Filezilla to the trusted applications list.

Why Java Web Start Sucks

June 14th, 2007

Just have a long waiting time for downloading the *.jar files, and always it comes to a security dialog notifying that the *.jar file is not signed or not signed by known CA while it requires unlimited local access and remote connection access!

How can I accept “Unlimited local access and remote connection access” for unknown *.jar application! Java Applet or Java Web Start really sucks.

Subversive Sucks

June 11th, 2007

There are many bugs in Subversive besides the known bug “Can not compare with old deleted repository resources“.

And yesterday, one of my colleague used Subversive’s “Check out as” to a different location resulted in deleting all her one-week modifications. I think it was a bug that Subversive did not warn her that it was going to delete modified sources in “Check out as” mode!

In my experience, I found Subclipse is a much better plugin. So Subversive sucks.

Add Source Highlighting to Wordpress Editor

June 9th, 2007

If you are a technical geek, you may want to write some blog articles attaching some sources for discussion. And if you are using Wordpress, you may find a lot of difficulties in struggling with Wordpress’ messy TinyMCE editor in preserving codes format.

Thanks for early Wordpress bloggers, there are some plugins trying to solve this problem. A known plugin is “Preserve Code Formatting“. But that plugin may be not good enough for you, at least not good enough for me.

I modify that plugin a little, and deploy it in my Wordpress 2.2. And I also add my own source syntax highlighting tools.

Here is my modified preserve-code-formatting.php:

<?php
/*
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

function c2c_prep_code( $text ) {
$use_nbsp_for_spaces = false;

$text = preg_replace("/(\r\n|\n|\r)/", "\n", $text);
$text = preg_replace("/\n\n+/", "\n\n", $text);
$text = str_replace(array("&#36&;", "&#39&;"), array("$", "’"), $text);
//$text = htmlspecialchars($text, ENT_QUOTES);
$text = preg_replace("/\n\s+\n/", "\n&#160;\n", $text);
$text = str_replace("\t", ' ', $text);
if ($use_nbsp_for_spaces) $text = str_replace(' ', '&#160;&#160;', $text);
// Change other special characters before wptexturize() gets to them
$text = c2c_anti_wptexturize($text);
//$text = nl2br($text);
return $text;
} //end c2c_prep_code()

// This short-circuits wptexturize process by making ASCII substitutions before wptexturize sees the text
function c2c_anti_wptexturize( $text ) {
$text = str_replace('—', '&#45;&#45;-', $text);
$text = str_replace('–', '&#45;-', $text);
$text = str_replace('…', '&#46;..', $text);
$text = str_replace('“', '&#96;`', $text);

// This is a hack, look at this more later. It works pretty well though.
$cockney = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round");
$cockneyreplace = array("&#39;tain&#39;t","&#39;twere","&#39;twas","&#39;tis","&#39;twill","&#39;til","&#39;bout","&#39;nuff","&#39;round");
$text = str_replace($cockney, $cockneyreplace, $text);

$text = preg_replace("/’s/", '&#39;s', $text);
$text = preg_replace("/’(\d\d(?:&#8217;|’)?s)/", "&#39;$1", $text);
$text = preg_replace('/(\s|\A|")\'/', '$1&#39;’, $text);
// $text = preg_replace(’/(\d+)”/’, ‘$1"’, $text);
$text = preg_replace("/(\d+)’/", '$1&#39;', $text);
$text = preg_replace("/(\S)’([^’\s])/", "$1&#39;$2", $text);
// $text = preg_replace(’/(\s|\A)”(?!\s)/’, ‘$1"$2′, $text);
// $text = preg_replace(’/”(\s|\S|\Z)/’, ‘"$1′, $text);
$text = preg_replace("/’([\s.]|\Z)/", '&#39;$1', $text);
$text = preg_replace("/ \(tm\)/i", ' &#40;tm)', $text);
$text = str_replace("”", '&#39;&#39;', $text);

$text = preg_replace('/(d+)x(\d+)/', "$1&#120;$2", $text);

$text = str_replace("\n\n", "\n&#160;\n", $text);
return $text;
} //end c2c_anti_wptexturize()

function c2c_preserve_code_formatting( $text ) {
$text = str_replace(array('$', "’"), array('&#36&;', '&#39&;'), $text);
$tags = array('code', 'pre');
foreach ($tags as $tag) {
$text = preg_replace(
"^(<$tag>)\n?([\S|\s]*?)\n?(</$tag>)^ie",
"’<$tag>’ . c2c_prep_code(\"$2\") . ‘</$tag>’",
$text
);
}
$text = str_replace(array('&#36&;', '&#39&;'), array('$', "’"), $text);
return $text;
} //end c2c_preserve_code_formatting()

add_filter('the_content', 'c2c_preserve_code_formatting', 9);
add_filter('the_excerpt', 'c2c_preserve_code_formatting', 9);
// Comment out this next line if you don’t want to allow preserve code formatting for comments.
add_filter('get_comment_text', 'c2c_preserve_code_formatting', 9);

?>

And here is my css style:

.code {
overflow:scroll;
overflow-y:hidden;
background-color:#f0f0f0;
}

code {
white-space: pre;
color: #222;
}

.keyword {
color:blue;
}
.api {
color:navy;
font-weight:bold;
}
.scope {
color:#f0f;
}
.string {
color:green;
}
.comment {
color:#777;
}
.tag {
color:#f70;
}

And here is the instruction to add my source highlighting when editing:
1. Go to visit http://demo.java2script.org/syntaxor/ , and you can highlight your sources there;
2. Copy the link at left upper corner, which started by a blue block;
3. Bookmark any page, and then modify the bookmark’s URL property to the above link location (a “javascript:” link to load source syntax highlighting);
4. Try to write or edit a post in browser, and then click the above bookmarked link, and the same source highlighting application window shows up after a while, try to paste your highlighted HTML source in the wordpress’ TinyMCE editor.

Get Projects List in Eclipse Workbench

June 8th, 2007

http://dev.eclipse.org/newslists/news.eclipse.newcomer/msg13300.html

Add
org.eclipse.core.resources
in the Require-Bundle section in your plugin MANIFEST.MF file
and invoke code:

ResourcesPlugin.getWorkspace().getRoot().getProjects()