Skip to main content

How to use Global Transactions and Data Sources with Spring Framework 2.0.8 in SAP Netweaver Aplication Server 7.0, Part 1

For this part, we will create, build and deploy a J2EE Application on SAP AS 7.0 with J2SE 1.4, and the version of Spring Framework is 2.0.8 because it is the last one that can be supported by J2SE 1.4.

For the Spring XML configuration we will use the XML configuration syntax based on XML Schema, also we could use syntax based on XML DTD for backward compatibility. Because of we are using J2SE 1.4, we will need a parser that supports XML Schema like Xerces.

We need to remind that when you create an application with transaction support, we could use 2 type of transaction:

  • Local Transaction are resource-specific (by example when only we work with one resource that needs transaction support like jdbc connection).
  • Global Transaction are managed by the application server using JTA, it provide the ability to work with multiple transactional resources (by example when we work atleast two resources that need transaction support like jdbc connection, and jca connection).
Now, we must follow the next steps:

1. Create a Java Project and add the Spring Libraries and its dependence libraries, and Xerces library too. Here, we will create the Spring XML Configuration file like Figure 1.

Figure 1

Here, we are using the new Spring AOP Tags to use transaction in our application. The most important thing related to this blog is the transaction-manager attribute of the tx:advice tag.

2. We will create the Spring bean to control the transaction. It is the transaction manager bean like the figure 2.

transaction manager
Figure 2

In this part, we are using the default name for the transaction manager bean. Also, we are declaring 2 properties: userTransactionName and transactionManagerName.

The default JNDI location for the JTA UserTransaction is java:comp/UserTransaction, but in the SAP AS the JNDI Name for it is "UserTransaction", it is reason because we will use it on the userTransactionName property of the "transactionManager" Spring bean. The other property, transactionManagerName, is necessary for suspending and resuming transactions, as this not supported by the UserTransaction interface. The TransactionManager will be autodetected if the JTA UserTransaction object implements the JTA TransactionManager interface too, but how we don't know the exactly implementation of the JTA UserTransaction interface, it is better to use the right JNDI value on the SAP AS ("ts").

This Spring bean "transactionManager" is used in the advice with id "myServiceTxAdvice". It give us the posibility to use global transactions in our code. It together with pointcut named "serviceOperation" allows to wrap every method on the class MyService that follow the expression "execution(* *..service.MyService.*(..))".

The Spring XML configuration file could be used in Spring MVC proyect, or Java project with some class to load the Spring Xml file (by example using the org.springframework.context.support.ClassPathXmlApplicationContext class as Figure 3).


Figure 3

The next part of this blog we learn about how to use J2EE Data sources on J2EE Application with Spring Framework on SAP AS 7.0

Comments

Popular posts from this blog

My first serious Groovy class ..... decompiling java classes with closures

After I read the chapter 6 "closures" of the book Groovy and Grails Recipe, and I decided to use the power of closures of Groovy for resource (files) with other problem that I had, decompile in one step every class of jar library. Well, the purpose of this class is call an external java decompiler (jad) from a Groovy class and execute the command into directory where the jar file was decompressed. And by using the power of closures executes recursively into this directory until find the classes. Well, no more words, here the class package demo class Executor { // directory where the library(jar) was decompressed def path /** * Execute the decompilation of the classes into the directory defined in the path * @return */ def decompileClasses(){ def directory = new File(path) //make use of closures defined in the Object class directory.eachFileRecurse { def name = it.absolutePath //if the current resource hasn't a .class extension continues with

How to .. Integration Non-SAP J2EE-based Web Applications into SAP Portal with SSO Part 1

We are going to integrate Non-SAP J2EE-based Web Applications into the SAP Portal with Application Integrator and SSO. In this part, I will discuss the overall of these posts and configure the iView with Application Integrator Overview of Integration. To perform this integration must take into account the following steps: Deployment of the portal application for the creation of the system portal object Create and set the type of Application Integrator iView that will contain the applications to integrate. Installing SAPSSOEXT and SAPSECU libraries Deployment of the application gateway called SsoGatewayWeb Changing the target application. This integration has the following restrictions: It applies only for web applications based on J2EE Servlet. Depend exclusively on the sucessful load of the libraries supported by SAP (sapssoext and sapsecu) in both Windows and UNIX environments. The target application must have created a profile for the user id logged to the SAP portal, this sh

Convert HTML Content to PDF format using Java

I have researched about to convert HTML to PDF. I got 2 approaches. 1. Using Tidy and XSL-FO. 2. Using the project xhtmlrenderer Basically the 1st approach is : 1. Your HTML will need to be validate in according to XHTML, for this you could use Tidy . 2. After you will need to transform this new XHTML document in XLS-FO, you can review this link to find the stylesheet resource ( XHMTL to XLS-FO ). 3. Finally, convert your XLS-FO document in a PDF document. There are 2 links that could help with this approach: http://www.onjava.com/lpt/a/3924 http://www.javaworld.com/javaworld/jw-04-2006/jw-0410-html.html The 2nd approach is using the project xhtmlrenderer (https://xhtmlrenderer.dev.java.net/) This is easier than 1st approach. This tool hides the steps mentioned in the 1st approach and use CSS. This project uses a CSS parser (http://sourceforge.net/projects/cssparser/). the unique problem the I found out was when you want to use external CSS file in your HTML file. In the example use