JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Use Agile By Default
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile Access more options (Alt+g)
  • Create Issue
  • Mule
  • MULE-5955

AbstractAnnotatedTransformerArgumentResolver returns a jaxbContext the first time only even when it should not

  • Agile Board
  • More Actions
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Patch submission Patch submission
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Modules: (other)
  • Labels:
    None
  • User impact:
    Low
  • Configuration:
    Hide

    <mule xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
    xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
    xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"
    xsi:schemaLocation="
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
    http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.1/mule-vm.xsd
    http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.1/mule-xml.xsd
    http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/1.0/mule-mongo.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    ">

    <mulexml:jaxb-context name="jaxbContext" packageNames="org.mule.entity"/>
    <mulexml:jaxb-object-to-xml-transformer name="jaxbTransformer" jaxbContext-ref="jaxbContext" />

    <mongo:config name="mongo" database="test" host="localhost" port="27017"/>

    <flow name="testJaxbAndMongo">
    <vm:inbound-endpoint address="vm://test" exchange-pattern="request-response"/>
    <logger level="ERROR" message="#[payload]"/>
    <mongo:update-objects collection="test-collection" config-ref="mongo" multi="false" upsert="true"
    query="{ "id" : #[json:id] }" element="#[payload]" />
    </flow>
    </mule>

    Show
    <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.1/mule-vm.xsd http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.1/mule-xml.xsd http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/1.0/mule-mongo.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd "> <mulexml:jaxb-context name="jaxbContext" packageNames="org.mule.entity"/> <mulexml:jaxb-object-to-xml-transformer name="jaxbTransformer" jaxbContext-ref="jaxbContext" /> <mongo:config name="mongo" database="test" host="localhost" port="27017"/> <flow name="testJaxbAndMongo"> <vm:inbound-endpoint address="vm://test" exchange-pattern="request-response"/> <logger level="ERROR" message="#[payload]"/> <mongo:update-objects collection="test-collection" config-ref="mongo" multi="false" upsert="true" query="{ "id" : #[json:id] }" element="#[payload]" /> </flow> </mule>
  • Similar Issues:
    None

Description

Mongo db connector has a property upsert (boolean) on the update-objects element. The auto generated code will try to find a transformer to convert from string to boolean to get the proper value from the XML configuration. This works fine until you introduce a Jaxb context to your Mule configuration. Once you add a jaxb context, a JAXBContextResolver will start appearing in the list of transformer resolvers. When Mule tries to find a transformer to convert String to Boolean, the first time only the jaxb resolver will return a jaxb context to be used by the transformer for the conversion. Obviously this will throw an exception when the transformer is eventually invoked. Second time round however, everything works fine because the JAXBContextResolver returns null!!

The issue is found in the AbstractAnnotatedTransformerArgumentResolver. In the resolve, if the arguments are not correctly annotated, the classes are added correctly to the nonMatchingClasses set so that next time round we return null immediately without having to scan. However, the first time round, the context is still returned even though the arguments are not properly annotated!! Second time round, everything works fine because the argument classes would be in the nonMatchingClasses and a null is immediately returned.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    patch.txt
    12/Dec/11 09:48 AM
    0.8 kB
    Alan Cassar
  2. Hide
    Zip Archive
    transformer-resolver-test.zip
    13/Dec/11 09:13 AM
    8 kB
    Alan Cassar
    1. XML File
      transformer-resolver-test/pom.xml 1 kB
    2. Java Source File
      transformer-resolver-test/.../Person.java 0.5 kB
    3. Java Source File
      transformer-resolver-test/.../ObjectFactory.java 1 kB
    4. Java Source File
      transformer-resolver-test/.../InputMessage.java 0.3 kB
    5. Java Source File
      transformer-resolver-test/.../ToBooleanTransformer.java 1 kB
    6. XML File
      transformer-resolver-test/.../jaxb-resolver-mule-config.xml 1 kB
    7. File
      transformer-resolver-test/.../log4j.properties 1.0 kB
    8. Java Source File
      transformer-resolver-test/.../JaxbResolverTestCase.java 1 kB
    9. File
      transformer-resolver-test/.../org.eclipse.m2e.core.prefs 0.1 kB
    10. File
      transformer-resolver-test/.../org.maven.ide.eclipse.prefs 0.2 kB
    11. File
      transformer-resolver-test/.../org.eclipse.jdt.core.prefs 0.7 kB
    12. File
      transformer-resolver-test/.DS_Store 6 kB
    13. File
      transformer-resolver-test/.classpath 0.6 kB
    14. File
      transformer-resolver-test/.../MongoFunctionalTestCase.class 0.5 kB
    15. XML File
      transformer-resolver-test/.../mule-config.xml 3 kB
    16. File
      transformer-resolver-test/.project 0.7 kB
    Download Zip
    Show
    Zip Archive
    transformer-resolver-test.zip
    13/Dec/11 09:13 AM
    8 kB
    Alan Cassar
  3. Hide
    Zip Archive
    transformer-resolver-test.zip
    12/Dec/11 09:48 AM
    7 kB
    Alan Cassar
    1. XML File
      transformer-resolver-test/pom.xml 1 kB
    2. Java Source File
      transformer-resolver-test/.../Person.java 0.5 kB
    3. Java Source File
      transformer-resolver-test/.../ObjectFactory.java 1 kB
    4. File
      transformer-resolver-test/.../log4j.properties 1.0 kB
    5. XML File
      transformer-resolver-test/.../jaxb-mongo-mule-config.xml 1 kB
    6. Java Source File
      transformer-resolver-test/.../JaxbMongoTestCase.java 0.9 kB
    7. File
      transformer-resolver-test/.../org.eclipse.m2e.core.prefs 0.1 kB
    8. File
      transformer-resolver-test/.../org.maven.ide.eclipse.prefs 0.2 kB
    9. File
      transformer-resolver-test/.../org.eclipse.jdt.core.prefs 0.7 kB
    10. File
      transformer-resolver-test/.DS_Store 6 kB
    11. File
      transformer-resolver-test/.classpath 0.6 kB
    12. File
      transformer-resolver-test/.../MongoFunctionalTestCase.class 0.5 kB
    13. XML File
      transformer-resolver-test/.../mule-config.xml 3 kB
    14. File
      transformer-resolver-test/.project 0.7 kB
    Download Zip
    Show
    Zip Archive
    transformer-resolver-test.zip
    12/Dec/11 09:48 AM
    7 kB
    Alan Cassar

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Transitions
  • Commits
  • Source
  • Builds
Hide
Permalink
Alan Cassar added a comment - 12/Dec/11 09:48 AM

Attached test case

Show
Alan Cassar added a comment - 12/Dec/11 09:48 AM Attached test case
Hide
Permalink
Alan Cassar added a comment - 12/Dec/11 09:48 AM

Attached patch

Show
Alan Cassar added a comment - 12/Dec/11 09:48 AM Attached patch
Hide
Permalink
Alan Cassar added a comment - 12/Dec/11 09:49 AM

To run this test, you need mongo db running. Also just wanted to note that this does not happen only with mongodb connector

Show
Alan Cassar added a comment - 12/Dec/11 09:49 AM To run this test, you need mongo db running. Also just wanted to note that this does not happen only with mongodb connector
Hide
Permalink
Daniel Feist added a comment - 12/Dec/11 01:31 PM

Any chance you can convert this into a test without external dependencies?

Show
Daniel Feist added a comment - 12/Dec/11 01:31 PM Any chance you can convert this into a test without external dependencies?
Hide
Permalink
Alan Cassar added a comment - 13/Dec/11 09:13 AM

new testcase without external dependencies

Show
Alan Cassar added a comment - 13/Dec/11 09:13 AM new testcase without external dependencies
Hide
Permalink
Alan Cassar added a comment - 13/Dec/11 09:18 AM

Hi dan, I added a new test without any external dependencies. I debugged this a little further and found out why in most cases it works, but it does not with the mongo db connector (and possibly a lot more other cloud connectors).

The code generated by the cloud connector, for example for an attribute like upsert which is boolean, the cloud connector generates code to convert the string from the xml to boolean, however, it does not use java.lang.Boolean, but it uses the primitive boolean.

When the JAXBTransformerResolver class gets a jaxb context, it will try to check whether the source/target are jaxb annotated, hence it will call method hasJaxbAnnotations(). The problem here is that since boolean is primitive, the call String p = annotatedType.getPackage().getName(); will throw an exception.

In my opinion there are two ways of fixing this, either by applying the patch I attached here yesterday, which will return null immediately when the JAXBTransformerResolver tries to get the context, or otherwise the hasJaxbAnnotations() class need to check not just for the ignore packages, but also for primitive types.

Hope all of this helps.

Show
Alan Cassar added a comment - 13/Dec/11 09:18 AM Hi dan, I added a new test without any external dependencies. I debugged this a little further and found out why in most cases it works, but it does not with the mongo db connector (and possibly a lot more other cloud connectors). The code generated by the cloud connector, for example for an attribute like upsert which is boolean, the cloud connector generates code to convert the string from the xml to boolean, however, it does not use java.lang.Boolean, but it uses the primitive boolean. When the JAXBTransformerResolver class gets a jaxb context, it will try to check whether the source/target are jaxb annotated, hence it will call method hasJaxbAnnotations(). The problem here is that since boolean is primitive, the call String p = annotatedType.getPackage().getName(); will throw an exception. In my opinion there are two ways of fixing this, either by applying the patch I attached here yesterday, which will return null immediately when the JAXBTransformerResolver tries to get the context, or otherwise the hasJaxbAnnotations() class need to check not just for the ignore packages, but also for primitive types. Hope all of this helps.

People

  • Assignee:
    Unassigned
    Reporter:
    Alan Cassar
Vote (1)
Watch (1)

Dates

  • Created:
    12/Dec/11 09:46 AM
    Updated:
    19/Jan/12 08:28 AM

Agile

  • View on Board
  • Atlassian JIRA (v5.0.7#734-sha1:8ad78a6)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for MuleForge. Try JIRA - bug tracking software for your team.