Archive

Archive for October, 2008

Http Servlet Debug Filter

October 27th, 2008 No comments

If you have programmed any considerably sized Java web application, chance that you wrote some debug statements to dump what’s coming over wire as request and going out as response. Next time you run into such requirement, well, save some typing and use this Http Servlet Debug Filter.

This is simple jar file which you need to add to the WEB-INF/lib folder and it logs the Servlet Request and Response details to the log file. Optionally (by specifying a parameter) it also returns the debug to the browser as commented html so it can be be seen via “View Source” browser command.

Here is the sample response from the filter.

<!--
================= Start of Http Servlet Request (968784) =================
-----------------------------------------------------------------
From and Time
-----------------------------------------------------------------
Time: Mon Oct 27 23:27:31 PDT 2008
IP: 127.0.0.1
Host: 127.0.0.1

-----------------------------------------------------------------
Servlet Values
-----------------------------------------------------------------
AuthType: null
CharacterEncoding: null
Class: org.apache.coyote.tomcat5.CoyoteRequestFacade
ContentLength: -1
ContentType: null
ContextPath: /hdf
Locale: en_US
Method: GET
PathInfo: null
PathTranslated: null
Protocol: HTTP/1.1
QueryString: hdf.debugToClient=true
RemoteUser: null
RequestedSessionId: 221e7c81176e8af317081378f143
RequestURI: /hdf/index.html
RequestURL: http://localhost:8080/hdf/index.html
Scheme: http
ServerName: localhost
ServerPort: 8080
ServletPath: /index.html
Session: org.apache.catalina.session.StandardSessionFacade@110f850
UserPrincipal: null

-----------------------------------------------------------------
Servlet Parameters
-----------------------------------------------------------------
hdf.debugToClient=true

-----------------------------------------------------------------
Servlet Attributes
-----------------------------------------------------------------
com.sun.enterprise.http.sessionTracker=org.apache.coyote.tomcat5.SessionTracker@87c801

-----------------------------------------------------------------
Session Details
-----------------------------------------------------------------
Id: 222bab8d43997024f4d6051542f5
CreationTime: 1225175251640
LastAccessedTime: 1225175251640
MaxInacctiveInterval: 1800
<no session attributes>

-----------------------------------------------------------------
Servlet Cookies
-----------------------------------------------------------------
name=JSESSIONID, value=221e7c81176e8af317081378f143, domain=null, path=null, maxAge=-1, version=0, secure=false, coment=null

-----------------------------------------------------------------
Servlet Locales
-----------------------------------------------------------------
en_US
en

-----------------------------------------------------------------
Raw Http Headers
-----------------------------------------------------------------
host=localhost:8080
user-agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
accept-language=en-us,en;q=0.5
accept-encoding=gzip,deflate
accept-charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7
keep-alive=300
connection=keep-alive
referer=http://localhost:8080/hdf/
cookie=JSESSIONID=221e7c81176e8af317081378f143
if-modified-since=Tue, 28 Oct 2008 06:26:35 GMT
if-none-match=W/"398-1225175195890"
cache-control=max-age=0
================= End of Http Servlet Request ===================
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>
<body>
<h5>Debug <a href="index.html?hdf.debugToClient=true">page</a> to test the Http Servlet debug filter.  View source to see the details.</h5>
</body>
</html>

<!--
================= Start of Http Servlet Response (968784) =================
Time: Mon Oct 27 23:27:31 PDT 2008
Status: -1
CharacterEncoding: ISO-8859-1
ContentLength: 398
ContentType: text/html;charset=ISO-8859-1
Locale: en_US

-----------------------------------------------------------------
Session Details
-----------------------------------------------------------------
Id: 222bab8d43997024f4d6051542f5
CreationTime: 1225175251640
LastAccessedTime: 1225175251640
MaxInacctiveInterval: 1800
<no session attributes>

-----------------------------------------------------------------
Set Cookies
-----------------------------------------------------------------
<no cookies>

-----------------------------------------------------------------
Set Http Headers
-----------------------------------------------------------------
ETag=W/"398-1225175249921"
Last-Modified=Tue, 28 Oct 2008 06:27:29 GMT
================= End of Http Servlet Response ===================
-->

Installation

1. Download the jar file (here is the source)
2. Add the jar file to the WEB-INF/lib folder
3. Add the following filter mapping to your web.xml

	<filter>
		<filter-name>hdf</filter-name>
		<filter-class>com.brsanthu.hdf.HttpDebugFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>hdf</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

4. You can also download pre-packaged war file, which can be deployed and accessed via “http://localhost:8080/hdf/index.html?hdf.debugToClient” (change the server/port accordingly)

Attached source code is released as is without any warranty and you can use/modify the source as you required.

Let me know if you have any suggestions.

Syntax highlighting in WordPress

October 26th, 2008 No comments

If you are writing technical blogs, it is apparent you would need to post some source code of some language at sometime or the other. Posting code with no syntax coloring works fine but coloring makes code goes easy on eyes and to understand it faster.

The tool of choice I prefer for blogging is Syntax Highlighter. It is completely client side so server won’t be burden with extra work of syntax highlighting the code and it looks pretty on page.

Many blogging engines provides their own set of tags which enables to do syntax highlighting. If you are hosting a blog in Wordress.com you can use the the sourcecode tag.

If you are hosting your own blog using WordPress engine, you are not luck as it doesn’t support sourcecode tag. Not to worry, there are some great options to highlight your code. Out of many available options, I prefer Syntax Highlighter Plus wordpress plugin. It works out of the box and you can just paste the complete code as is without worry about converting the < and > characters.

However one issue I had with it was the width of the code window it renders. By default it uses around 530 pixes, which may be little small if you have wide width blog layout as mine. Solution is pretty simple. After installing the plugin, open

wp-content/plugins/syntaxhighlighter-plus/shlfiles/SyntaxHighlighter.css
&lt;/pre&gt; and edit the 
&lt;pre&gt;.dp-highlighter

class with desired code width. The code window used in this site uses 750px.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}
Categories: All, Web, Wordpress Tags: , ,

Events Map

October 26th, 2008 No comments

For friend of mine I created a events map based on the google maps API (original idea credit goes to Virender Ajmani), which takes a data file with set of events and shows the events details on map as slide show. For ex., here is event map created with my major lifetime events.

Here is the direct url for the html and js file.   I have completely separated the data elements from the scripting elements so you can use the event map out of box with your own data file without any modifications to html/js file (except changing the Google Map API Key). The event map accepts following parameters.

  • datafile => the url to the data file containing all events
  • ap => 1 or 0 indicating if events should start autoplay or not
  • h => height of the map
  • w => width of the map

Data file itself can be very easily constructed.  Here is the data file with couple of events.

<?xml version='1.0' standalone='yes'?>
<events>
	<defaultthumbnail>http://www.brsanthu.com/map/santhosh.jpg</defaultthumbnail>
	<defaultzoom>7</defaultzoom>
	<event>
		<name>Born in Doddachellur, Karnataka</name>
		<place>Chitradurga, Karnataka, India</place>
		<desc><![CDATA[Bon on 14th Oct to Rudramuniyappa and Sowbhagyamma]]></desc>
	</event>
	<event>
		<name>High school in Malladihalli</name>
		<place>Holalkere, Karnataka, India</place>
		<desc><![CDATA[Joined for High school at Malladi halli swami ashram]]></desc>
	</event>
	<event>
		<name>Pre-University education at Chitradurga circa Jun, 1991</name>
		<place>Chitradurga, Karnataka, India</place>
		<desc><![CDATA[Joined for PUC Education at Govt Sc College in Chitradurga, Karnataka]]></desc>
	</event>
</events>

The events map API will automatically Geocode the address specified in the place tag and positions the marker.  Optionally you can also specify exact lat/lon if you know it instead of place tag as follows.

	<event>
		<name>Born in Doddachellur, Karnataka</name>
		<place>Chitradurga, Karnataka, India</place>
		<lat>14.230774</lat>
		<lon>76.400299</lon>
		<desc><![CDATA[Bon on 14th Oct to Rudramuniyappa and Sowbhagyamma]]></desc>
	</event>

Here is the zip file containing all the source.  Let me know if you need something.

Categories: All, Google Maps Tags: , , ,

Expired Indian packaged food

October 26th, 2008 No comments

It is sad to admit that some Indian privately owned businessmen are deceiving at best.  It is evident when you go to most of the Indian groceries in North Bay area (San Rafael, Vallejo, Berkeley etc) and check out the packaged food packets.  Most of them are either,

  • Expired
  • Or there is no expiry date
  • Or expiry date is erased (that’s right, erased)

When you try to inform them that expired package is kept for sale, forget about being apologetic, they are ignorant and rude at best.  Usual responses when I highlight that package expired is “We don’t know”, “Don’t buy that” etc.

Shame on you people who do this.  Let’s be fair.  While you charge way more than what they are worth (for ex., one simple udupi mixture costs $3 while the actual value might be just around $1 or so), at least provide the good service for the money you expect.

I’m not sure what’s the law of California Public Safety and Health department. Hope that they will take some action and curb this shady practice.

So people please please check out the expiry date before you buy.  If there is no expiry date, don’t buy it.  If you find something which is expired, tell them take it off the shelf.  Spread the word and let your friends/family know.

Another tip to businessmen if they haven’t realized already: Please smile. Customer likes it.

Time to count

October 25th, 2008 No comments

Even though CNN has named around 10 names for the current crisis, everybody knows it is the whole system which failed.  The so called bankers, politicians and people who went beyond their limit resulting the crisis.

Because of few percentage of people, lots many people are suffering due to lost jobs or investment value (401k or stocks), depreciated house prices and increased rents.  All the things are adding to each other little bit day by day worsening.

As I work in IT industry, it is curious for me to follow the current market situation about jobs.  Techcrunch has started a list of lost tech jobs.  It is alarming rate at which count is getting bigger.  Check it out.

Categories: All Tags: