Archive for the 'Java' Category

catch that ESB! – ServiceMix the right concoction for all your ESB needs.

Yes i’ve been lazy! as always!. And this latest post is in response to the question "time to update ur blog?" from someone i know. You know who you are :D , and i know you are the only one reading it :p
So here goes, educate yourself :D . Go back to your Maths and Physics after ur done, ok?

What is ESB?

ESB (Enterprise Service Bus) is not just a fancy name used in the Java world, Its become an iconic term when people talk about "Integration". Imaging 10 different applications wanting to communicate with each other by some means, and lets say each application has some form of communication link between them, the end result? a mesh of communication links running across each of the individual applications resulting in CHAOS! The way ESB solves this problem is providing a single interface to for application to communicate to each other, synonymous to a line and different components connected to the same line at different places. Something like a BUS? :D

Now for some technical jargon….. 

The purpose of an ESB is to facilitate application and process integration by providing distributed processing, intelligent routing, security, and dynamic data transformation. In an ESB these services are infrastructure services so each application does not have to implement these requirements independently and in a proprietary manner. The ESB addresses the disadvantages of existing solutions by creating a standard infrastructure for integration. Point-to-point solutions, where each of n components requires n-1 interfaces for full communication, are replaced by a bus solution where each component requires a single interface to the bus for global communication. An ESB provides distributed messaging, routing, business process orchestration, reliability and security. It also provides pluggable services and, because of the standard bus, these pluggable services can be provided by third parties and still interoperate reliably with the bus.

ServiceMix – Whats it all about?

ServiceMix was an Apache incubator project which finally graduated and is now an Apache top level project. Apache ServiceMix is an Open Source ESB (Enterprise Service Bus) that combines the functionality of a Service Oriented Architecture (SOA) and an Event Driven Architecture (EDA)  to create an agile, enterprise ESB. Its an open source distributed ESB built from the ground up on the  Java Business Integration (JBI) specification JSR 208 and released under the Apache license. The goal of JBI is to allow components and services to be integrated in a vendor independent way, allowing users and vendors to plug and play. 

Why ServiceMix?

There are many vendors that provide ESB solutions (like Oracle ESB and IBM Websphere ESB), but there is no universal agreement as to the best design or architecture for an ESB. ServiceMix has a design that is based on the JBI (JSR 208) specification in order to create a standards based ESB and the ServiceMix ESB combines the functionality of both a Service Oriented Architecture (S0A) and Event Driven Architecture (EDA) to achieve an agile, enterprise ESB.As previously stated, ServiceMix is an open source ESB that is based on the Java Business Integration (JBI) standard. These two factors, open source and open standards-based, allow for low entry cost, maximum flexibility, reuse, and investment protection.

ServiceMix uses yet another Apache project ActiveMQ to provide remoting, clustering, reliability and distributed failover. Iam not going to go into any details on using ServiceMix, there are already plenty of resource for it on the project’s homepage. So goahead and give it a try.

JBoss Seam (EJB3+JSF+WORKFLOW)

Ok you wanted a sneak peak into EJB3? find a way to integrate JSF with EJB3?

Well here comes JBoss Seam it has everything u need to get started with EJB3 and also to find out how cool JSF can be when integrated with EJB3. I came across some nice features about Seam when i visited the Linux Asia 2006 conference held in New Delhi, India. I met Subramaniam Satyamoorthy (Director of Operations and Services (Asia Pacific)) , quite a funny guy :) . He showed us some of the workings of Seam, that got me hooked into it. And i am still experimenting with a lot of interesting stuff in it, not to mention JBoss jBPM which i had no idea about untill i knew about JBoss Seam. EJB3 uses Hibernate for persistance so you got best of both worlds :p. Maybe after a while i might  just post some code for download regrading Seam. Eventhough Seam is still in beta its still a handfull.  So check it out at http://www.jboss.com/products/seam 

and oh btw, you need to either select "ejb3 cluster" or "ejb3" profile while installing Jboss Application Server .

Single Sign-On with CAS (Central Authentication Service)

First things first,

What is Single Sign-On?
: Wikipdedia has this definition for it.

CAS (Central Authentication System): Its a project started by Yale university to provide a trusted way for an application to authenticate a user (ref: The JA-SIG CAS Project)

I came across CAS when i was searching for a Single Sing-On framework for a project, i did find another similar project Java Open Single Sign-On Project (www.josso.org). And the reason why i choose CAS is its Proven track record. CAS has been successfully implemented in a lot of projects not to mention Yale University has been using it for a long time now (Ok you could have guessed that :p).

When i downloaded the source and deployed the web application that came with it, i thought the java cas-client would work just out of the box. Well it would have, if i had a valid server certificate for my tomcat server, compared to my self-signed certifcate to make tomcat work with SSL. Wasn’t too long until i realized what was causing the problem the class edu.yale.its.tp.cas.util.SecureURL (inside the Java Cas Client) that was downloaded from http://www.ja-sig.org/products/cas/client/javaclient/index.html which didn’t accept my self-signed certificate from the server. So i just went back and changed it :) Everything after that went super smooth, not to mention trying to use CAS everywhere i could :p

I played around with it a bit and installed a simple LDAP Authentication handler for the CAS Server application, this is an extract from the file WEB-INF/deployerConfigContext.xml

<bean id=“ldapAuth” class=“org.tecnova.cas.authentication.handler.support.LDAPAuthenticationHandler”>
     <property name=“providerUrl”>
         <value>ldap://localhost:389</value>
     </property>
 
     <property name=“credentialQueryString”>
         <value>cn=#username#,ou=Employees,dc=tecnova,dc=com</value>
     </property>
 
 </bean>
 …
 …
 …
 
 <property name=“authenticationHandlers”>
     <list>
         <bean class = “org.jasig.cas.authentication.handler.support.
 HttpBasedServiceCredentialsAuthenticationHandler”
  />

         …
         …
         <ref local=“ldapAuth” />
     </list>
 </property>

and to enable CAS authentication on the client application all we need are the following entries in the WEB-INF/web.xml of the Client web application.

<web-app>
 …
 …
     <filter>
         <filter-name>CAS Filter</filter-name>
         <filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>
       
         <init-param>
             <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
             <param-value>https://localhost/cas/login</param-value>
         </init-param>
 
         <init-param>
             <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
             <param-value>https://localhost/cas/proxyValidate</param-value>
         </init-param>
 
         <init-param>
             <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
             <param-value>localhost</param-value>
         </init-param>
 
     </filter>
 
     <filter-mapping>
         <filter-name>CAS Filter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
 …
 …
 </web-app>

Remember my tomcat is set to listen on port 80 and has SSL enabled, CAS won’t work without SSL enabled on your app server.

For rest of the details on what I did I have attached a sample Server and Client web application. Which can be downloaded here.

Using Apache Axis to create Web Services

Apache axis, is one of the best way to deploy Web Services without needing to buy those expensive Application Servers out there. Axis is deployed as a simple web application, with web services deployed as either simple .jws files or more complex compiled classes. Web Services can either be coded as simple java classes and later renamed to .jws rather than the usual .java, when invoked via axis using a url like http://localhost:8080/axis/services/MyService.jws, Axis compiles the code and exposes it as a SOAP Web Service. The other way of deploying a web service is by compiling the code and writing something called as the "Web Service Deployment Descriptor (WSDD)" WSDD files describe a Web Service,ex: the actual class and the methods that have been exposed in the Web Service, the scope of the Web Service etc. A sample axis Web Application which contains both a service (Calc) and a Client for the Web Service (Calc.jsp) can be found here.

Using Jasper Reports with Hibernate and Teamwork

Jasper Reports is the perfect open source reporting tool for the masses, heres a code snippet to generate the "Operator by Worklog" sample report using Jasper Report in Teamwork 3

 

CompanyCalendar cc = new CompanyCalendar();
 
 cc.set(CompanyCalendar.YEAR, cc.get(CompanyCalendar.YEAR)1);
 cc.set(CompanyCalendar.MONTH, CompanyCalendar.JANUARY);
 cc.set(CompanyCalendar.DAY_OF_MONTH, 1);
 
 OqlQuery oql = new OqlQuery(“select new map(r.id as id, r.personName as personName , r.personSurname  as personSurname, sum(w.duration) as worklog_total) from com.twproject.resource.Resource r, com.twproject.worklog.Worklog w where w.assig = r.myself and w.inserted > :paramInserted and r.myself is not null group by r.id”);
 
 oql.setParameter(“paramInserted”,cc.getTime());
 List persLog = oql.list();
 
 Map parameters = new HashMap();
 
 InputStream reportStream = new FileInputStream(
 request.getRealPath(“applications/teamwork/reports/jrxml/new_worklog.jrxml”));
 JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
 JasperReport jasperReport = JasperManager.compileReport(jasperDesign);
 
 JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(persLog);
 JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);
 
 //—- Export PDF —-
 JasperManager.printReportToPdfFile(jasperPrint, request.getRealPath(“”) + “/applications/teamwork/reports/output/report.pdf”);
 
 //—- Export HTML —-
 JasperExportManager.exportReportToHtmlFile(jasperPrint, request.getRealPath(“”) + “/applications/teamwork/reports/output/report.html”);

 

Sample worklog.jrxml for Teamwork 3