13 Replies Latest reply on Oct 15, 2007 2:32 AM by beve

    Issue using XStreamToObject

    tobysaville

      Hello,

      I am trying to convert xml to an object using the XStreamToObject action. I use the SystemPrintln action to print the xml that is being passed in (which is generated from XStream originally):

      12:27:29,337 INFO [STDOUT] [<com.easynet.ripe.model.AllocationRequest>
       <addressLine1>line1</addressLine1>
       <multiline>0</multiline>
       <ipSize>0</ipSize>
       <nat>false</nat>
       <smpf>false</smpf>
       <ripeUsername>toby.saville</ripeUsername>
       <ripePassword>letmein</ripePassword>
      </com.easynet.ripe.model.AllocationRequest>].
      


      And the stack trace that gets generated by the XStreamToObject action when it tries to convert it into an object:
      12:27:42,524 WARN [ActionProcessingPipeline] Unexpected exception caught while processing the action pipeline
      com.thoughtworks.xstream.converters.ConversionException: addressLine1 : No ClassLoaders found for: addressLine1
      ---- Debugging information ----
      required-type : com.easynet.ripe.model.AllocationRequest
      cause-message : addressLine1 : No ClassLoaders found for: addressLine1
      class : com.easynet.ripe.model.AllocationRequest
      message : addressLine1 : No ClassLoaders found for: addressLine1
      path : /com.easynet.ripe.model.AllocationRequest/addressLine1
      cause-exception : com.thoughtworks.xstream.alias.CannotResolveClassException
      -------------------------------
       at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:45)
       at com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller.convertAnother(ReferenceByXPathUnmarshaller.java:39)
       at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:99)
       at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:12)
       at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:552)
       at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:540)
       at org.jboss.soa.esb.actions.converters.XStreamToObject.fromXmlToObject(XStreamToObject.java:187)
       at org.jboss.soa.esb.actions.converters.XStreamToObject.process(XStreamToObject.java:106)
       at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:265)
       at org.jboss.soa.esb.listeners.message.MessageAwareListener$1.run(MessageAwareListener.java:297)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: com.thoughtworks.xstream.alias.CannotResolveClassException: addressLine1 : No ClassLoaders found for: addressLine1
       at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:35)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.XmlFriendlyMapper.realClass(XmlFriendlyMapper.java:44)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:49)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:46)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:70)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
       at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:27)
       at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.determineType(ReflectionConverter.java:179)
       at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.unmarshal(ReflectionConverter.java:102)
       at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:38)
       ... 12 more
      

      Could it be that the new line is confusing things somewhere?

      I constructed a unit test to use this action outside of the ESB and it all works fine.

      Any suggestions on why this might be?

      cheers,
      Toby

        • 1. Re: Issue using XStreamToObject
          beve

          Hi Toby,

          could you post your action configuration from jboss-esb.xml?

          Here's an example from one of our actions:

          <action name="getVehicles" class="org.jboss.soa.esb.actions.converters.XStreamToObject">
           <property name="class-alias" value="rollingstock"/>
           <property name="incoming-type" value="se.xxx.Rollingstock"/>
           <property name="exclude-package" value="true"/>
           <property name="aliases">
           <alias name="vehicles" class="java.util.ArrayList"/>
           <alias name="vehicle" class="se.xxx.Vehicle"/>
           <alias name="serviceType" class="se.xxx.ServiceType"/>
           <alias name="phonenumbers" class="java.util.ArrayList"/>
           <alias name="phonenumber" class="se.xxx.PhoneNumber"/>
           <alias name="comments" class="java.util.ArrayList"/>
           <alias name="comment" class="se.xxx.Comment"/>
           </property>
          </action>
          

          What I'm thinking is that you might need to specify aliases for you classes, if you havn't done so already that is.

          Regards,

          Daniel

          • 2. Re: Issue using XStreamToObject
            tobysaville

            Hi Dave,

            thanks for your help!

            yeah, no aliases defined:

            <action name="transform-from-stream"
             class="org.jboss.soa.esb.actions.converters.XStreamToObject">
             <property name="incoming-type"
             value="com.easynet.ripe.model.AllocationRequest" />
            </action>
            


            Can you provide hints on how aliases would work on this occasion? My understanding is that it is used to rename tags instead of using the class/attribute name, but i dont understand how this will help me in this case.

            The part that really confuses me is that this action works in the unit test, outside of the ESB.

            cheers,
            toby

            • 3. Re: Issue using XStreamToObject
              beve

              Hi Toby,

              Could you tell me, what is the type of "addressLine1" ? I looks as though XStream does not know about that type.
              Could you try to add an alias for it and see if that helps?
              Something like this:

              <property name="aliases">
               <alias name="addressLine1" class="addressLine1s_Type"/>
              </property>
              



              /Daniel

              • 4. Re: Issue using XStreamToObject
                tobysaville

                Hi Daniel,

                sorry for calling you Dave before, i was talking to my workmate Dave and got confused...

                i should have elaborated - that field is simply a String. If i remove that field from the XML, the same problem arises but for the multiline field, which is an int. it seems that it is whatever tag is on the next line of the XML causes the problem.

                thanks again,
                tobes

                • 5. Re: Issue using XStreamToObject
                  tfennelly

                  Toby, would you be able to post details on the object graph you're trying to bind this xml data to.

                  Another option for you is to use the SmooksTransformer to populate the object graph from the XML. There are a number of quickstarts (e.g. transform_xml2pojo) on this, as well as some examples on the Smooks website.

                  • 6. Re: Issue using XStreamToObject
                    tfennelly

                     

                    "tobysaville" wrote:
                    Hi Daniel, sorry for calling you Dave before


                    His real name is Rodney ;-)

                    • 7. Re: Issue using XStreamToObject
                      beve

                       

                      sorry for calling you Dave before, i was talking to my workmate Dave and got confused...

                      No worries :)

                      Haven't seen this before. We had some trouble with Arraylist and things but not with String objects and primitives and this was the reason for adding the aliases.

                      /Daniel



                      • 8. Re: Issue using XStreamToObject
                        beve

                        Hmm, can't understand why XStream cannot determine that addressLine1 is of type String. Is there anything fishy with the AllocationRequest class's getters?
                        Just a thought...

                        /Daniel

                        • 9. Re: Issue using XStreamToObject
                          tobysaville

                          Hi Tom, Rodney :)

                          The object graph is as follows:

                          class RipeRequest {
                           private String username, password
                          
                           // ... public getters & setters
                          }
                          
                          class AllocationRequest extends RipeRequest {
                           private String addressLine1, addressLine2 // etc
                           private int multiline, ipSize //etc
                          
                           // ... public getters & setters
                          }
                          


                          They are just standard POJOs with nothing special happening in the accessor methods. do you need any other info?

                          Thanks for the smooks suggestion, ill investigate that if i cant get anywhere with XStream.

                          Thanks again,
                          toby

                          • 10. Re: Issue using XStreamToObject
                            tobysaville

                            i dont know if its important, but i forgot to mention that the RipeRequest class is abstract and implements Serializable:

                            public abstract class RipreRequest implements Serializable {
                            ...
                            }
                            


                            • 11. Re: Issue using XStreamToObject
                              beve

                              Hey Toby,

                              I've tried with abstract classes and that works fine.

                              Could you try something for me?

                              Could your change your xml to this:

                              <AllocationRequest>
                               <addressLine1>line1</addressLine1>
                               <multiline>0</multiline>
                               <ipSize>0</ipSize>
                               <nat>false</nat>
                               <smpf>false</smpf>
                               <ripeUsername>toby.saville</ripeUsername>
                               <ripePassword>letmein</ripePassword>
                              </AllocationRequest>


                              And then add the following property to the action :
                              <property name="class-alias" value="AllocationRequest"/>
                              


                              Do you get the same error?

                              Thanks,

                              Daniel

                              • 12. Re: Issue using XStreamToObject
                                tobysaville

                                Hi Daniel,

                                i tried your suggestions, and got an interesting result.

                                when using an alias, i can call the service once and it will work. if i call it again, i get the following error:

                                17:03:39,283 WARN [ActionProcessingPipeline] Unexpected exception caught while processing the action pipeline
                                com.thoughtworks.xstream.alias.CannotResolveClassException: AllocationRequest : No ClassLoaders found for: AllocationRequest
                                 at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:35)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.XmlFriendlyMapper.realClass(XmlFriendlyMapper.java:44)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:49)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:46)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:70)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:18)
                                 at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:27)
                                 at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:95)
                                 at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:12)
                                 at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:552)
                                 at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:540)
                                 at org.jboss.soa.esb.actions.converters.XStreamToObject.fromXmlToObject(XStreamToObject.java:187)
                                 at org.jboss.soa.esb.actions.converters.XStreamToObject.process(XStreamToObject.java:106)
                                 at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:265)
                                 at org.jboss.soa.esb.listeners.message.MessageAwareListener$1.run(MessageAwareListener.java:297)
                                 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
                                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
                                 at java.lang.Thread.run(Thread.java:595)
                                


                                I can repeat this process over and over with the same result. seems like some type of caching issue perhaps?

                                thanks for your help!
                                - toby

                                • 13. Re: Issue using XStreamToObject
                                  beve

                                  Hey Toby,

                                  interesting...I'll try to reproduce this and see if we can figure out what's going on. Won't be until later today or tomorrow though.

                                  Let me know if you find anything.

                                  Thanks,

                                  Daniel