I have successfully marshaled and unmarshalled my castor generated classes to an XML file. Now I'm trying to do it over a socket, here is the base code, I'm sure it's something Java related that I'm doing wrong, hopefully it's more obvious to you. I'm not sure if the wrappers that I used are correct, so to send I marshal to the following writer:

   Writer x = new OutputStreamWriter(new ByteArrayOutputStream());

and I unmarshall from the following reader:

Reader y = new InputStreamReader(new ByteArrayInputStream(DatagramPacket byte buffer);


Here's the receiver side:

       try {
           byte[] buf = new byte[10000];
           policyInfo.Policies readPolicies = new policyInfo.Policies();
           DatagramSocket ourSocket = new DatagramSocket(4444);
           DatagramPacket ourPacket = new DatagramPacket(buf, buf.length);
           ourSocket.receive(ourPacket);
ByteArrayInputStream bais = new ByteArrayInputStream(ourPacket.getData());
           Reader byteArray = new InputStreamReader(bais);
           System.out.println("byteArray Size is "+ourPacket.getLength());
readPolicies = (Policies) org.exolab.castor.xml.Unmarshaller.unmarshal(policyInfo.Policies.class, byteArray);
       } catch (Exception e) {
           e.printStackTrace();
       }

Here's the sender side:

   try {
                   Policies tempPolicies = AddPolicyClass._policyList;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
                   Writer byteArray = new OutputStreamWriter(baos);
org.exolab.castor.xml.Marshaller.marshal(AddPolicyClass._policyList, byteArray); DatagramPacket ourPacket = new DatagramPacket(baos.toByteArray(), baos.size(), InetAddress.getByName("192.168.172.123"), 4444);
                   DatagramSocket ourSocket = new DatagramSocket();
                   ourSocket.send(ourPacket);
               } catch (Exception e) {
                   e.printStackTrace();
               }

I can run in debug and see the XML, it seems fine. I have actually marshalled the data to a file, and then I read in the file on the server side and marshall it to the socket. The file's last character is line 2, column 205 (which is the character 0). Looking at the XML in debug in the stream, it would have no way of knowing this, so I'm not sure where that is from, but I get the following errors:

org.exolab.castor.xml.MarshalException: Content is not allowed in trailing section.{File: [not available]; line: 2; column: 205} at org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:755)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:721)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:610)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:812)
   at MainPackage.mainReceive.<init>(mainReceive.java:29)
   at MainPackage.mainReceive.main(mainReceive.java:38)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in trailing section. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
   at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:709)
   ... 4 more
Caused by: org.xml.sax.SAXParseException: Content is not allowed in trailing section. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
   at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:709)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:610)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:812)
   at MainPackage.mainReceive.<init>(mainReceive.java:29)
   at MainPackage.mainReceive.main(mainReceive.java:38)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in trailing section. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
   at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:709)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:610)
   at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:812)
   at MainPackage.mainReceive.<init>(mainReceive.java:29)
   at MainPackage.mainReceive.main(mainReceive.java:38)

Thanks for any light you may shed on my problem!

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to