Hi Ugo,

What you're doing should be fine, in theory. Judging from the error it sounds like you may be getting garbage at the end of your reconstituted byte array. How do you create rdCERRecord.data, and is it always an exact match for the received array of bytes? If not, that would explain it.

If that doesn't help, try copying the ByteArrayInputStream to System.out before you try to unmarshal, and make sure there are no extra characters at start or end.

 - Dennis

Ugo Enyioha wrote:

I'm having quite the problem here. It's a little
difficult for me to explain, my understanding tells me
it should work but I'll do my best to flesh it out
here.

The overall question is, what would be the best
approach to transport a single marshalled XML record
across network? I'm having issues unmarshalling it on
the other end.

Basically my approach was to perform the following
actions.

1. Create, marshall and queue XML records on server 1.
                                        asp.parseRecord();
                                        arxm.fillXMLRecord(par);
                                        arxm.writeXMLRecord(bos);      // bos 
is a
ByteArrayOutputStream
                                                        
aq.add(bos.toByteArray());     // aq is a
Concurrent Array Blocking Queue storing byte arrays
                                        
bos.reset();

1a. arxm.writeXMLRecord(bos) looks like this
public void writeXMLRecord(OutputStream out)    {
try {
// marshallingContext.setOutput(out, "UTF-8");        
marshallingContext.marshalDocument(rawCER, "UTF-8",
false, out);
} catch (JiBXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
        }
}

2. Write marshalled XML records to socket on server 1

while(true)     {
                                                        // get data from queue 
and write to socket      
cerRecordData = aq.remove();
                                                
dataAgentOutputStream.writeInt(cerRecordData.length);
                                                        
dataAgentOutputStream.write(cerRecordData);
}

} catch (IOException e) {
                                                System.out.println("Error: 
Client Agent was
unable to connect");
                                                System.err.println(e);
}

3. Read records from socket on server 2 and queue.
while(true)     {
try { rdCERRecord.length = dataAgentInputStream.readInt();

// read the entire record off the network       
dataAgentInputStream.read(rdCERRecord.data,0,rdCERRecord.length);


acaq.add(rdCERRecord.data);     // acaq is a
concurrent queue.

} catch (IOException e) {                       
System.out.println("Error: Unable to read data from
input stream");
                                        System.err.println(e);
                                        System.exit(-1);
}
}

3. Extract the record from the queue.
while(true)     {
anCERRecord.data = acaq.remove();
                                
ByteArrayInputStream tempIs = new
ByteArrayInputStream(anCERRecord.data);
                                
// unmarshall the common event record
this.cer = (CommonEventRecordType)
arum.readXMLRecord(tempIs);

3a. readXMLRecord(tempIs) looks like this
        public Object readXMLRecord(InputStream is)     {
try {
    obj = unmarshallingContext.unmarshalDocument(is,
"UTF-8");     // right here
} catch (JiBXException e) {
// TODO Auto-generated catch block
        e.printStackTrace();
}
                
System.out.println("Unmarshalled object: " +
obj.toString());
        return obj;
}

From my debugging it seems that my problem is at the
line above indicated (unmarshallDocument). Note that
because I am transporting the xml data across the
network as a byte array and JibX requires at least an
input stream I perform the appropirate converstion
using ByteArrayInputStream.

JiBX is spitting this out as its error message.
org.xmlpull.v1.XmlPullParserException: in epilog non
whitespace content is not allowed but got > (position:
END_TAG seen ...</commonEventRecordType>>... @18:108) at
org.xmlpull.mxp1.MXParser.parseEpilog(MXParser.java:1646)
at
org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1416)
at
org.xmlpull.mxp1.MXParser.nextToken(MXParser.java:1144)
at
org.jibx.runtime.impl.UnmarshallingContext.advance(UnmarshallingContext.java:315)
at
org.jibx.runtime.impl.UnmarshallingContext.parsePastEndTag(UnmarshallingContext.java:806)
at
com.internet2.eddy.schema.cer.JiBX_bindingCommonEventRecordType_access.unmarshal()
at
org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2515)
at
org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2675)
at
com.internet2.eddy.argus.speedtest.ArgusRecordXMLUnmarshaller.readXMLRecord(ArgusRecordXMLUnmarshal

So i think its unmarhshalling correctly but there's
some parsing error. One thing is each byte array
represents a complete marshalled record so my
rationale is that it should unmarshall correctly on
the other end. What could I be doing incorrectly?

I really appreciate assistance on this. Thanks.

--Ugo


                
____________________________________________________ Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to