Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-220

Jaxb2Marshaller::supports method does not consider multiple marshallers

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.0.2
    • Component/s: OXM
    • Labels:
      None

      Description

      When evaluating multiple MarshallingMethodEndpointAdapters, each with their own Jaxb2MarshallingEndpoint, the first MarshallingMethodEndpointAdapter::supports method is always true.

      We are building a modular application; where each endpoint is packaged as it's own module.
      Each of those endpoint modules has it's own MarshallingMethodEndpointAdapter and it's own Jaxb2Marshaller.
      This means that when the webapp is packaged and running there will be multiple MarshallingMethodEndpointAdapters available to the MessageDispatcher.

      The Jaxb2Marshaller::supports method is implemented to return true for any subclass of Jaxb2Element.

          public boolean supports(Class clazz) {
              if (JAXBElement.class.isAssignableFrom(clazz)) {
                  return true;
              }
              ...
          }

      The Jaxb2Marshaller should not even bother with this check, it should only return true if the JaxbContext is capable of supporting the given class.

      1. Jaxb2Marshaller.patch.txt
        3 kB
        Ray Krueger
      2. Jaxb2Marshaller.patch2.txt
        3 kB
        Ray Krueger
      3. Jaxb2Marshaller.patch3.txt
        2 kB
        Ray Krueger

        Activity

        Hide
        raykrueger Ray Krueger added a comment -

        Arjen, I see you're checking the contextPath using "getContextPath().startsWith(packageName)". From what I read the "contextPath" for the JAXBContext can be a colon delimited string. Meaning that if my packageName isn't first in the list, this check will fail. Granted I used "contains" which wasn't added till 1.5 , but an indexOf check here might be necessary.

        Or did I read that wrong?

        Show
        raykrueger Ray Krueger added a comment - Arjen, I see you're checking the contextPath using "getContextPath().startsWith(packageName)". From what I read the "contextPath" for the JAXBContext can be a colon delimited string. Meaning that if my packageName isn't first in the list, this check will fail. Granted I used "contains" which wasn't added till 1.5 , but an indexOf check here might be necessary. Or did I read that wrong?
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Yes, you are right. The funny thing is that I was just thinking about the same thing. Great minds...

        I will tokenize the context path first based on colon, and then use startsWith.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Yes, you are right. The funny thing is that I was just thinking about the same thing. Great minds... I will tokenize the context path first based on colon, and then use startsWith.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Done. I now tokenize the context path.

        Also, the spec says that supported classes should be in the package denoted by the context path (and not subpackages). So I now use equals rather than startsWith.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Done. I now tokenize the context path. Also, the spec says that supported classes should be in the package denoted by the context path (and not subpackages). So I now use equals rather than startsWith.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        After some more testing, the supports() issue turned out to be even more difficult than I thought. All JAXB2 Marshallers must also support JAXBElements which are parameterized over a primitive or standard type, such as JAXBElement<String>, etc.

        Show
        arjen.poutsma Arjen Poutsma added a comment - After some more testing, the supports() issue turned out to be even more difficult than I thought. All JAXB2 Marshallers must also support JAXBElements which are parameterized over a primitive or standard type, such as JAXBElement<String>, etc.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Closing 1.0.2 issues.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Closing 1.0.2 issues.

          People

          • Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            raykrueger Ray Krueger
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: