Details
-
Type:
Patch submission
-
Status:
Open
-
Priority:
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.
-
- patch.txt
- 12/Dec/11 09:48 AM
- 0.8 kB
- Alan Cassar
-
Hide
- transformer-resolver-test.zip
- 13/Dec/11 09:13 AM
- 8 kB
- Alan Cassar
-
- transformer-resolver-test/pom.xml 1 kB
- transformer-resolver-test/.../Person.java 0.5 kB
- transformer-resolver-test/.../ObjectFactory.java 1 kB
- transformer-resolver-test/.../InputMessage.java 0.3 kB
- transformer-resolver-test/.../ToBooleanTransformer.java 1 kB
- transformer-resolver-test/.../jaxb-resolver-mule-config.xml 1 kB
- transformer-resolver-test/.../log4j.properties 1.0 kB
- transformer-resolver-test/.../JaxbResolverTestCase.java 1 kB
- transformer-resolver-test/.../org.eclipse.m2e.core.prefs 0.1 kB
- transformer-resolver-test/.../org.maven.ide.eclipse.prefs 0.2 kB
- transformer-resolver-test/.../org.eclipse.jdt.core.prefs 0.7 kB
- transformer-resolver-test/.DS_Store 6 kB
- transformer-resolver-test/.classpath 0.6 kB
- transformer-resolver-test/.../MongoFunctionalTestCase.class 0.5 kB
- transformer-resolver-test/.../mule-config.xml 3 kB
- transformer-resolver-test/.project 0.7 kB
-
Hide
- transformer-resolver-test.zip
- 12/Dec/11 09:48 AM
- 7 kB
- Alan Cassar
-
- transformer-resolver-test/pom.xml 1 kB
- transformer-resolver-test/.../Person.java 0.5 kB
- transformer-resolver-test/.../ObjectFactory.java 1 kB
- transformer-resolver-test/.../log4j.properties 1.0 kB
- transformer-resolver-test/.../jaxb-mongo-mule-config.xml 1 kB
- transformer-resolver-test/.../JaxbMongoTestCase.java 0.9 kB
- transformer-resolver-test/.../org.eclipse.m2e.core.prefs 0.1 kB
- transformer-resolver-test/.../org.maven.ide.eclipse.prefs 0.2 kB
- transformer-resolver-test/.../org.eclipse.jdt.core.prefs 0.7 kB
- transformer-resolver-test/.DS_Store 6 kB
- transformer-resolver-test/.classpath 0.6 kB
- transformer-resolver-test/.../MongoFunctionalTestCase.class 0.5 kB
- transformer-resolver-test/.../mule-config.xml 3 kB
- transformer-resolver-test/.project 0.7 kB
Activity
To run this test, you need mongo db running. Also just wanted to note that this does not happen only with mongodb connector
Any chance you can convert this into a test without external dependencies?
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.
Attached test case