Synapse
  1. Synapse
  2. SYNAPSE-207

Support classpath resources in registry entries

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.1.1-QA-B2
    • Component/s: Core
    • Labels:
      None

      Description

      When defining a localEntry the src attribute specifies a URL resource. It would be useful to load the resources from classpath using something like (spring) src="classpath:someFile.xml".

        Activity

        Hide
        Asankha C. Perera added a comment -

        fixed

        Show
        Asankha C. Perera added a comment - fixed
        Hide
        Andreas Veithen added a comment -

        The fix based on URL.setURLStreamHandlerFactory does not work when Synapse is deployed as a WAR. Indeed, URL.setURLStreamHandlerFactory can only be called once per VM and it will be called already by the servlet container.

        Show
        Andreas Veithen added a comment - The fix based on URL.setURLStreamHandlerFactory does not work when Synapse is deployed as a WAR. Indeed, URL.setURLStreamHandlerFactory can only be called once per VM and it will be called already by the servlet container.
        Hide
        Asankha C. Perera added a comment -

        Yep.. since this was asked as an improvement by a user, I thought something would be better than nothing for right now...I was reading through this -> http://unicon.net/node/776.. so this comes with limitations..

        Jose, are you using the standalone version of Synapse?

        Show
        Asankha C. Perera added a comment - Yep.. since this was asked as an improvement by a user, I thought something would be better than nothing for right now...I was reading through this -> http://unicon.net/node/776 .. so this comes with limitations.. Jose, are you using the standalone version of Synapse?
        Hide
        Andreas Veithen added a comment -

        I completely agree that this is better than nothing. I just posted my comment to make people aware of the fact that it doesn't work in all deployment scenarios.

        In the OSGi platform they have the same problem and they partially solved it, but I don't think their hack works properly in a servlet container. The URLStreamHandlerFactory solution has one big advantage, which is that it is completely transparent, i.e. there is no need to modify code and it also works with third party libraries. What is interesting to see is that in the Spring framework they don't use it, probably because they came to the conclusion that it doesn't work in a servlet container. A long term solution for Synapse could be to integrate the Spring resource framework. What do you think?

        Show
        Andreas Veithen added a comment - I completely agree that this is better than nothing. I just posted my comment to make people aware of the fact that it doesn't work in all deployment scenarios. In the OSGi platform they have the same problem and they partially solved it, but I don't think their hack works properly in a servlet container. The URLStreamHandlerFactory solution has one big advantage, which is that it is completely transparent, i.e. there is no need to modify code and it also works with third party libraries. What is interesting to see is that in the Spring framework they don't use it, probably because they came to the conclusion that it doesn't work in a servlet container. A long term solution for Synapse could be to integrate the Spring resource framework. What do you think?
        Hide
        Asankha C. Perera added a comment -

        I agree that integrating with the Spring framework would be a better solution.. which reminds me, we need to properly fix the Spring libraries we depend on .. Do you know what it takes to re-use the classpath handler from Spring? i.e. if its a trivial fix I would rather do it right now..

        Show
        Asankha C. Perera added a comment - I agree that integrating with the Spring framework would be a better solution.. which reminds me, we need to properly fix the Spring libraries we depend on .. Do you know what it takes to re-use the classpath handler from Spring? i.e. if its a trivial fix I would rather do it right now..
        Hide
        Andreas Veithen added a comment -

        The Spring framework defines a ResourceLoader interface as a replacement for the URLStreamHandlerFactory mechanism. The DefaultResourceLoader handles standard URLs (those supported by the JRE) as well as classpath: URLs. There are also implementations that support servlet context resources properly.

        Note that in my comment above I said that "The URLStreamHandlerFactory solution has one big advantage, which is that it is completely transparent, i.e. there is no need to modify code and it also works with third party libraries." The blog article you cite also says something along those lines. However this is actually incorrect. The reason is that you can always translate a classpath: URL into a URL supported by the JRE (either jar: or file: in the standalone case or jndi: in the servlet container case).

        Actually the modifications required to support this in Synapse would be:

        • In the initialization code (ServerManager?) create an appropriate ResourceLoader instance.
        • In the code that parses the configuration (and only there, but except endpoint URLs obviously), all expressions that create URL objects from Strings should be replaced by a call to ResourceLoader#getResource#getURL. This will produce a standard URL to access the resource.

        The only thing still to investigate is what will happen in the code that serializes the Synapse configuration to XML.

        Show
        Andreas Veithen added a comment - The Spring framework defines a ResourceLoader interface as a replacement for the URLStreamHandlerFactory mechanism. The DefaultResourceLoader handles standard URLs (those supported by the JRE) as well as classpath: URLs. There are also implementations that support servlet context resources properly. Note that in my comment above I said that "The URLStreamHandlerFactory solution has one big advantage, which is that it is completely transparent, i.e. there is no need to modify code and it also works with third party libraries." The blog article you cite also says something along those lines. However this is actually incorrect. The reason is that you can always translate a classpath: URL into a URL supported by the JRE (either jar: or file: in the standalone case or jndi: in the servlet container case). Actually the modifications required to support this in Synapse would be: In the initialization code (ServerManager?) create an appropriate ResourceLoader instance. In the code that parses the configuration (and only there, but except endpoint URLs obviously), all expressions that create URL objects from Strings should be replaced by a call to ResourceLoader#getResource#getURL. This will produce a standard URL to access the resource. The only thing still to investigate is what will happen in the code that serializes the Synapse configuration to XML.
        Hide
        Jose Luis Alba added a comment -

        Asankha, I'm using the war distribution of Synapse.

        Show
        Jose Luis Alba added a comment - Asankha, I'm using the war distribution of Synapse.

          People

          • Assignee:
            Asankha C. Perera
            Reporter:
            Jose Luis Alba
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development