-
1. Re: JbossWS 1.2.0
thomas.diesler Mar 2, 2007 4:05 AM (in response to matienzar)This is correct. The handler should be scoped on the endpoint NOT on the request.
You can put you UserTransaction in the MessageContext or use a ThreadLocal -
2. Re: JbossWS 1.2.0
matienzar Mar 2, 2007 4:11 AM (in response to matienzar)Thanks, but how can i put the usertransaction into the messagecontext?
-
3. Re: JbossWS 1.2.0
heiko.braun Mar 2, 2007 5:20 AM (in response to matienzar)There is currently no portable way of doing this in 4.0.5. @WebServiceContext injection will be available with 4.2.
In the meantime you can access the message context like this:CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext(); msgContext.setProperty(<Name>, <Value>);
-
4. Re: JbossWS 1.2.0
heiko.braun Mar 2, 2007 8:21 AM (in response to matienzar)I didn't realize your first post.
In case you want to populate the context from within a handler, it's passed in as a parameter. -
5. Re: JbossWS 1.2.0
matienzar Mar 2, 2007 8:50 AM (in response to matienzar)I've solve it with this code:
public class HibernateWS extends GenericSOAPHandler {
@Override
public boolean handleFault(MessageContext msgContext) {
UserTransaction _tx = null;
try {
if (msgContext.containsKey("hibernateTrx")){
_tx = (UserTransaction)msgContext.get("hibernateTrx");
_tx.rollback();
}
} catch (Exception e) {
Log.error("No se ha podido hacer el rollback", e);
throw new RuntimeException(e);
}
return super.handleFault(msgContext);
}
@Override
protected boolean handleInbound(MessageContext msgContext) {
try {
HibernateUtil.openSession();
UserTransaction _tx = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
_tx.begin();
msgContext.put("hibernateTrx", _tx);
} catch (Exception e) {
Log.error("Cogiendo la transacción.", e);
}
return true;
}
@Override
protected boolean handleOutbound(MessageContext msgContext) {
UserTransaction _tx = null;
try {
if (msgContext.containsKey("hibernateTrx")){
_tx = (UserTransaction)msgContext.get("hibernateTrx");
_tx.commit();
}
} catch (Exception e) {
Log.error("Haciendo el commit", e);
try {
if(_tx != null)
_tx.rollback();
} catch (Exception e2) {
Log.error("Haciendo el rollback", e2);
}
throw new RuntimeException(e);
}
return true;
}
}
I use Jboss 4.0.5