Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-5854

automatic manage of tx in webengine filter

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.4
    • Component/s: WebEngine

      Description

      WebEngine filter should:

      • start/close tx if required
      • provide a stateless/stateful core session which is automatically closed when needed
      • enable modules to overwrite default behavior per a path basis.

      By default webengine will start tx for any request to a JAX-RS application. /skin/ paths are ommited to avoid tx on static resources
      You can configure the default behavior using the runtime property:
      org.nuxeo.webengine.tx.auto=true|false

      By default session is stateless for any JAX-RS request. You can configure this behavior by using the framework variable:
      org.nuxeo.webengine.session.stateful=true|false
      Note that if you enable stateful session the requests belonging to the same HttpSession will be synchronized to avoid concurrent access to the same core session.

      To configure tx and stateful flag on a path basis you should use an extension like:

      <extension target="" point="">
      <path value="/mymodule1" autoTx="false" stateful="true" />
      <path value="/mymodule2/resources" autoTx="false" />
      <path value="/mymodule3/.*\.gif" autoTx="false" regex="true"/>
      </extension>

      Path matchers will be sorted from logest path string to the smallest one, prefixes tried matched first, and after that regex matchers are tried.
      Ex:
      /module1/myresource
      /module1
      /module1/.*

      Anyway it is recommended to use path prefixes and avoid regex for better perfs.

      To get the provided core session in a resource you can use:
      UserSession.getCurrentSession(httpRequest).getCoreSession();
      or
      UserSession.getCurrentSession(httpRequest).getCoreSession("repoName");

      The session will be closed by webengine - so you don't need to worry about that.
      Also if you want to do cleanup after the request was done (for example removing any temporary file or closing other resources) you can use:

      UserSession.addRequestCleanupHandler(httpRequest, new RequestCleanupHandler() {
      cleanup(HttpServletRequest httpRequest)

      { .... }

      });

      in a JAX-RS or MessageBodyWriter class.

      If you need the current UserSession you can get it in either using:
      UserSession.getCurrentSession(httpRequest)
      either
      WebEngine.getActiveContext().getUserSession()

      Not that the usersession is available only on requests threads that are dispatched to webengine (JAX-RS apps or webengine apps)

        Attachments

          Activity

            People

            • Assignee:
              bstefanescu Bogdan Stefanescu
              Reporter:
              bstefanescu Bogdan Stefanescu
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: