• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UserTransaction in JBOSS

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

JBOSS Version = jboss-4.0.3SP1.

In JSP Page i'm using custom taglib to manage the transaction

<demo:transaction>
CRUD Operations going here and I'm using CMP Beans for that
</demo:transaction>

and the tag class is TransactionTag which is explained here


import java.util.Collection;
import java.util.Vector;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TryCatchFinally;
import javax.transaction.Status;

import javax.transaction.UserTransaction;

public class TransactionTag extends BodyTagSupport implements TryCatchFinally {

private static UserTransaction transaction = null;
private static Collection activeThreads = null;

public TransactionTag() {
super();
}

public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);

if (transaction == null) {
try {

Context context = (Context)getInitialContextStatic();
transaction = (UserTransaction) context.lookup("UserTransaction");
activeThreads = new Vector();
} catch (Exception e) {
throw new CascadingRuntimeException(e);
}
}
}

public int doStartTag() throws JspException {
try {
if (transaction.getStatus() != Status.STATUS_ACTIVE) {
activeThreads.add(Thread.currentThread());
transaction.begin();
}
} catch (Exception e) {
throw new JspException(e.getMessage(), e);
}

return EVAL_PAGE;
}

public void doCatch(Throwable t) throws Throwable {
if (activeThreads.contains(Thread.currentThread())) {
activeThreads.remove(Thread.currentThread());

if (transaction.getStatus() == Status.STATUS_ACTIVE) {
try {
transaction.rollback();
} catch (Exception e) {
}

}

}
throw t;
}


public void doFinally() {
if (activeThreads.contains(Thread.currentThread())) {
activeThreads.remove(Thread.currentThread());

try {
transaction.commit();
} catch (Exception e) {

try {
transaction.rollback();
} catch (Exception e1) {
}

throw new CascadingRuntimeException(e);
}
}
}


public void removeThread() {
if (activeThreads.contains(Thread.currentThread())) {
activeThreads.remove(Thread.currentThread());
}
}

public InitialContext getInitialContextStatic() {
Hashtable hashTable = new Hashtable();
hashTable.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
hashTable.put(Context.PROVIDER_URL, "jnp://localhost:1099");
hashTable.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
return new InitialContext(hashTable);
}

}



When i run the jsp page the contents between the demo:transaction tag is not executing properly. I am getting blank page and without any error. Is this because of Usertransaction or some other issue.
It is working fine with weblogic 8.1

Is that any usertransaction configuration that i'm missing.

Thanks in advance
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic