searchforsolutions

Just another WordPress.com site

Optimizing start up time of an Spring application

1. Load the bean lazily! Specify @Lazy (true) annotation for all the beans!
2. Instead of class path scanning the beans could be loaded from a particular package name format or have a list of classes generated before hand (write some utility to generate discovered beans and dump in csv and then use it to load only certain beans)

Deploying Tomcat with SSL / HTTPS enabled with POODLE vulnerablity fixed

1. To enable SSL deployment generate self signed certificate  or procure one from a trusted 3rd party store.

For the sake of simplicity i’ll use self signed certificate.Run the keytool located in the JDK under bin folder for generating self signed certificate.

keytool -genkey -alias tomcat -keyalg RSA -keystore \path\to\my\keystore.keystore

For those wanting to have certificate from trusted Certificate Authority.

In case of For Importing the Chain Certificate into your keystore provided by trusted Certificate Authority
keytool -import -alias root -keystore <your_keystore_filename> -trustcacerts -file <filename_of_the_chain_certificate>

And finally import your new Certificate
keytool -import -alias tomcat -keystore <your_keystore_filename> -file <your_certificate_filename>

2. Configure Tomcat for SSL with POODLE fix

In server.xml under conf folder of tomcat installation enable SSL by removing comments around the SSL section and modifying it as given below

<Connector port=”8443″ protocol=”org.apache.coyote.http11.Http11NioProtocol” maxThreads=”150″ SSLEnabled=”true” scheme=”https” secure=”true” clientAuth=”false” sslProtocol=”TLS” keystorePass={password provided during certificate generation} keystoreFile=”\path\to\my\keystore.keystore” sslEnabledProtocols=”TLSv1.2,TLSv1.1,TLSv1″/>

Start Tomcat & hit https://localhost:8443 accept the certifcate and it will display default root application.

3. To confirm SSLv2/3 is disabled download the following tool https://github.com/rbsec/sslscan/releases
Execute the foolowing CLI
sslscan –ssl3 –no-failed 127.0.0.1:8443
sslscan –ssl2 –no-failed 127.0.0.1:8443

The tool should not return any results

Deploying Spring framework in Undertow web container

With Undertow ,the new web container replacement for JBoss AS/Wildfly , kicking ass in performance benchmarks [Ref: http://www.techempower.com/benchmarks/#section=data-r9&hw=peak&test=db%5D including node.js

I decided to explore it further. The Async features as well as Non-blocking IO features looks interesting. So going to explore that further and keep you guys posted.

Meanwhile have created reference template for getting kick started.

This could be used by anyone looking @ exploring undertow & spring deployments.

Source Code: https://github.com/rohitdev/project-templates

Maven Gotchas

1. Saving passwords data in settings.xml or any other xml doc with special characters

e.g. ur password is like @Q999988#

save it like <![CDATA[@Q999988#]]>

Hibernate Tools refuses to auto generate code in Eclipse

After debugging the plugin and observing the logs it seems there is some classloader issue for the tools plugin due to which the logger libs are creating an issue with code generation.

You would get the follwoing stacktrace in the eclipse logs

!MESSAGE An internal error occurred during: "Fetching children of Database".
!STACK 0
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:550)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)

To workaround this issue there are 2 ways.

For maven based projects comment out the logger libs reference or if its a well organised maven project remove reference to the parent

Trigger the generation it would generate the code.

If its a normal java project remove the references tot the loggers temporarily and triger generation.

Solution – Eclipse / Springsource ToolSuite consumes large number of CPU cycles or hangs when starting Tomcat

• Delete all the breakpoints that you may have set for debugging. I think it has some recursive call through the code to figure out the breakpoints. If the line has changed i guess it goes for a toss.
• Disable all the validators
• Close unrealted projects

JSF framework for Web 2.0

Just stumbled across an JSF framework.

http://www.primefaces.org/

The demo portal looks quite promising

http://www.primefaces.org/showcase-labs/ui/home.jsf

I’m more comfortable with server-side user interface designing using component technologies.So this may not be suitable for high traffic websites but an awesome choice for enterprise applications

Tip : Exception designing

• Use checked exceptions for recoverable conditions and runtime exceptions for programming errors:Runtime exceptions should be used only to indicate programming errors, such as precondition violations.
• Use exceptions only for exceptional conditions:That is, do not use exceptions for control flow.
• Avoid unnecessary use of checked exceptions: In other words, don’t use checked exceptions for conditions from which the caller could not possibly recover, or for which the only foreseeable response would be for the program to exit.
• Throw exceptions appropriate to the abstraction:In other words, exceptions thrown by a method should be defined at an abstraction level consistent with what the method does, not necessarily with the low-level details of how it is implemented.