Posts

Showing posts from 2013

Spring Data JPA & Spring 3 Transactions Through JTA and Atomikos

In this article I will discuss about Spring Transactions with JTA. The underlying JTA implementation with Atomikos. The server platform is jBoss7. The XA-DataSource configured in jBoss AS7 is of the type Oracle 10g. The Underlyimg Persistence Provider in Hibernate 4. I have used the Hibernate Module already available with jBoass AS7, but during Startup of my application I faced some issues for which i have to Externally plug in the jar "hibernate-core-3.6.0.Final.jar", Tried to find out the reason behind but remain undone. Now before going into the discussion, I will first try note down the jars that I have used, as this portion has Given me Immense pain due to lack of proper Documentation. jar List --------------------------------- 1) hibernate-core-3.6.0.Final.jar 2) transactions-jta-3.6.4.jar 3) atomikos-util-3.6.4.jar 4) transactions-3.6.4.jar 5) transactions-api-3.6.4.jar 6) transactions-hibernate3-3.6.4.jar 7) transactions-jdbc-3.6.4

Memento Pattern with AspectJ

Hello Friends, This time i have implemented Memento Pattern with AspectJ. In Memento Pattern, there are two roles: 1) Originator & 2)Memento Originator is the Object or the Entity that we are working with. Memento is the artifact where we are going to save the state of the Originator, so that when required we can roll back the current state of the Originator with the state saved in the Memento. Here I have saved only the state of the Originator during Initialization. Multiple states of Originator as required can be saved in Memento and can be restored when required based on the requirement. Intersting Huh!!!! We are going to implement this feature with AspectJ public abstract aspect MyNewAspectMementoPattern { public interface Originator { public void setMemento(Memento memento); //public Originator getObject(); public Originator restoreState(); } public interface Memento { public void setState(Originator originator); public Originator getSt

State Pattern with Aspect

Today I am going discuss Implementation of State Pattern throgh AspectJ In state Pattern there are two roles to watch out for, The Context and the state. The Context Role contains state. Now when an operation is required to be carried out on context then the state is checked Now based on the state, the operation on the state is undertaken and if required the new state is set in context. The mentioned operation is carried out through the AspectJ. public abstract aspect MyNewAspectStatePattern { public interface Context { public void setState(State state); public State getState(); } public interface State { public void perform(); } public abstract pointcut interceptInitialState(Context context/*,com.aspectj.target.State state*/); } In the above aspect there are two states as mentioned, the Context and the State. The context has the state within itself and the State role has the perform method for performing operations. public aspect MyNewAspe

Aspect's Paradigm With Design Patterns (Proxy Pattern)

Implementation of Design patterns with AspectJ is another intersting episode of AspectJ. After I have implemented a few such Design patterns, I came to realize the power of AspectJ and How beautiful it is. So,I will share my expereince with this dimension of AspectJ Proxy Pattren First, I have created some Utility classes which will be assigned some role using Aspects Dynamically. package com.aspectj.target; import java.io.IOException; import javax.naming.OperationNotSupportedException; public class PureSubject { public String write() { System.out.println(" @@@ In PureSubject.write() @@@ "); return "### PureSubject.write() completed ###"; } public String read() throws OperationNotSupportedException { throw new OperationNotSupportedException("This Operation is not Supported in this version"); } public String update() throws OperationNotSupportedException { throw new OperationNotSupportedException("This Operatio

Aspects of AspectJ

Image
This time I will share my experience with AspectJ. Aspects evolve for the separation of cross cutting concerns from the business logic. The cross cutting concerns evolve Logging,Transaction Management,Security Concerns etc. i.e. anything that is not inherently related with Business Logic. For implementing aspects we need to know about AspectJ programming syntax, which are not exact replica of java files but almost similar and follows all oops concepts. The source files are with extension .aj and the source files are compiled to .class files(in exact bytecode format like normal java class files) by the AspectJ compiler so that any JVM can execute the compiled aspects. Whenever we talk about aspects one term always comes to our mind that is WEAVING . Aspects are woven into the source code at 1) Compile time (Compile Time Weaving) 2) Load Time (Load Time Weaving) 3) Run Time (Th

Stax Parsing

Image
Here, I will provide STAX parsing Outline. STAX is streaming parsing API. Now the question arises, that why should we use STAX, instead of DOM,SAX,JAXP (well known tools for working with the XML infosets) and other XML parsing API's, what extra benefit does STAX provides us, so here it is: 1) StAX is a streaming PULL-PUSH parsing java API for reading and writing XMLs. 2) StAX API is a set of interfaces providing a framework for bi-directional parser. It provides two sets of APIs, cursor and iterator based. 3) Unlike DOM it doesn't load the entire Document tree in the memory(i.e. In Memory Objects), but it uses the Streaming Architecture just like File Streaming and thus reducing memory footprint. 4) Like JDBC StAX is a standard, and there are different implementations confirming to those standards like stax.codehaus, sjsxp,woodstox etc. 5) The Streaming API provides us with advantage of reading and writing large XML documents sequentially, performing operat

Custom CAS Service Ticket Validator

Service Ticket Validator is used by the Application(Spring here) for validating the ticket as provided by CAS to the application during login (Cross Verification). For my own understanding  and to implement Custom features as applicable I have implemented custom Ticket Validator. Every Ticket Validator must implement TicketValidator interface, which contains a single validate method and it returns a Assertion. In the validate() method, we contruct the validation URL from the ticket(to be validated by the application) as returned by the CAS server during login and the CASService properties. Now using the Valdation URL as constructed above and the ticket(to be validated by the application) as returned by the CAS server during login, response is retrieved from the server. The response is in XML format. The response is then parsed to create an object of type Assertion, which is returned from the validate() method. The custom attributes if configured through Attribute Repository(

Credential to Principal Resolver and Attribute Repository

In this blog I will share my experience with Credential to Principal Resolver of CAS. After the user has been successfully authenticated by the Custom Authentication Handler (as provided in the previous blog), then there comes the Credential to Principal Resolver of CAS. Now before going into the architecture of Credential to Principal Resolver of CAS we have to get some idea regarding AuthenticationManager of CAS which corresponds to bean id "authenticationManager" and class "org.jasig.cas.authentication.AuthenticationManagerImpl" of the deployerConfigContext.xml of CAS war. This authenticationManager at first lopps through all the registered list Authentication Handlers configured in the deployerConfigContext.xml holding the property name "authenticationHandlers" of the bean "authenticationManager" to get the user authetication and then it loops through all the registered list of Credential to Principal Resolver configured in the d

Pre Requisites for CAS

Now before going on to the discussion on Custom Credential To Principal Resolver which requires attribute Repository for fetching user attributes from the underlying repository, In this post I will take up the issue of configuring CAS to use over HTTPS. While configuring CAS over Https I faced the exception Error javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. Though I have configured custom HostNameverifier still I was facing the above error. The reason behind the above error i found out is that the certificate which i was using was not added to the truststore. This issue can be resolved with the following steps: 1) Locate the cacerts file from the JDK, which the server is using.     The usual path is jdk1.6.0_05\jre\lib\security\cacerts    2) Run the following command from the command promt: