Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-4083

Sling Models: Enable SlingObject injector to inject all context objects when a request is attached to the current thread

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: Sling Models Implementation 1.1.0
    • Fix Version/s: None
    • Component/s: Extensions
    • Labels:

      Description

      The SlingObjectInjector should support injecting all context objects (Resource, ResourceResolver, Request, Response, SlingScriptHelper) always, and not only when derivable from the current adaptable.

      in sling models 1.1.0 the injection of most of those objects fails e.g. when adapting from a resource resolver because the request object is not available. thus if a developer uses a @SlingObject annotation he has to be aware of those implementation details when the context objects are available and when not. if used from a scripting language light Sightly which first tries to adapt a model from the current resource, and after that from the current request things get worse.

      if a model is adapted in a thread initiated from a request all injections should be always supported.

        Issue Links

          Activity

          Hide
          kwin Konrad Windszus added a comment -

          Just for the reference: the mailing list thread about using ThreadLocals is at http://www.mail-archive.com/dev@sling.apache.org/msg37982.html

          Show
          kwin Konrad Windszus added a comment - Just for the reference: the mailing list thread about using ThreadLocals is at http://www.mail-archive.com/dev@sling.apache.org/msg37982.html
          Hide
          sseifert@pro-vision.de Stefan Seifert added a comment -

          Completed: At revision: 1635446

          reverted all changes for this ticket in trunk.

          implementation is available in branch:
          https://svn.apache.org/repos/asf/sling/whiteboard/sseifert/SLING-4083_models_slingobject_threadlocal

          we will pick up this again if a agreement on this is achieved in the mailing list - otherwise we can postpone or close it, it's still possible to implement such a functionality in a custom injector.

          Show
          sseifert@pro-vision.de Stefan Seifert added a comment - Completed: At revision: 1635446 reverted all changes for this ticket in trunk. implementation is available in branch: https://svn.apache.org/repos/asf/sling/whiteboard/sseifert/SLING-4083_models_slingobject_threadlocal we will pick up this again if a agreement on this is achieved in the mailing list - otherwise we can postpone or close it, it's still possible to implement such a functionality in a custom injector.
          Hide
          sseifert@pro-vision.de Stefan Seifert added a comment -

          yes, indeed! - will start a thread on this

          Show
          sseifert@pro-vision.de Stefan Seifert added a comment - yes, indeed! - will start a thread on this
          Hide
          justinedelson Justin Edelson added a comment -

          Stefan Seifert I think this warrants some discussion on sling-dev. I have two concerns.

          1) This ThreadLocal filter doesn't seem to be appropriate as part of Sling Models. If such a filter is going to be part of Sling it should IMHO be done in the engine and then used across the codebase. Of course, then we need to figure out how to work with old versions of the Engine bundle, but that's a solveable problem.

          2) In the past, there have been objections to these types of ThreadLocal filters (see, for example, http://sling.markmail.org/thread/epn5vdw3fkmpsk6w). This isn't to say that we shouldn't have this filter, but I think it is important (and Apache way-ish) to at least try to reconcile this on sling-dev before going to far.

          NOTE - I'm not asking you to revert your code, just to start a discussion about this change.

          Show
          justinedelson Justin Edelson added a comment - Stefan Seifert I think this warrants some discussion on sling-dev. I have two concerns. 1) This ThreadLocal filter doesn't seem to be appropriate as part of Sling Models. If such a filter is going to be part of Sling it should IMHO be done in the engine and then used across the codebase. Of course, then we need to figure out how to work with old versions of the Engine bundle, but that's a solveable problem. 2) In the past, there have been objections to these types of ThreadLocal filters (see, for example, http://sling.markmail.org/thread/epn5vdw3fkmpsk6w ). This isn't to say that we shouldn't have this filter, but I think it is important (and Apache way-ish) to at least try to reconcile this on sling-dev before going to far. NOTE - I'm not asking you to revert your code, just to start a discussion about this change.
          Hide
          sseifert@pro-vision.de Stefan Seifert added a comment -

          Completed: At revision: 1633413

          fix invalid dependency scope.
          i tried to add an integration test for this as well, but this fails because the integration tests does not seem to run in a request context, but in some separate thread i suppose (have never looked into the IT infrastructure implementation).

          Show
          sseifert@pro-vision.de Stefan Seifert added a comment - Completed: At revision: 1633413 fix invalid dependency scope. i tried to add an integration test for this as well, but this fails because the integration tests does not seem to run in a request context, but in some separate thread i suppose (have never looked into the IT infrastructure implementation).
          Hide
          sseifert@pro-vision.de Stefan Seifert added a comment -

          Completed: At revision: 1633409

          implemented using a servlet filter that attaches the current request to a thread local and cleans up after that.
          (i would be nice to have such a feature in a central place e.g. the Sling API - Interface, Impl).

          Show
          sseifert@pro-vision.de Stefan Seifert added a comment - Completed: At revision: 1633409 implemented using a servlet filter that attaches the current request to a thread local and cleans up after that. (i would be nice to have such a feature in a central place e.g. the Sling API - Interface , Impl ).

            People

            • Assignee:
              Unassigned
              Reporter:
              sseifert@pro-vision.de Stefan Seifert
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development