Monday, April 28, 2008
HTTP Debugger
I have used the following products:
Commercial Product:
Charles Web debugging proxy is really good and it automatically takes up the settings from the browser and proxies the request.
URL: http://www.xk72.com/charles/
Open source Tool:
Fiddler
URL: http://www.fiddlertool.com/fiddler/
Friday, April 18, 2008
Apache + SSL
Download Apache With SSL Support and OpenSSL
Extra both zip files into two different location, and replace all *.exe, *.dll, *.so files from Apache with OpenSSL support to your Apache local installation.
Download ssl.conf into APACHE_HOME/conf
Download openssl.cnf into your OpenSSL directory Also copy the files ssleay32.dll and libeay32.dll from the OpenSSL distribution directory to WINDOWS\System32 directory !!!
2.0 Create CertificateEnter the following command
openssl req -config openssl.cnf -new -out my-server.csr
This creates a certificate signing request and a private key.
openssl rsa -in privkey.pem -out my-server.key
This removes the passphrase from the private key.
openssl x509 -in my-server.csr -out my-server.cert -req -signkey my-server.key
This creates a self-signed certificate.
Create an APACHE_HOME/conf/ssl directory and move my-server.key and my-server.cert into it.
3.0 Configure mod_ssl and ApacheEdit APACHE_HOME/conf/httpd.conf add the following line
LoadModule ssl_module modules/mod_ssl.so
# SSL
SSLMutex default
SSLRandomSeed startup builtin
SSLSessionCache none
SSLEngine On
SSLCertificateFile conf/ssl/my-server.cert
SSLCertificateKeyFile conf/ssl/my-server.key
You also need to modify APACHE_HOME/conf/ssl.conf to update DocumentRoot and ServerName
Restart your Apache server and you could test it on https://localhost/
For reference please go tohttp://www.thompsonbd.com/tutorials/apachessl.php and http://tud.at/programm/apache-ssl-win32-howto.php3
Tuesday, April 15, 2008
How Spring can Leverage any ORM
I was previously working with Spring with Hibernate (2.3) Combination. It was really painful because hibernate was throwing all the exceptions as checked exceptions and we were forced to catch all the exceptions in the Service Layer. But now a days it is very simple as we can catch the exceptions as Throwable in Service Layer and can use an Interceptor to log those message and rethrow as application specific exceptions. I came across a good article about the Spring leveraging any ORM and thought of adding its content into my blog with the reference to the source site.
In a typical Spring architecture, DAOs are effectively Strategy Pattern objects, isolating service layer objects from the technology specifics of obtaining and saving persistent objects.
Spring supports a range of ORM tools and persistence frameworks, including (but not limited to) TopLink, Hibernate, JDO (Java Data Objects), iBATIS SQL Maps, and Apache OJB (ObjectRelational Bridge).
Spring provides a consistent approach to working with all these tools, but doesn't attempt to completely abstract the ORM tool, because doing so would be counterproductive. Thus, for example, implementations of DAO interfaces will use the native query API of the ORM tool: Spring does not attempt to create a query abstraction, which would be less powerful than that of leading ORM products.
How Spring can Leverage any ORM ?


Secondly, Spring's exception handling approach uses unchecked exceptions. Using unchecked exceptions works particularly well in conjunction with an exception hierarchy, because it is only necessary to catch a particular subclass that may be recoverable. Catching subclasses of checked exceptions is less useful, since the base class still needs to be caught. (Note that JDBC was always something of an odd API out, in terms of using checked exceptions: TopLink and JDO, for example, both use unchecked exceptions. In version 3, Hibernate will switch from checked to unchecked exceptions.)
Resource acquisition and release: One of the major challenges of working with any data access technology is that resources such as JDBC connections or ORM sessions must be acquired and released correctly even in the event of errors.
Spring solves the problem of resource acquisition and release by using a callback approach. The framework is responsible for acquiring and releasing resources, while the application developer implements code in a callback method to perform the necessary persistence operation with the desired resource. Thus application developers focus on the unique needs of their application, rather than writing plumbing code.
Helper classes that provide this functionality are termed templates, and Spring provides a consistent approach across many APIs where such resource acquisition and release is a problem, such as JDBC, JNDI and JMS.
Transaction management and thread binding: Spring's resource acquisition and release strategy is integrated with its transaction management support. It's important to get the same resource for every operation in the same transaction. While JTA and JCA may provide support for this in a full-blown J2EE environment (depending on the persistence tool), Spring provides support for this in any environment, including J2SE environments. The necessary Spring configuration is also simpler than JCA configuration.
Spring does this by binding resources such as JDBC connections or TopLink or Hibernate Sessions to the current thread. Many application developers have implemented such support in their own applications. However, the Spring solution not only has the merit of being far more sophisticated than typical in-house solutions (with support for transaction suspension and many other complex-to-implement value adds), but eliminates the need to write and maintain such custom code. Again, generic concerns are best given a generic solution.
Source: http://www.oracle.com/technology/pub/articles/masterj2ee/j2ee_wk9.html
Wednesday, April 9, 2008
Improve Your Java Code Quality
His associated article series In pursuit of code quality will offer best practices for ensuring your code is the best it can be.
Code Quality Discussion Forumhttp://www.ibm.com/developerworks/forums/dw_forum.jsp?forum=812&cat=10
Encoding JSP Pages globally with specific encoding (Servlet 2.4 onwards)
<jsp-config>
<jsp-property-group>
<display-name>Setup default encoding</display-name>
<url-pattern>*.jsp</url-pattern>
<page-encoding>ISO8859-1</page-encoding>
</jsp-property-group>
</jsp-config>
Reference article:
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jsps/jspconfig/jspconfig.html#encode
Tuesday, April 8, 2008
Exception handling and Logging Strategies for J2EE projects
http://www.ibm.com/developerworks/websphere/library/techarticles/0207_barcia/barcia.html
Webmethods Exception handling
http://www.wmusers.com/ezine/2002dec_iandrosov_1.shtml
Implement Logging as an Aspect Using Spring's AOP Framework
http://www.devx.com/Java/Article/30799/1954
Exception management and error tracking in J2EE
http://www.javaworld.com/javaworld/jw-07-2005/jw-0711-exception.html?page=1
Best Practises in EJB exception handling
http://www.ibm.com/developerworks/java/library/j-ejbexcept.html
Exception Handling Framework for J2EE
http://www.onjava.com/pub/a/onjava/2006/01/11/exception-handling-framework-for-j2ee.html?page=1
Exception Handling & Logging Presentation
http://www.softwaresummit.com/2004/speakers/SteltingExceptionHandling.pdf
Logging in JSPs Tag Library
http://jakarta.apache.org/taglibs/doc/log-doc/intro.html
Java tutorial: exceptions
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/exception.html
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
Exception handling
http://www.objectsource.com/j2eechapters/Ch18-Exception_Handling.htm
Designing with Exceptions
http://www.artima.com/designtechniques/desexceptP.html
Best Practices for Exception Handling
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html
Three Rules for Effective Exception Handling
http://today.java.net/pub/a/today/2003/12/04/exceptions.html
Beware the dangers of generic Exceptions
http://www.javaworld.com/javaworld/jw-10-2003/jw-1003-generics.html
Exception Handling in Web Applications
http://weblogs.java.net/pub/wlg/987
Java Theory and Practice: The exceptions debate
http://www-106.ibm.com/developerworks/java/library/j-jtp05254.html
Best practices in EJB exception handling
http://www-106.ibm.com/developerworks/java/library/j-ejbexcept.html
Exception handling with JAX-RPC
http://www-106.ibm.com/developerworks/xml/library/ws-tip-jaxrpc.html
JavaOne2002 - Handling Exceptions in Distributed Systems
http://servlet.java.sun.com/javaone/sf2002/conf/sessions/display-1563.en.jsp
book: Java Platform Exception Handling
http://www.amazon.com/exec/obidos/ASIN/0131008528