Wednesday, May 7, 2008

How to present the version number on a web front end with spring and maven

Blink It Digg! Dzone

This bog will describe how to present a application version number in
the pom.xml on a web front end by using spring and maven. Maven
generates by default a pom.properties file in the META-INF folder when
generating a war. This file holds the following fields; version,
groupId, artifactId

The exact location from your context root is;

META-INF/maven/<groupId>/<artifactId>/pom.properties


by specifying the following bean in your spring config; (REPLACE
<groupId> and <artifactId> with what you have defined in your pom.xml)

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<property name="basenames">
<list>
<value>META-INF/maven/<groupId>/<artifactId>/pom</value>
</list>
</property>
</bean>


Now the properties in this file can be used in your font-end by using
the standard spring tags for example to print the version number in a
jsp file use the following line;

<b>Version:</b> <spring:message code="version"/>


REMARK don't forget to add the spring tag definition to your jsp file;

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

Wednesday, April 2, 2008

JPA Toplink, and stored procedures

Blink It Digg! Dzone

If all you want to do is create extra stored procedure queries then
you might want to consider just creating a customizer and adding some
queries there. Then you won't actually need to create a project at
all.

Use the toplink.session.customizer property described at:
http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html

and then add some queries to your session. To make it even easier,
then just define your queries in JPA, and override the call in your
customizer. For example, if you defined a JPA named query called
"Employee.executeStoredProc" then in your customizer method you could
have something like:

public void customize(Session session) {
DatabaseQuery query = session.getQuery("Employee.executeStoredProc");
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("employee_stored_proc");
query.setCall(call);
}

Then when you call your JPA query the stored proc will run.

Thursday, March 13, 2008

AirDisk problems with Airport extreme

Blink It Digg! Dzone

Just back from my Snowboard holidays, and the worse thing happended I could not connect to my AirDisk through my AirPort extreme. The following errors reported to me.

- Error 35
- The alias "xxx" could not be opened, because the original item cannot be found

Where xxx is the name of your AirPort extreme. This errors resulted that my AirDisks where not accessible by anything. After some surfing (3 days) If found a solution to my problem on a forum. (see link below).

The solution was for me to go back to a previous version of the firm ware of my AirPort extreme. The following steps should be taken to downgrade you AirPort extreme. (I went from version 7.2.1 to 7.1.1)

- Go to your Airport Base station utility
- In the menu bar choose "Base Station" then "Upload firmware".
- A drop down will give you a choice of other previous version of the firmware.

This solved the problem for me, I hope this helps you guys out there. (BWT I tested this on a mac and on a windows machine)

see http://discussions.apple.com/thread.jspa?messageID=6765045 for more info

Monday, August 13, 2007

Remember me with ageci security

Blink It Digg! Dzone

Remembering returning vistors logon is nice functionality for your website. Ageci security is nice tool what offers this functionality with just what configuration. This topic will help you configuring the remember me authentification based on a form login with Java Authentication and Authorization Service (JAAS).

Remember me functionality is one of the more insucure features of a website. Remember me functionality works on a client side cookie. A cookie can be tampered with or stolen by an hacker, that is why you should be carefull implementing a remember me service.

Friday, August 10, 2007

Tomcat with HTTPS SSL

Blink It Digg! Dzone

Tomcat and HTTPS is for me one of the less easy things to do. Several times I set up Tomcat with SSL and HTTPS and never documented it untill now....

In my setup for Tomcat and SSL HTTPS I used tomcat version 5.5.23. Tomcat needs a signed JDK to accept HTTPS request correctly. Your JDK will get signed by generating a certificate and add this to the jks keychain. WARNING generating the certificate use ‘localhost ’ as your name or common name, otherwise tomcat will not except this certificate. This is very importend otherwise Tomcat will not accept your certificate!


$JAVA_HOME\bin\keytool -delete -alias tomcat -keypass changeit
$JAVA_HOME\bin\keytool -genkey -alias tomcat -keypass changeit -keyalg RSA
$JAVA_HOME\bin\keytool -export -alias tomcat -keypass changeit -file server.crt
$JAVA_HOME\bin\keytool -import -file server.crt -keypass changeit -keystore %JAVA_HOME\jre\lib\security\cacerts
$JAVA_HOME\bin\keytool -import -file server.crt -keypass changeit

For tomcat to accept HTTPS request the next few lines should be added to the server.xml. The .keystore file can be found in your home folder.

<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="/path/to/.keystore"
keystorePass="changeit"/>

This should be all to get things running. To test your HTTPS SSL connection just start Tomcat, and point to https://localhost:8443. If everything is okee you should see the standard tomcat startup page, otherwise check the tomcat logs. Common mistakes are JAVA_HOME is not set to the correct JDK, and the certificate is not accepted by tomcat the cause can be a incorrect password. I hope this helps to get Tomcat setup to accept HTTPS SSL

Wednesday, August 1, 2007

Multi threaded JMS with Lingo and Jencks

Blink It Digg! Dzone

In the previous article about Lingo JMS with Lingo we took care of a simple Lingo implementation. In that article we discussed that Lingo does not support out of the box a multi threaded server side. This article will discuss the steps to take to get your Lingo implementation to the next level.

To get the server side to process server calls on multiple threads we going to use Jencks. Jencks is a implementation of the J2EE Connector Architecture (JCA). For now we are just going to implement a simple multi threaded solution without transactions.

The client side is exactly the same as discused in JMS with Lingo, for more info about how to setup the Lingo client site I refer to this article.

The server side is also the same as discused in JMS with Lingo, but additinal to this configuration for Jecks needs some configuration to take care of multi threading part.


<!-- JCA container -->
<bean id="jencks" class="org.jencks.JCAContainer">

<!-- lets use the default configuration of work manager and transaction manager-->
<property name="bootstrapContext">
<bean class="org.jencks.factory.BootstrapContextFactoryBean">
<property name="threadPoolSize" value="25" />
</bean>
</property>


<!-- the JCA Resource Adapter -->
<property name="resourceAdapter">
<bean id="activeMQResourceAdapter"
class="org.apache.activemq.ra.ActiveMQResourceAdapter">
<property name="serverUrl" value="tcp://localhost:61626" />
</bean>
</property>
</bean>

<!-- an inbound message connector using a stateless, thread safe MessageListener -->
<bean id="inboundMessageA" class="org.jencks.JCAConnector">

<property name="jcaContainer" ref="jencks" />

<!-- subscription details -->
<property name="activationSpec">
<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
<property name="destination"
value="org.isthisjava.service.jca.ExampleService" />
<property name="destinationType" value="javax.jms.Queue" />
</bean>
</property>

<property name="ref" value="exampleService" />
</bean>


When you want more details for the multi threaded client and server, the complete source code is added at the end of this page. If you want to see it in action just drop the server end client binaries into tomcat. and point your browser to http://locahost:8080/somepathtothemultithreadedclient

TODO add source and binaries

Sunday, July 29, 2007

JMS with Lingo

Blink It Digg! Dzone

Lingo is one of those little projects what make life a lot easier for a java developer. According to the Lingo people Lingo is a lightweight POJO based remoting and messaging library based on Spring's Remoting which extends it to support JMS. Lingo can support a wide range of message exchange patterns including both synchronous and asynchronous message exchange.

I came across Lingo when I was searching for a really simple JMS solution. Ofcourse I looked into Spring but I didn't like what they offered. In my opinion spring JMS (Message Driven POJO) was still to low level for me. I was searching for a real POJO based solution what handles all the messaging for me, and that is just the thing Lingo does.

This article is focused around how to setup Lingo correctly in your environment. At the bottom you find a link to the source code with a sample client implementation, and a sample server implementation. These project are both web based, they where tested in a default Tomcat 5.5.23, and a default Active MQ 4.1.1. Active MQ is used as a JMS message broker.

The client consist out of two pages, the first page will initiate the call to the server, the second page will present the result to the user. A sample of the client side spring config is represented below. For Lingo client side 3 beans are defined, the actual service, the JMS broker, and the queue where to send the message to. The last two must also be present in the server side spring config.


<!-- client side proxy-->
<bean id="exampleService" class="org.logicblaze.lingo.jms.JmsProxyFactoryBean">

<property name="serviceInterface" value="org.isthisjava.service.ExampleService"/>
<property name="connectionFactory" ref="jmsFactory"/>
<property name="destination" ref="exampleDestination"/>
</bean>

<!-- JMS ConnectionFactory to use -->
<bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>

<bean id="exampleDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg index="0" value="org.isthisjava.service.ExampleService"/>
</bean>


For the Lingo server side consist out of 4 beans, the actual POJO implementation of the service, a setup for the POJO so that it will listen to incomming messages, and the JMS broker and the queue definition. The last two are also in the client configuration. Take in account that this configuration is a single threaded solution. A single threaded solution is okee for the client side, but the server side should be multi threaded. How to make your server side multi threaded will be discussed in a later article.


<!-- the server side -->
<bean class="org.logicblaze.lingo.jms.JmsServiceExporter">
<property name="service" ref="serverImpl"/>
<property name="serviceInterface" value="org.isthisjava.service.ExampleService"/>
<property name="connectionFactory" ref="jmsFactory"/>
<property name="destination" ref="exampleDestination"/>
</bean>

<!-- the actual implementation of the service - which is only made public for testing purposes -->
<bean id="exampleServiceImpl" class="org.isthisjava.service.ExampleServiceImpl" singleton="true"/>


In the source code added to this article you will find the ExampleService and a simple implementation of this service. For more details please look into the source code.

If you just want to see a demo please install Active MQ and drop the two wars (see binary) in your Tomcat, and navigate to http://localhost:8080/jmswithlingoclient

jmswithlingoclient-src-1.0.zip
jmswithlingoclient-bin-1.0.zip
jmswithlingoserver-src-1.0.zip
jmswithlingoserver-bin-1.0.zip