Hi,

  This is my first time using Castor (ver: 0.9.3.9) and SOAP.  I have
some legacy Java classes
  which I'm trying to marshal to XML using Castor mapping files that I
have created for the java classes.
  In the Castor mapping file, I specified the field I wanted to map and
the xml-name it should map to.
  The mapping file seem to work correclty when I running a test client
that is not going thru SOAP services,
  the marshalling of the object is working correctly.  But when I tried
to send request and marshal the java
  object that is returned back (thru SOAP), it seems that the
marshalling is not using the mapping file  that
  I have set and load.  Below is the function I used to marshal the
object and send the message back to the client.

public void buildResponse (
      String       inMsgName   ,
      Object       inContent   ,
      SOAPContext  outResponse ,
      Envelope     inoutEnv    )
         throws MessagingException, IOException
   {
      // Create the response.
      System.out.println("In buildResponse() ");

      Document theDoc = new DocumentImpl();
      Element theResponse =  theDoc.createElement ( inMsgName );

      String mapFile = "file:C:\\mappdir\\mapping.xml";

      try
      {
         Mapping map = new Mapping();

map.loadMapping(mapFile);
//Load mapping file
         Marshaller marshaller = new Marshaller(theResponse);

marshaller.setMapping(map);                                        //Set
mapping file
         marshaller.marshal(inContent);
      }

      catch ( Throwable e )
      {
         sLog.error ( "error building response", e );

         buildErrorResponse (
            "ERROR_BUILDING_RESPONSE" ,  // inError
            e.getMessage()            ,  // inDescription
            outResponse               ,  // outResponse
            inoutEnv                  ); // inoutEnv

         return;
      }

      // Set this response as the content of the envelope.

      Vector theBodyEntries = inoutEnv.getBody().getBodyEntries();
      theBodyEntries.clear();
      theBodyEntries.add ( theResponse );

      StringWriter aWriter = new StringWriter();
      inoutEnv.marshall ( aWriter, null );

      // Send the envelope back to the client.
      //
      outResponse.setRootPart ( aWriter.toString(), "text/xml" );
   }

Her an example of the Castor mapping file:
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version
1.0//EN"
                           "http://castor.exolab.org/mapping.dtd";>
<mapping>

 <class name="mil.dia.midb.mdal.gmi.facility.model.Facility">
   <map-to xml="FAC" />
   <!--field name="facSk"    type="java.math.BigDecimal">
    <bind-xml name="FAC_SK" />
   </field-->
   <field name="allegiance" type="java.lang.String">
    <bind-xml name="ALLEGIANCE" />
   </field>
   <field name="avRecordStatus" type="java.lang.String">
    <bind-xml name="AV_RECORD_STATUS" />
   </field>
   <field name="cc" type="java.lang.String">
    <bind-xml name="CC" />
   </field>
   <field name="datetimeBegin" type="java.lang.String">
    <bind-xml name="DATETIME_BEGIN" />
   </field>
   <field name="datetimeCreated" type="java.lang.String">
    <bind-xml name="DATETIME_CREATED" />
   </field>
   <field name="datetimeEnd" type="java.lang.String">
    <bind-xml name="DATETIME_END" />
   </field>
   ....
 </mapping


Please Help.
Thank You In Advance,
Ide

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to