5 Replies Latest reply on Mar 2, 2007 8:50 AM by marcial atienzar

    JbossWS 1.2.0

    marcial atienzar Newbie

      Hello,

      With 1.0.4 release, i've a hibernate handler to begiun a transaction and to commit it. With this new realese, the handler is not threadsafe, and when I need to commit the transaction, it's null. I'd defined the handler (with 1.0.4) in standard-jaxrpc-endpoint-config.xml, but with this new realse i've to define it in standard-jaxws-endpoint-config.xml.

      The code of the handler is:
      public class HibernateWS extends GenericSOAPHandler {
      UserTransaction _tx = null;

      @Override
      public boolean handleFault(MessageContext arg0) {
      try {
      _tx.rollback();
      } catch (Exception e) {
      Log.error("No se ha podido hacer el rollback", e);
      throw new RuntimeException(e);
      }
      return super.handleFault(arg0);
      }



      protected boolean handleInbound(MessageContext msgContext) {
      try {
      HibernateUtil.openSession();
      _tx = (UserTransaction) new InitialContext()
      .lookup("java:comp/UserTransaction");
      _tx.begin();
      } catch (Exception e) {
      Log.error("Cogiendo la transacción.", e);
      }
      return true;
      }

      protected boolean handleOutbound(MessageContext msgContext) {

      try {
      _tx.commit();
      } catch (Exception e) {
      Log.error("Haciendo el commit", e);
      try {
      _tx.rollback();
      } catch (Exception e2) {
      Log.error("Haciendo el rollback", e2);
      }
      throw new RuntimeException(e);
      }
      return true;
      }
      }

      And the config-handler:
      <endpoint-config>
      <config-name>Handler hibernate gnomo</config-name>
      <pre-handler-chains>
      <javaee:handler-chain>
      <javaee:protocol-bindings>##SOAP11_HTTP</javaee:protocol-bindings>
      <javaee:handler>
      <javaee:handler-name>WSHibernateHandlerInbound</javaee:handler-name>
      <javaee:handler-class>org.muvale.utilidades.handlers.HibernateWS</javaee:handler-class>
      </javaee:handler>
      </javaee:handler-chain>
      </pre-handler-chains>
      </endpoint-config>


      A lot of thanks,

      Marcial

        • 1. Re: JbossWS 1.2.0
          Thomas Diesler Master

          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
            marcial atienzar Newbie

            Thanks, but how can i put the usertransaction into the messagecontext?

            • 3. Re: JbossWS 1.2.0
              Heiko Braun Master

              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 Master

                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
                  marcial atienzar Newbie

                  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