Title: RE: Reusing Serializer/Deserializer for generic XML loading?

Joel,

I've done exactly what you're describing, for the purpose of testing. We've found that using XML tools that can automaticall populate an instance document (such as XML spy), we're able to generate a lot of test data really quickly. Unfortunately, it turned out to be more difficult that would be expected. 

Here is an example of the DeserializationContext creation:


        // Get the xml source from our string that we've read from a file
      Reader reader = new StringReader(xmlString);
      InputSource xmlSource = new InputSource(reader);

        // Get an engine configuration and let that populate the type mappings for us
      EngineConfigurationFactory configFactory = EngineConfigurationFactoryDefault.newFactory(null);
      EngineConfiguration engineConfig = configFactory.getServerEngineConfig();
      AxisServer server = new AxisServer(engineConfig);
      MessageContext msgContext = new MessageContext(server);

        // Some voodoo here.  We need the message context we use to create the deserializer to use our type mapping registry

      TypeMappingRegistry tmr = engineConfig.getService(new QName("","OurWebService")).getTypeMappingRegistry();
      msgContext.setTypeMappingRegistry(tmr);

        // finally!  we can create the deserialization context
      DeserializationContextImpl dser = new DeserializationContextImpl(
            xmlSource,
            msgContext,
            org.apache.axis.Message.REQUEST);


This is based on the 1.0 release source, so it may need to change for the latest source.  I haven't tried that yet.
This is also dependent on the server-config.wsdd since that is where the type mappings reside.  We also had to create our own serializer to use this, but I'm not sure if you'll need to in order to use it, depending on the structure of your WSDL.  When we used a wrapped doc/lit style WSDL, we had to do some more voodoo with the type mappings, explicitly inserting the type mapping with our types into the chain of type mappings.  With SOAP/RPC, however, we didn't have to do that.

I don't expect that you'll be able to take this code and get it working out of the box, but it will hopefully get you started.

Thanks,

David Altenburg 


-----Original Message-----
From: Joel Grenon [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 19, 2002 8:37 AM
To: [EMAIL PROTECTED]
Subject: Reusing Serializer/Deserializer for generic XML loading?


I've used WSDL2Java to generate a number of wrappers. Each of those wrappers contains all the code to marshall and unmarshall the object from/to XML. I'd like to reuse this code to help automate my JUnit tests. I have a bunch of test data in XML, which are using the same schema than the one in the WSDL. Instead of using another XML persistence layer, I'd like to reuse the Deserializer to read in the XML document and populate my wrapper state automaticaly.

I've retrieved a Deserializer from the wrapper and integrated it in my SAX event handling but I'm missing the DeserializationContext which sounds like hard to generate outisde a SOAP Call. Is there an easy way to create a DeserializationContext (an API somewhere)? I need it fully configured (with all type mappings and the rest...)

Any help welcomed.

Joel

Reply via email to