tag:blogger.com,1999:blog-72201073705968715902024-03-13T10:15:17.101+05:30Something about Software TechnologiesWindow where I express what I think helpful to others in programming technologies especially javaVijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-7220107370596871590.post-88961570631998987702011-05-09T00:38:00.003+05:302011-05-09T00:51:01.748+05:30Grails Plugin Spring Security Kerberos Sample<div dir="ltr" style="text-align: left;" trbidi="on">This blog is about a simple sample application that demonstrates usage of <a href="http://www.grails.org/plugin/spring-security-kerberos">Grails Spring Security Kerberos Plugin</a>. It is assumed that the reader is familiar with Kerberos Authentication, Grails, Spring Security and Grails Plugin system.<br />
<br />
The above plugin is just a wrapper on top of <a href="http://static.springsource.org/spring-security/site/extensions/krb/index.html">Spring Security Kerberos Extension</a>. All it is doing is to handle the Spring beans assembly and integrate with the Spring Core Security Plugin.<br />
<br />
Start with reading the <a href="http://grails-plugins.github.com/grails-spring-security-kerberos/">documentation on Kerberos Grails Plugin</a> and the <a href="http://blog.springsource.com/2009/09/28/spring-security-kerberos/">blog on Spring Kerberos Extension</a>. As you can see there isn't much configuration to do in Grails Kerberos Plugin. Just the <i>Keytab file path</i> and <i>Service Principal Name</i> are required.<br />
<br />
Read the <i>blog on Kerberos Extension</i> carefully and create the Keytab file for the Service Principal (Your AD administrator would do it). The bulleted check list found towards the end of the Kerberos Extension blog is very helpful to make sure that everything is done properly.<br />
<br />
<b>What is the Grails Plugin is all about?</b><br />
There is a section "Configuring Spring Security" in the above blog. The plugin has all those configurations taken care of except the URL mapping. So you don't have to do it in your Grails application<br />
<br />
<b>How do I do the URL mapping?</b><br />
Just use one of the options provided by Spring Security Core Plugin (@Secured, Requestmap etc.)<br />
<br />
<b>What are the other catches?</b><br />
Typically when Kerberos SSO authentication is used, no user details would be stored in the application database. In Spring Security the user details are loaded into the security context by the "userDetailsService" bean. This is demonstrated by the usage of "dummyUserDetailsService" in the Kerberos Extension sample.<br />
So in the Grails application the following bean should be present in conf/spring/resources.groovy. Otherwise Security domain objects (User, Role etc.) should be in use<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">beans = {</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">userDetailsService(com.mycompany.myapp.MyUserDetailsService)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">}</span><br />
<br />
<b>Now about the sample application.</b><br />
This is how I had created the application<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">> grails create-app grails-spring-security-kerberos-sample</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">> grails install-plugin spring-security-kerberos</span><br />
And added <sec:username> is main.gsp and index.gsp.</sec:username><br />
<br />
** Consider "mymachine" as the CNAME/Hostname of the machine being used deploy the application and "mydomain" is the domain controller<br />
So the Service Principal should be "<b>HTTP/mymachine.mydomain.com@MYDOMAIN.COM</b>"<br />
The name of the keytab file could be anything.<br />
<br />
Let's start <b>Config.groovy</b> configuration.<br />
<br />
<span class="Apple-style-span" style="font-family: inherit;">// Kerberos related</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">grails.plugins.springsecurity.kerberos.ticketValidator.servicePrincipal='HTTP/mymachine.mydomain.com@MYDOMAIN.COM'</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">grails.plugins.springsecurity.kerberos.ticketValidator.keyTabLocation='file://D:/keytabs/myapp.keytab' </span><span class="Apple-style-span" style="font-family: inherit;">//put the keytab file in a secure location</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">// Spring Security Core related (You may use other options too)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">grails.plugins.springsecurity.securityConfigType = SecurityConfigType.InterceptUrlMap</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">grails.plugins.springsecurity.interceptUrlMap = ['/**': ['IS_AUTHENTICATED_FULLY']]</span><br />
<br />
<b>What about KDC configuration?</b><br />
Create a krb5.conf file and point to it using -Djava.security.krb5.conf JVM option. A sample can be found in the root folder of the source.<br />
In Windows a krb5.ini file (exact name only) can be placed in C:/Windows folder<br />
<br />
That's it.<br />
Now run the application<br />
Access it from another machine in the same domain using the fully qualified name of machine where application is running (localhost will not work, also using IP address from another machine).<br />
If the authentication is successful, the NT user name will be displayed in home page.<br />
<br />
<a href="http://sites.google.com/site/somethingabouttech/grails-spring-security-kerberos-sample.zip">Download the source (Eclipse/STS)</a><br />
<br />
Just unzip it, create the Keytab file for the Service Principal and change the Config.groovy entries. You are ready to go.<br />
<br />
<b>My Environment Details</b><br />
<ul style="text-align: left;"><li>app.grails.version=1.3.7</li>
<li>plugins.spring-security-kerberos=0.1</li>
<li>JDK 1.6.0_23</li>
<li>Windows XP</li>
<li>Sample worked with embedded server (run-app) and apache-tomcat-7.0.10</li>
<li>Windows 2003 Server (Used a local domain controller setup [i.e. two XP and one 2003])</li>
<li>IE 6 & 7, FF 4.0 and Chrome 11</li>
<li>STS 2.5.2 (Springsource Tool Suite)</li>
</ul><div><b>Error when "userDetailsService" bean is not Present</b></div><div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">ERROR [/grails-spring-security-kerberos-sample].[default] - Servlet.service() for servlet default threw exception</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">java.lang.NullPointerException: Cannot get property 'clazz' on null object</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:235)</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>at org.codehaus.groovy.grails.plugins.springsecurity.GormUserDetailsService.loadUserByUsername(GormUserDetailsService.groovy:50)</span></div></div><div><br />
</div><div>Hope this blog helps you implement Keberos based security in your Grails application.</div><br />
<br />
</div>Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com4tag:blogger.com,1999:blog-7220107370596871590.post-65457201464848961492010-06-07T14:43:00.001+05:302010-06-07T15:19:27.874+05:30Grails EvaluationRecently at work, I have evaluated <b><a href="http://www.grails.org/">Grails Framework</a></b> as part of larger initiative to choose a better framework that focuses on productivity gains without compromising other features expected from a good framework. Finally we chose Grails as the framework to be adopted internally for agile development. Here is why:<br />
<br />
The published tag lines of the Grails framework are Rapidness (Productivity), Dynamic (Agile) and Robustness. While principles like <b>DRY </b>(Do not Repeat yourself), <b>CoC </b>(Convention over Configuration) and Code Generation etc provides the Rapidness; and Groovy, Scaffolding and Automatic Dependency Injection makes it Dynamic; and ultimately the fact that Grails artifacts are compiled to Java class files that make use of well proved libraries like Spring, Hibernate, Sitemesh etc. and runs in JVM provides the much needed Robustness.<br />
<br />
On top of the core Grails library there are myriads of plug-ins (modular Grails extensions that enhance core Grails features and brings new ones to it) that brings reusable components/functionalities to Grails and greatly reduces the total effort required to create applications.<br />
<br />
Grails has its own DSL based ORM mechanism (GORM); Controllers, Filters and Interceptors, Tag libraries etc. for Web layer; Pluggable AJAX provider; a Service Layer with automatic dependency injection and optional Java service use; excellent internationalization support with messages.properties files generated for multiple languages and convention based keys; very helpful error display where actual code snippet that caused the error is quoted; out of the box support for REST and plug-ins for SOAP web services; integration tests are created when controllers are generated; and Grails has embedded database and servlet container for development environment.<br />
<br />
The hands on exercises that we have carried out using Grails revealed its main offering: productivity. It took no more than 10 minutes to setup the development environment, another 5 minutes to create a ‘Hello World’ application. By spending less than 30 minutes we were able to create a fully functional CRUD application (on a single entity). With the experience gained from creating these two applications, we were able to create a fully functional sample Shopping Cart application with an RDBMS within 1.5 days!!. Within 10 minutes security was enabled using Acegi plug-in.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO1oU4IPmi1XLNJRkbn5xLUlydd4ORZ-3f2EDA8niZmcp3NUPpnuIkB1LSJfijIIwoP5H1CHCA-OyvhV0I_EXlIGec5vfO-TsrT4pxpM3ptFVDNpkAUZEDVXDV9hI2D_kjhpy40RkS2dg/s1600/Grails-CRUD.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO1oU4IPmi1XLNJRkbn5xLUlydd4ORZ-3f2EDA8niZmcp3NUPpnuIkB1LSJfijIIwoP5H1CHCA-OyvhV0I_EXlIGec5vfO-TsrT4pxpM3ptFVDNpkAUZEDVXDV9hI2D_kjhpy40RkS2dg/s400/Grails-CRUD.jpg" width="400" /></a></div><br />
<br />
What good a framework will do if it accompanies performance penalty for improving the productivity? Grails has no such issues, though it doesn’t provide significant performance improvement. It did work pretty reasonably under varying loads.<br />
<br />
Adopting any new language and framework involves learning curve, sometimes it can be a hindrance. Groovy, the language behind Grails, too involve some learning curve, but relatively easy as it follows existing idioms.<br />
<br />
Grails is a good framework that delivers what it promises and can be adopted for enterprise use. If adherence to full-stack JEE and usage of Java language is not a must, then Grails is an ideal framework that offers full application-stack features<br />
<br />
<b>Environment Details</b><br />
<br />
app.grails.version=1.2.2<br />
app.servlet.version=2.4<br />
plugins.acegi=0.5.3<br />
plugins.hibernate=1.2.2<br />
plugins.tomcat=1.2.2<br />
Java 1.6<br />
<br />
If you are planning to learn Grails and use it, you will find the necessary guidelines from the various articles at <a href="http://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=mastering+grails">Mastering Grails at DeveloperWorks</a><br />
<br />
I will try publish more specific articles on Grails in coming days (lot many from others already exists though)Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com0tag:blogger.com,1999:blog-7220107370596871590.post-89383853959861631212009-09-11T17:19:00.015+05:302009-09-13T00:10:40.293+05:30Spring JNDI Bind Utility for Unit Tests<div><br />
</div><div><div>Spring does provide JndiTemplate class for JNDI lookup through spring configuration. But there is not such convenience class for binding Objects to jndi server through configuration.</div><div>Through there are some classes like SimpleNamingContextBuilder that can be used programmatically but not via configuration (at least as it is).</div><div><br />
</div><div></div><div>Here I am presenting a utility class that be used to register jndi objects via Spring configuration.</div><div></div><div>For demo purpose <em>commons-dbcp</em> classes are used as resources to be bound to the jndi server.</div><div><br />
</div><div>The JNDI server used is file based <em>RefFSContextFactory</em> from sun. Any other JNDI Server would also suffice</div><div><i><br />
</i></div><div><i><div><span style="font-size:85%;">Prerequisites</span></div><div></div><div>spring-core-2.5.6.jar</div><div>spring-beans-2.5.6.jar</div><div>spring-context-2.5.6.jar</div><div><a href="http://www.docjar.com/jar/fscontext.jar">fscontext.jar</a></div><div><a href="http://www.docjar.com/jar/providerutil.jar">providerutil.jar</a> (referenced from fscontext)</div><div></div><div>The following jars are required for the demo sample only</div><div><a href="http://mirrors.ibiblio.org/pub/mirrors/maven/commons-dbcp/jars/commons-dbcp-1.2.2.jar">commons-dbcp-1.2.2.jar</a></div><div><a href="http://mirrors.ibiblio.org/pub/mirrors/maven/commons-pool/jars/commons-pool-1.4.jar">commons-pool-1.4.jar</a></div><div><a href="http://mirrors.ibiblio.org/pub/mirrors/maven/commons-logging/jars/commons-logging-1.1.jar">commons-logging-1.1.jar</a></div><br />
<div><span class="Apple-style-span" style="font-style: normal;">I am presenting two version of the JNDI Binder utility class; one extends JndiTemplate and the other one extends InitialContext.</span></div><div><br />
<br />
<span class="Apple-style-span" style="font-style: normal;"><b>Binder Utility based on Spring's JndiTemplate class: </b><b><i>JndiBinderTemplate</i></b></span></div></i></div></div><pre class="brush: java">package in.spring.jndi.util;
import java.util.Iterator;
import java.util.Map;
import javax.naming.NamingException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jndi.JndiTemplate;
/**
* A Spring specific utility class to register objects to a jndi server through spring configuration
* Sample usage with file based jndi server
*
* Instead of using interfaces InitializingBean and DisposableBean, @PostConstruct and @PreDestroy
* annotations or init-method can be used
* @see org.springframework.jndi.JndiTemplate
* @author Vijesh
*
*/
public class JndiBinderTemplate extends JndiTemplate implements InitializingBean, DisposableBean {
private Map jndiObjects;
public Map getJndiObjects() {
return jndiObjects;
}
public void setJndiObjects(Map jndiObjects) {
this.jndiObjects = jndiObjects;
// if life cycle interfaces are not available
// call loadJndi(); here
}
@Override
public void afterPropertiesSet() throws Exception {
loadJndi();
}
public void loadJndi() {
System.out.println(" start binding Objects to JNDI server ");
if(jndiObjects != null && !jndiObjects.isEmpty()) {
Iterator itr = jndiObjects.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
try {
rebind((String) entry.getKey(),entry.getValue());
} catch (NamingException e) {
System.out.println(" Binding "+entry.getKey()+" is failed with error: "+e.getMessage());
}
}
System.out.println(jndiObjects.size()+" Objects bound to JNDI server ..");
}
}
@Override
public void destroy() throws Exception {
clearJndi();
}
public void clearJndi() {
System.out.println(" unbind the Objects from the JNDI server ");
if(jndiObjects != null && !jndiObjects.isEmpty()) {
Iterator itr = jndiObjects.keySet().iterator();
while (itr.hasNext()) {
String jndi = null;
try {
jndi = (String) itr.next();
unbind(jndi);
} catch (NamingException e) {
System.out.println(" Error in unbinding "+jndi);
e.printStackTrace();
}
}
}
}
}</pre><br />
The Spring configuration for the above class with some sample resources used to bind to the JNDI server is:<span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 13px; white-space: pre; "> </span><pre class="brush: xml"><beans>
<bean id="sharedDataSource" class="org.apache.commons.dbcp.datasources.SharedPoolDataSource"></bean>
<bean id="poolDataSource" class="org.apache.commons.dbcp.datasources.PerUserPoolDataSource"></bean>
<bean id="jndiBinderTemplate" class="in.spring.jndi.util.JndiBinderTemplate" init="false">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.provider.url">file:/</prop>
</props>
</property>
<property name="jndiObjects">
<map>
<entry key="jndi/sDS">
<ref bean="sharedDataSource">
</ref></entry>
<entry key="jndi/pDS">
<ref bean="poolDataSource">
</ref></entry>
</map>
</property>
</bean>
<!-- Test Class -->
<bean id="testClass" class="in.spring.jndi.util.TestJndiBinding"></bean>
</beans>
</pre><br />
<br />
Now the look up from the jndi consumer classes using will happen as expected. For example the following code would work perfectly fine.<br />
<br />
<pre class="brush: java">/**
* Jndi lookup using Standard mechanism
*/
public void testJNDIBinder() {
System.out.println("\n in testJNDIBinder ");
System.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
System.setProperty("java.naming.provider.url", "file:/");
try {
Context cxt = new InitialContext();
Object obj1 = cxt.lookup("jndi/sDS");
System.out.println(" obj1 "+obj1);
Object obj2 = cxt.lookup("jndi/pDS");
System.out.println(" obj2 "+obj2);
System.out.println(" Look up test is successful.... ");
} catch (NamingException e) {
System.out.println(" Look up test failed.... ");
e.printStackTrace();
}
}
</pre><br />
<br />
<span style="font-weight:bold;">Binder Utility without Spring dependency: JndiBinderContext</span><br />
<br />
The second class is very much similar to the one shown above except for it extends the class InitialContext<br />
<br />
<pre class="brush: java">package in.spring.jndi.util;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* A standard utility class to register objects to a jndi server through spring configuration
* Sample usage with file based jndi server
* @see javax.naming.InitialContext
* @author Vijesh
*/
public class JndiBinderContext extends InitialContext {
public JndiBinderContext() throws NamingException {
super();
}
public JndiBinderContext(Hashtable env) throws NamingException {
super(env);
}
// Rest is almost same as JndiBinderTemplate class, refer the source code for details
</pre><br />
<br />
Another main difference is in passing the environment properties. In this case they are passed as constructor arguments (it is so in InitialContext)<br />
<br />
<pre class="brush: xml"><beans>
<bean id="sharedDataSource" class="org.apache.commons.dbcp.datasources.SharedPoolDataSource"> </bean>
<bean id="poolDataSource" class="org.apache.commons.dbcp.datasources.PerUserPoolDataSource"></bean>
<bean id="jndiBinderContext" class="in.spring.jndi.util.JndiBinderContext" init="false" method="loadJndi">
<constructor-arg index="0"><props>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.provider.url">file:/</prop>
</props>
</constructor-arg><property name="jndiObjects"><br />
<map><br />
<entry key="jndi/sDS"><br />
<ref bean="sharedDataSource"><br />
</ref></entry><br />
<entry key="jndi/pDS"><br />
<ref bean="poolDataSource"><br />
</ref></entry><br />
</map><br />
</property><br />
</bean><br />
<br />
<!-- Test Class --><br />
<bean id="testClass" class="in.spring.jndi.util.TestJndiBinding"></bean><br />
</beans><br />
</pre><br />
<br />
Please note that both the classes should be loaded lazily.<br />
<br />
It's really unfortunate that Spring didn't provide a similar utility class. Why didn't it occurred to them when they created JndiTemplate class for lookup purpose?<br />
<br />
<a href="http://sites.google.com/site/somethingabouttech/home/spring-jndi-binder.zip">Download the source (eclipse project)</a><br />
The dependent libraries listed in the prerequisites should be downloaded separately and added to the project.<br />
<br />
Even though I have used particular version of each dependent libraries, it doesn't mean that the utility will work only with that. As you can see, it is a simple class and should work with the earlier releases of the dependent libraries.Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com5tag:blogger.com,1999:blog-7220107370596871590.post-76047096844073860342009-02-20T04:12:00.001+05:302009-02-22T07:37:07.195+05:30JavaFX CRUD Application<div>Well, I too jumped into the JavaFX bandwagon. Since I have good exposure to Swing, naturally I got excited by the new Rich Client Platform offering from Sun.</div><div><br /></div><div>Most of of the examples using JavaFX available in Internet are demonstrating the graphic and animation capabilities of JavaFX and very few concentrates on Enterprise application needs. Yes I understand that one of the objective of JavaFX is to compete with other RIA/RCP offerings and the enterprise data centric application needs are already taken care of by Java Swing and web technologies.</div><div><br /></div><div>Since my experience is mainly in developing data centric applications in enterprise world, I thought of creating a sample CRUD application that would use components from both JavaFX and Swing, former being the runtime and having major presence.</div><div><br /></div><div><a href="http://www.learntechnology.net/">http://www.learntechnology.net/</a> has nice set of sample applications using most of the commonly used technology/frameworks and all of them are based on the same data model (Employee-Department). I liked the idea behind this site and decided to develop my JavaFX example using the same model, infact it uses the data layer from one of the samples there and make contribution.</div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4WhudEmDMLL5BvBeuC3ZKykdPdpaaQ7yRCKarv4gTyVZwuLpqrjuPdIYyMuCFXc1AgATfzKYhUcRDROfSNj1wyqkbf_qHg4gQgB_tIfraimzxSJllGqlmnGWbkxDfsbTE6l6bQ-yj8qw/s1600-h/javafx-crud-employee-main.JPG"><img id="BLOGGER_PHOTO_ID_5304646724784637346" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 400px; CURSOR: hand; HEIGHT: 301px; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4WhudEmDMLL5BvBeuC3ZKykdPdpaaQ7yRCKarv4gTyVZwuLpqrjuPdIYyMuCFXc1AgATfzKYhUcRDROfSNj1wyqkbf_qHg4gQgB_tIfraimzxSJllGqlmnGWbkxDfsbTE6l6bQ-yj8qw/s400/javafx-crud-employee-main.JPG" border="0" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh12oI8yHsy0Kj7gqWGHHJ800LG2XHthzdHldTq_wpzX4bOewvqqyksTCYg1KRqTaVPHkEdjljNS6ku2XetoywAxdxHvhgFbJZorqv91SwNuvHpx6rt6unNgAA3eQS5538iEbMnuF6izBY/s1600-h/javafx-crud-employee-details.JPG"><img id="BLOGGER_PHOTO_ID_5304646733298150258" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 400px; CURSOR: hand; HEIGHT: 301px; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh12oI8yHsy0Kj7gqWGHHJ800LG2XHthzdHldTq_wpzX4bOewvqqyksTCYg1KRqTaVPHkEdjljNS6ku2XetoywAxdxHvhgFbJZorqv91SwNuvHpx6rt6unNgAA3eQS5538iEbMnuF6izBY/s400/javafx-crud-employee-details.JPG" border="0" /></a><br />Please find the lesson and source at <a href="http://www.learntechnology.net/content/javafx/javafx.jsp">http://www.learntechnology.net/content/javafx/javafx.jsp</a><br /><br /><p>Click the button to start the above example using Java Webstart: <a href="http://www.learntechnology.net/content/javafx/empcrud/Employee_Management_Application.jnlp" rel="nofollow"><img src="http://sites.google.com/site/sonicread/_/rsrc/1230819339226/Home/webstart.png" /></a> </p><p> </p>Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com5tag:blogger.com,1999:blog-7220107370596871590.post-88858766992881153722009-02-05T23:57:00.001+05:302009-02-06T22:54:41.550+05:30JBoss4 Admin Reference Card<div>I have been working with JBoss quiet often recently. Though lot of documentations and tutorials are availble, they are scattered. Besides there is no reference card available for JBoss as of now. So thought of authering one.</div><div><br /></div><div>This reference card or cheatsheet is an attempt to provide a concise view of most commonly used tasks from a JBoss production environment administrators view.</div><div><br /></div><div>Please find the reference card at the following location.</div><div><br /></div><div><a href="http://www.scribd.com/doc/11790704/Refcard-JBoss-4xx-Administration">http://www.scribd.com/doc/11790704/Refcard-JBoss-4xx-Administration</a><br /></div><div><br /></div><div>Your feedbacks are welcome to improve the RefCard</div>Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com0tag:blogger.com,1999:blog-7220107370596871590.post-42709454220020613152009-01-08T10:31:00.000+05:302009-02-05T23:48:31.365+05:30Running JBoss as a Windows Service<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXX00yU9owpocP4TimmObINXMVHzT5gNC7leWHc1RjyNeOXyRkp6Kcrc-CQLFAjACIU0JHoNuU9GHQBjh8Rub0O0CRO7MjkX7JmZQ-kUA3tdBjzq-jrgNjGCbbHNPuG2ptbvi2GpJVYJQ/s1600-h/jboss-win-ser.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 132px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXX00yU9owpocP4TimmObINXMVHzT5gNC7leWHc1RjyNeOXyRkp6Kcrc-CQLFAjACIU0JHoNuU9GHQBjh8Rub0O0CRO7MjkX7JmZQ-kUA3tdBjzq-jrgNjGCbbHNPuG2ptbvi2GpJVYJQ/s320/jboss-win-ser.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5294307048076291218" /></a><br />What you need to know to run a JBoss server instance as a Windows Service.<div><br /></div><div>Until recently it was done by using JavaService.exe or tanuki wrapper. Both involved quite a bit of configurations compared to what's available directly from JBoss.</div><div><br /></div><div>Please note that this features is available in JBoss 5 by default. No need to download the files from jboss-native.</div><div><br /></div><div>This solution will work with JBoss 4 too. I have tested it on JBoss 4.0.3, JBoss 4.2.3 and JBoss 5.0.0.<br /><div><br /></div><div>Some information is available at <a href="http://jboss.org/community/docs/DOC-10679">http://jboss.org/community/docs/DOC-10679</a></div><div><br /></div><div>Download the distribution from <a href="http://www.jboss.org/jbossweb/downloads/jboss-native/">http://www.jboss.org/jbossweb/downloads/jboss-native/</a></div><div><br /></div><div>You will find links for different windows versions, select the appropriate one.</div><div><br /></div><div>The downloaded file will be in .zip format, unzip it somewhere.</div><div><br /></div><div>Copy jbosssvc.exe, service.bat and README-service.txt to your JBOSS_HOME/bin folder.</div><div><br /></div><div>The file README-service.txt contains instructions on configurations changes.</div><div><br /></div><div>Unfortunately the above file doesn't explain the part about service name related configuration</div><div><br /></div><div>By default the <span class="Apple-style-span" style="font-style: italic;">service.bat </span>contains settings entered for JBoss 5.</div><div><br /></div><div><div><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">set SVCNAME=JBAS50SVC</span></span></div><div><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">set SVCDISP=JBoss Application Server 5.0</span></span></div><div><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">set SVCDESC=JBoss Application Server 5.0.0 GA/Platform: Windows x86</span></span></div><div><span class="Apple-style-span" style="font-style: italic;"><br /></span></div><div>You may want to change it you describe your environment. If you are running multiple JBoss instances in machine, make sure you are using different values for <span class="Apple-style-span" style="font-style: italic;">SVNNAME </span>in each instance.</div><div><br /></div><div>Let's say you are using it with JBoss 4.0.3:</div><div><br /></div><div><div><span class="Apple-style-span" style="font-family:'courier new';">set SVCNAME=JBAS403SVC</span></div><div><span class="Apple-style-span" style="font-family:'courier new';">set SVCDISP=JBoss Application Server 4.0.3</span></div><div><span class="Apple-style-span" style="font-family:'courier new';">set SVCDESC=JBoss Application Server 4.0.3 GA/Platform: Windows x86</span></div><div><br /></div><div>Next part to look at is where run.bat and shutdown.bat is referred. You may want to modify there if you want to pass arguments these batch files.</div><div><br /></div><div>e.g.</div><div><br /></div><div><div><span class="Apple-style-span" style="font-family:'courier new';">jbosssvc.exe -p 1 "Starting %SVCDISP%" > </span><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">run.log</span></span></div><div><span class="Apple-style-span" style="font-weight: bold;"><span class="Apple-style-span" style="font-family:'courier new';">call run.bat </span><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">-c all -b 127.0.0.1</span></span><span class="Apple-style-span" style="font-family:'courier new';"> < .r.lock >> run.log 2>&1</span></span></div><div><span class="Apple-style-span" style="font-family:'courier new';">jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> </span><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">run.log</span></span></div></div><div><br /></div></div><div>run.log file is where console output is written to. </div><div><br /></div><div><div><span class="Apple-style-span" style="font-family:'courier new';">jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > shutdown.log</span></div><div><span class="Apple-style-span" style="font-weight: bold;"><span class="Apple-style-span" style="font-family:'courier new';">call shutdown -S </span><span class="Apple-style-span" style="font-style: italic;"><span class="Apple-style-span" style="font-family:'courier new';">--server=myserver:2099 </span></span><span class="Apple-style-span" style="font-family:'courier new';">< .s.lock >> shutdown.log 2>&1</span></span></div><div><span class="Apple-style-span" style="font-family:'courier new';">jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> shutdown.log</span></div><div><br /></div><div>shutdown.log contains console outputs after service is stopped</div><div><br /></div><div>To create/register the JBoss service with the windows service manager (This needs to be done only once)</div></div><div><br /></div><div><span class="Apple-style-span" style="font-family:'courier new';">JBOSS_HOME/bin> service.bat install.</span></div><div><br /></div><div>Now the service will be available in the windows services manager. It can be modified and operated just like any other service.</div><div><br /></div><div>If you ever want to remove the JBoss service from Windows, use the following command:</div><div><br /></div><div><span class="Apple-style-span" style="font-family:'courier new';">JBOSS_HOME/bin> service.bat uninstall.</span><br /></div><div><br /></div><div>That's all....</div><div><br /></div><div>BTW, why JBoss is run as a Windows Service?</div><div><div><ul><li>Automatically starts the process on system startup, and closes it on shutdown (when automatic) <br /></li><li>It launches the application as Windows service at system boot, before user logon and runs it without the need of a user session. <br /></li><li>Standard windows service monitoring mechanism can be utilized to check the application availability <br /></li><li>The application can be started using 'service account' without having to login as that user.<br /></li></ul></div></div><div><br /></div></div></div>Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com44tag:blogger.com,1999:blog-7220107370596871590.post-1961816192481162022008-12-03T10:41:00.006+05:302009-09-11T19:01:59.228+05:30Injecting JNDI datasource for JUnit test cases in Hibernate/JBoss environment<div><br /></div><div>Recently a project in which I am working with had faced a little bit nuisance in having to maintain a seperate set of hibernate configuration for JUnit test cases.</div><div><br /></div><div>The application is using JBoss application server, so the hibernate.cfg.xml has data source and transaction lookup class configuration specific to JBoss.</div><div><br /></div><div>Since JUnit test cases are run outside the container, it had to be replaced with hibernate's default transaction and Database Connection pool configurations.</div><div><br /></div><div>Snippet of Production configuration</div><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><br /><code><property name="hibernate.connection.datasource">java:/mysqldatasource</property><br /><property name="dialect">org.hibernate.dialect.MySQLDialect</property><br /><property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property><br /><property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property><br /></code></pre><div><br /></div>What was used for the JUnit run<div><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><br /><property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mysqldb</property><br /><property name="hibernate.connection.username">someuser</property><br /><property name="hibernate.connection.password">somepwd</property><br /></code></pre><div><br /></div><div>The problem with using the actual configuration is that for datasource and transaction manager jndi lookup, the respective object must be bound in a JNDI server.</div><div><br /></div><div>The following blog explains how to do it.</div><div><br /><a> http://blogs.sun.com/randystuph/entry/injecting_jndi_datasources_for_junit </a><br /></div><div><br /></div></div><br /><br />I am going explain further in JBoss context.<br /><br />It is a common practice that when Hibernate is used with JBoss the transaction manager used will be that of JBoss. This is done in Hibernate using the following hibernate properties.<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property><br /><property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property><br /></code></pre><br />JBossTransactionManagerLooup class in Hibernate does two jndi looups using "java:/TransactionManager" and "UserTransaction" for obvious objects. This necessitates that TransactionManager and UserTransaction implementation from JBoss has to be bound against those names respectively.<div><br /></div><div>A few minutes of searching says following are the classes</div><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;<br />import com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple;<br /></code></pre><br /><div>It possed another issue. Both of them are not Serializable and transient objects can not be bound to JNDI!!.</div><div><br /></div><div>Well the only solution I found was to create dummy extesion classes and implement Serializable interface</div><br /><br /><!--pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code--><br /><br /><pre class="brush: java"><br /><br />//Created to avoid serialization error while binding to the jndi<br />private static class CustomTXNManager extends TransactionManagerImple implements Serializable {<br /><br />private static final long serialVersionUID = 1L;<br /><br />public CustomTXNManager() { <br />}<br />}<br /><br />// Created to avoid serialization error while binding to the jndi<br />private static class CustomUserTransaction extends UserTransactionImple implements Serializable {<br /><br />private static final long serialVersionUID = 1L;<br /><br />public CustomUserTransaction() { <br />}<br />}<br /><br /></pre><br /><br /><pre class="brush: java"><br /> TransactionManager tm = new CustomTXNManager();<br /> ic.bind("java:/TransactionManager", tm); <br /><br /> UserTransaction ut = new CustomUserTransaction(); <br /> ic.bind("UserTransaction",ut);<br /></pre><br /><div>These can be included in a base JUnit class with a static block. The properties can be externalized in a properties file to reduce the hard coded parts. Below is the entire static block declaration and a static util method I have used.</div><div><br /></div><br /><pre class="brush: java"> static {<br /><br /> try {<br /> // Create initial context<br /><br /> Properties props = new Properties();<br /> props.load(AbstractTestCase.class.getClassLoader()<br /> .getResourceAsStream("mytest.properties"));<br /><br /> System.setProperty(Context.URL_PKG_PREFIXES, props<br /> .getProperty("java.naming.factory.url.pkgs"));<br /><br /> System.setProperty(Context.INITIAL_CONTEXT_FACTORY, props<br /> .getProperty("java.naming.factory.initial"));<br /><br /> // to avoid discoverServer error<br /> NamingServer server = new NamingServer();<br /> NamingContext.setLocal(server);<br /><br /> // Construct DataSource<br /> MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();<br /> // For Oracle database use the following (no common interface, hence<br /> // can't generalize; well reflection would help)<br /> // OracleConnectionPoolDataSource ds = new<br /> // OracleConnectionPoolDataSource();<br /> ds.setURL(props.getProperty("ds.url"));<br /> ds.setUser(props.getProperty("ds.username"));<br /> ds.setPassword(props.getProperty("ds.password"));<br /><br /> InitialContext ic = new InitialContext();<br /><br /> String dsName = props.getProperty("ds.name");<br /><br /> String[] cxts = dsName.split("/");<br /><br /> String inCxt = cxts[0];<br /> createSubcontext(ic, inCxt);<br /> for (int i = 1; i < cxts.length - 1; i++) {<br /> // if the data source name is like java:/comp/mysqldatasource<br /> // this takes care of creating subcontexts in jndi<br /> inCxt = inCxt + "/" + cxts[i];<br /> createSubcontext(ic, inCxt);<br /> } <br /><br /> ic.bind(dsName, ds);<br /><br /> // The following binding is done to support the hibernate properties<br /> // hibernate.transaction.factory_class and transaction.manager_lookup_class <br /><br /> // the following requires JBoss dependent class. May be sth can be done<br /> // to generalize this<br /> TransactionManager tm = new CustomTXNManager();<br /> ic.bind("java:/TransactionManager", tm); <br /><br /> UserTransaction ut = new CustomUserTransaction(); <br /> ic.bind("UserTransaction",ut);<br /><br /> } catch (Exception e) {<br /> // what can be done?<br /> e.printStackTrace();<br /> }<br /><br />}<br /><br />// copied from org.jboss.naming.Util<br />private static Context createSubcontext(Context ctx, String cxtName)<br /> throws NamingException {<br /> //System.out.println(" creating subcontext " + cxtName);<br /> Context subctx = ctx;<br /> Name name = ctx.getNameParser("").parse(cxtName);<br /> for (int pos = 0; pos < name.size(); pos++) {<br /> String ctxName = name.get(pos);<br /> try {<br /> subctx = (Context) ctx.lookup(ctxName);<br /> } catch (NameNotFoundException e) {<br /> subctx = ctx.createSubcontext(ctxName);<br /> }<br /> // The current subctx will be the ctx for the next name component<br /> ctx = subctx;<br /> }<br /> return subctx;<br />}<br /></pre><br /><br />Property file contents<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>ds.name=java:/mysqldatasource<br />ds.url=jdbc:mysql://localhost:3306/mysqldb<br />ds.username=someuser<br />ds.password=somepwd<br />java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory<br />java.naming.factory.url.pkgs=org.jboss.naming<br /></code></pre><br /><div>Hope this information helps solving some of the issues you are facing. If you need some clarifications let me know.</div>Vijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com2tag:blogger.com,1999:blog-7220107370596871590.post-36651068637843042402008-07-26T20:24:00.000+05:302008-07-29T22:37:05.137+05:30Getting exposed: My first blogTrue to being a lazy person, after a few years since I first thought of writing blogs, today I have taken the plunge. Everything happened quickly, there wasn't any planning at all - so the weird name of the Blog.<br /><br />Why do I want to write blog? - to impress others? to become famous? to educate others? to share my knowledge?. None of these, I just wanted to cement/enhance whatever I have already learned;by writing about them :). Till now I haven't done much writing other than coming up with work related documents though I am a voracious reader.<br /><br />A recent talk I had attended made me realize the importance of writing vis-a-vis reading. The speaker was making a point that writing enhances ones knowledge and that it's not just about describing something one already know. In order to write something meaningful, one has to do a lot of research, update knowledge etc. Also the effort required is high; one has to structure the narration, articulate the content properly, use proper words.<br /><br />So, what am I going to write about?<br /><br />About my random thoughts :)<br />About movies.<br />About books.<br />About Software Technologies<br />About what I think one can do to better human lives.<br />About my country, countrymen.<br />And may be some other topicsVijesh Aaniyamveetilhttp://www.blogger.com/profile/04553167436004511383noreply@blogger.com0