Uploaded image for project: 'Wink'
  1. Wink
  2. WINK-243

Unable to inject fields once ResourceInstance is initialized

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • 1.1
    • Server
    • None
    • Wink 1.0 / JRE 1.6

    Description

      Unable to inject fields once ResourceInstance is initialized.

      I get a handle to the the resource instance which is about to be invoked using UriInfo.getMatchedResources, which will initialize a new ResourceInstance using ObjectFactory which would in-turn inject all fields/methods to the resource instance and the resource instance is returned back. After this process any sort of field injection to the context is not getting reflected in the resource instance. This is because in ResourceInstance.getInstanceMethod,

      ResourceInstance.java
      ...
          public Object getInstance(RuntimeContext context) {
              if (instance != null) {
                  return instance;
              }
              instance = record.getObjectFactory().getInstance(context);
              return instance;
          }
      ...
      

      As we see if the instance is not null the instance is returned as it is.

      A probable fix could be to call wink common's CreationUtils.injectFields() to re-inject the fields which would inject any field that was set to the context after the resource class was initialized. The code above would look like,

      ResourceInstance.java
      ...
      public Object getInstance(RuntimeContext context) {
              if (instance != null) {
              	try {
      			CreationUtils.injectFields(instance, record.getMetadata(), context);
      		}  catch (Exception e) {
      			throw new ObjectCreationException(e);
      		}
                  return instance;
              }
              instance = record.getObjectFactory().getInstance(context);
              return instance;
          }
      ...
      

      However this would re-inject fields that was already injected to the instance before while creation of the instance. If that can be lived with, this could possibly be a patch for this bug.

      Attachments

        1. WINK-243.patch
          5 kB
          Bryant Luk

        Activity

          People

            bluk Bryant Luk
            bharath_c_m bharath chinnadurai
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: