Posts Tagged ‘Java’

Step by step to setup Java app monitoring tool – Java Melody

December 17th, 2012
  • In $CATALINA_BASE/webapps/myapp/WEB-INF/web.xml, add filter and listener at the beginning of filter and listener section of file:
<filter>
    <filter-name>monitoring</filter-name>
    <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>monitoring</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
...

<listener>
    <listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
  • copy following two jars files under $CATALINA_BASE/webapps/myapp/WEB-INF/ lib directory, add:

javamelody-1.42.0.jar
jrobin-1.5.9.jar

Visit URL: http://localhost:8080/myapp/monitoring

Soap web service with client certificate authentication

July 21st, 2012

In my previous post Example of SOAP web service call in Grails, it demos how to make soap web service call in Grails, over http. For further complicated requirement, web service all need to over https this time, and need to be with client certificate authentication.

How to do that in a rapid development environment?

SoapUI is your good friend.

But firstly, we need a self-signed CA (Certificate Authority) certificate, by using keytool in JDK.

terrence@stingy ~
09:23:59 122 $ keytool -genkeypair -alias soapui -keystore soapui.jks
Enter keystore password: XXXXXXXX 
Re-enter new password: XXXXXXXX
What is your first and last name?
  [Unknown]:  Terrence Miao
What is the name of your organizational unit?
  [Unknown]:  Scrum Line
What is the name of your organization?
  [Unknown]:  Paradise
What is the name of your City or Locality?
  [Unknown]:  Eden
What is the name of your State or Province?
  [Unknown]:  Heaven
What is the two-letter country code for this unit?
  [Unknown]:  
Is CN=Terrence Miao, OU=Scrum Line, O=Paradise, L=Eden, ST=Heaven, C=Unknown correct?
  [no]:  yes

Enter key password for 
	(RETURN if same as keystore password):

Setup SSL certificate for mock truststore and keystore in SoapUI preference:

» Read more: Soap web service with client certificate authentication

Iterate a class object to a list of enums generically?

July 3rd, 2012

Class#getEnumConstants() returns the enum constants and it’s type safe.

public static <T extends Enum> List<T> getList(Class<T> clazz) {
    return Arrays.asList(clazz.getEnumConstants());
}

Apache CXF, wsimport, xjc and jaxb binding

July 1st, 2012

Last two days I try to figure out the best practice mapping WSDL to Java Object. Still not very satisfied with any approach. I just bookmarks all the interesting links together for further reading:

Git and IntelliJ for impatient and not-very-happy developers

June 19th, 2012

If you want to be a good developer, you should try IntelliJ and switch to Git.

Having played with Spring Tools Suite, an Eclipse based IDE for more than six weeks. How do I feel? I hate it. Buggy and inconsistent. Unexpected behaviour should easily waste a few hours to figure out and workaround. Eclipse is no better. A fat blow-ware, confliction between different plugins …

IntelliJ has a lot goodies, bit by bit, piece by piece. Saving a few keystroke are not big deal to carry one task, but to do it thousand times, even one keystroke less can save your life.

+Dean Budd Deano has barracked for IntelliJ long time ago. You have to really try it by yourself, feel it by yourself, understand it by yourself, then convince you how good it is. IntelliJ will become my major development platform for JEE and Grails project.

Git, how many time I have to remind you how quick and lighting fast it is?

Setting up a new Git repository on my MacBook Pro tonight, 15MB big source codes initialised, pulled, pushed out and into repository. Everything just bang, bang, bang. Even Perforce never impress me so much.

95% time you only need run git on command line. The other 5% time I switch to SmartGit on Mac is to have a look graphic branch history.

Don’t be a loser. Good tools help and accelerate your work, and leave a smile on your face after job done …
» Read more: Git and IntelliJ for impatient and not-very-happy developers

Groovy and Grails in Action

May 10th, 2012

A Spring house is moving to Grails development for web based application. Plus, Spring is going to totally disappear in the middleware in this house. How come?

Any unit test framework for Groovy and functional test (BDD) for Grails you know or recommend?

Concise Learning – Why less is more?

April 24th, 2012

Technology never stop evolving during tough time in GFC and even in stock market flash crash in 2010. Spring in Action, as always good quality as other “in Action” series books from Manning, is in its 3rd generation now. It’s not only a revised book, but also recharging your Spring knowledge.

Based on the latest Spring 3.0 technology, Spring in Action adds some fresh contents built only in release 3 that I’m looking for:

• Native support RESTful service
• New Spring Expression Language (SpEL)
• New annotations to reduce configuration and poison XML files
• Last but not least, seamlessly integrated with Spring MVC, Spring Web Flow and Spring Security

All these original and additional Spring contents in a just over 400 pages book is quite amazing. This is another confirmation and confidence Spring team has given that you can build an Enterprise level application in ultra lightweight Spring fashion.

Happy reading!

Embedded Link

» Read more: Concise Learning – Why less is more?

JSF 2, Spring 3, Spring MVC 3, Hibernate 4, Tomcat 7 – a lightweight approach

April 22nd, 2012

“What is your favourite design pattern?” Question asked in a job interview.

WTF question is that?

“Hmmm… my favourite design pattern is Salami pattern – approaching to the finish line slice by slice.”

– From Antidisestablishmentarianism I.T.

In my previous blog - Spring 3 shacks up JSF 2, the maverick way, demonstrating how JSF 2 a component, event driven framework as the presentation layer, and Spring 3, Spring MVC 3 work in middleware. Well, technology keeps evolving. Hopefully even pigs could programe one day. This time, Hibernate 4 is added as the persistence layer. Now, we have end-to-end, a “traditional” three tiers web application. Moreover, an unit test to test business logic layer, the most important, runs outside of container.

Firstly, files and directories structure:

The backend database is Oracle’s example of  Human Resources (HR) application for a fictitious company (check the reference at the end of the blog).

» Read more: JSF 2, Spring 3, Spring MVC 3, Hibernate 4, Tomcat 7 – a lightweight approach