[EMAIL PROTECTED] wrote:

Hi Aleksander,

you could readly directly byte array using specialized UTF8 (streaming) reader and that may affect performance tests - XML paser will be only as good as quality of input stream y ou give to it.

Do you mean something like the following??
no i mean a specialzied high perf UTF8 Reader that will do internal buffering and avoid BufferedInputStream alltogether (that would do second buffering which is not needed for such small input) and is specialized so more efficient than generic InputStreamReader(..., "UTF8").

i did not do extensive testing but here is one i wrote which i believe is quite efficient :

http://www.extreme.indiana.edu/viewcvs/~checkout~/xsul/java/modules/common/xsul/util/Utf8Reader.java

i CCed stax builder mailing list in case there is more ways to get it improved that somebody knows about.

best,

alek

---
// Copy the data from udp packet
byte[] data = packet.getData();

// Build UTF8-ByteStream (not optimized)
ByteArrayInputStream bais = new ByteArrayInputStream(data);
InputStreamReader isr = null;
try {
        isr = new InputStreamReader(new BufferedInputStream(bais, 8192),
"UTF8");
} catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
}

// Init. XMLInputFactory instance
if (xmlif == null) {
        initXMLInputFactory();
}

// Build SOAPModel && extract SOAPEnvelope
XMLStreamReader xmlr = null;
try {
        xmlr = xmlif.createXMLStreamReader(isr);
        StAXBuilder builder = new StAXSOAPModelBuilder(xmlr);
        SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
        ...
---

Unfortunately, I still receive a java.lang.ExceptionInInitializerError when
using 'StAXSOAPModelBuilder(xmlr)'.


Anyway, thanks a lot for your advice!
Chris

-----Ursprüngliche Nachricht-----
Von: Aleksander Slominski [mailto:[EMAIL PROTECTED] Gesendet: Montag, 15. August 2005 12:48
An: [email protected]
Betreff: [Axis2] general XML parsing performance considerations for small
packets liek UDP [Re: [Axis2] AW: AW: AXIOM-SOAP-Problem

[EMAIL PROTECTED] wrote:

Hi Eran,

Thanks a lot for answering.


If you create a String from the incoming stream and then creating another
stream is not that good as this will not minimize memory usage. Better try
to wrap the incoming TCP stream with XMLStreamReader.
That's clear if you use TCP as transport mechanism. But I'd like to
integrate a Transport Sender and Transport Listener for UDP. Therefore I
receive only UDP packets (DatagramPacket), not a stream:

# DatagramPacket packet;
# ...
# // Copy the soap data from udp packet
# byte[] buffer = packet.getData();

After storing the SOAP data in a byte-array (buffer), the SOAP envelope
must
be extracted to complete the Message Context. Then we are able to call the
Axis engine:
# SOAPEnvelope envelope;
# ...
# msgContext.setEnvelope(envelope);
# if (envelope.getBody().hasFault()) {
#       engine.receiveFault(msgContext);
# }
# else {
#       engine.receive(msgContext);
# }

Does it make more sense to use SAX (like in Axis 1.*) instead of StAX to
construct the SOAP Envelope if the incoming SOAP messages aren't streams??

as UDP messages are very small it will not make much of difference as any goo parser will stream input in chunk and i would expect a sizeof chunk to be bigger than UDP packet so it should be only one read operation between parser and input.

I
would like to compare the performance of both variants.
in general there is no reason for performance difference between SAX and StAX APIs - optimized implementations will have very similiar performance.

so what you comapre is just implementations of XML parsers and that has little to do with SOAP

For this purpose the
byte-array must be converted into a stream, for example:


you could readly directly byte array using specialized UTF8 (streaming) reader and that may affect performance tests - XML paser will be only as good as quality of input stream y ou give to it.

HTH.

best,

alek

# // Convert SOAP-bytes to stream, build SOAPModel && extract SOAPEnvelope
# XMLInputFactory xmlif;
# ...
# XMLStreamReader xmlr = xmlif.createXMLStreamReader(new StringReader(
#       new String(data)));
# StAXBuilder builder = new StAXSOAPModelBuilder(xmlr);
# SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();



If you can send me the SOAP message as a String which you have, I can test
it with StAXSOAPModelBuilder.
I tried many different SOAP messages, also your one from
http://www.jaxmag.com/itr/magazine/downloads/jaxmag/chinthaka_axiom.zip
(soapmessage.xml).
But I always get the exception listed below.
I list my simple test code here. Maybe you or anyone see my fault.

# private StAXSOAPModelBuilder getSOAPBuilder(String fileName) {
#       StAXSOAPModelBuilder builder = null;
#       try {
#               FileReader soapFileReader = new FileReader(fileName);
#               XMLStreamReader parser = XMLInputFactory.newInstance()
#                               .createXMLStreamReader(soapFileReader);
#               //builder = new StAXSOAPModelBuilder(parser); // exception
here
#               builder = OMXMLBuilderFactory
#               .createStAXSOAPModelBuilder(OMAbstractFactory
#               .getSOAP12Factory(), parser);  // exception here
#       } catch (XMLStreamException e) {
#               e.printStackTrace();
#       } catch (FileNotFoundException e) {
#               e.printStackTrace();
#       }
#       return builder;
#}


Thanks!!
Chris



-----Ursprüngliche Nachricht-----
Von: Eran Chinthaka [mailto:[EMAIL PROTECTED] Gesendet: Montag, 15. August 2005 03:28
An: [email protected]
Betreff: RE: [Axis2] [0.9] AW: AXIOM-SOAP-Problem

Hi aii,

Sorry for not answering this email earlier.
(BTW, prefix all your Axis2 related dev or user mails with [Axis2]. 0.9 is
not needed.)

The one of the reasons behind us providing this AXIOM is to give streaming
support for Axis2. We wanted to have an Object model which relies on an
underlying pull stream. That’s why you can find constructors in
StAXSOAPModelBuilder which gets an XMLStreamReader as input.
But this will not hinder anyone like you, if you want to build it from an
existing source like a String. What Jeff suggested was correct.
But the way he did that was not according to Axiom principles. Axiom is
designed to provide the high performance with low memory foot print. If you
create a String from the incoming stream and then creating another stream
is
not that good as this will not minimize memory usage. Better try to wrap
the
incoming TCP stream with XMLStreamReader. <Better read the AXIOM tutorial>

Anyway seems like you have some other problem now. If you can send me the
SOAP message as a String which you have, I can test it with
StAXSOAPModelBuilder. If I can remember correct the only place OMAttribute
gives exceptions is where you try to give it a namespace, which has not
been
defined within the scope. I can’t give a solid answer without looking at
it.
Regards,
Eran Chinthaka



Jeff,

thanks for your help! Your code works.

Now I receive an exception while using StAXSOAPModelBuilder:

// this works now (I tested the output)
XMLStreamReader xmlr = xmlif.createXMLStreamReader(new StringReader(new
String(data)));

// this not ...
StAXBuilder builder = new StAXSOAPModelBuilder(xmlr);
//StAXBuilder builder = new StAXSOAPModelBuilder(xmlr, null);

// ... and leads to this Exception:
java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
        at java.util.regex.Matcher.getTextLength(Unknown Source)
        at java.util.regex.Matcher.reset(Unknown Source)
        at java.util.regex.Matcher.<init>(Unknown Source)
        at java.util.regex.Pattern.matcher(Unknown Source)
        at
org.apache.axis2.om.impl.llom.OMAttributeImpl.<clinit>(OMAttributeImpl.jav
a:
52)


What do I have to change?

Thanks again for help,
Chris

P.S. The whole code fragment and exception is listed below


-#- <Code> -------------------------------------------------------------#-
-
// Copy the data from udp packet, remove zero-bytes and restore SOAP
byte[] buffer = packet.getData();
byte[] data = new byte[findZeroByte(0, buffer)];
System.arraycopy(buffer, 0, data, 0, data.length);

// Init. XMLInputFactory instance
if (xmlif == null) {
        initXMLInputFactory();
}

// Convert SOAP-bytes to stream, build SOAPModel && extract SOAPEnvelope
XMLStreamReader xmlr = null;
try {
        xmlr = xmlif.createXMLStreamReader(new StringReader(
                                                                        new
String(data)));
        //StAXBuilder builder = new StAXSOAPModelBuilder(xmlr, null);
        StAXBuilder builder = new StAXSOAPModelBuilder(xmlr);
        SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
        ...
-#- </Code> -------------------------------------------------------------
#--


-#- <Exception> ---------------------------------------------------------
#--
java.lang.ExceptionInInitializerError
        at
org.apache.axis2.om.impl.llom.OMElementImpl.addAttribute(OMElementImpl.jav
a:
464)
        at
org.apache.axis2.om.impl.llom.builder.StAXBuilder.processAttributes(StAXBu
il
der.java:126)
        at
org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder.constructNode
(S
tAXSOAPModelBuilder.java:278)
        at
org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder.createOMEleme
nt
(StAXSOAPModelBuilder.java:166)
        at
org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder.next(StAXSOAP
Mo
delBuilder.java:302)
        at
org.apache.axis2.om.impl.llom.OMElementImpl.getNextSibling(OMElementImpl.j
av
a:268)
        at
org.apache.axis2.om.impl.llom.traverse.OMChildrenQNameIterator.hasNext(OMC
hi
ldrenQNameIterator.java:74)
        at
org.apache.axis2.om.impl.llom.OMElementImpl.getFirstChildWithName(OMElemen
tI
mpl.java:232)
        at
org.apache.axis2.soap.impl.llom.SOAPEnvelopeImpl.getHeader(SOAPEnvelopeImp
l.
java:58)
        at
org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder.parseHeaders(
St
AXSOAPModelBuilder.java:129)
        at
org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder.<init>(StAXSO
AP
ModelBuilder.java:92)
        at
de.iken.test.UDP.axis2.UDPWorkerTest.doWork(UDPWorkerTest.java:55)
        at
org.apache.axis2.util.threadpool.ThreadWorker.run(ThreadWorker.java:34)
Caused by: java.lang.NullPointerException
        at java.util.regex.Matcher.getTextLength(Unknown Source)
        at java.util.regex.Matcher.reset(Unknown Source)
        at java.util.regex.Matcher.<init>(Unknown Source)
        at java.util.regex.Pattern.matcher(Unknown Source)
        at
org.apache.axis2.om.impl.llom.OMAttributeImpl.<clinit>(OMAttributeImpl.jav
a:
52)
        ... 13 more
-#- </Exception> --------------------------------------------------------
#--

-----Ursprüngliche Nachricht-----
Von: Jeff Greif [mailto:[EMAIL PROTECTED]
Gesendet: Samstag, 13. August 2005 15:56
An: [email protected]
Betreff: Re: AXIOM-SOAP-Problem

I think you can do this:
String data = new String(packet.getData());
StringReader sr = new StringReader(data);
XMLStreamReader xmlReader
   = XMLInputFactory.newInstance().createXMLStreamReader(sr);

Jeff

[EMAIL PROTECTED] wrote:

Hi all,

I've got a question about AXIOM and SOAP:

If I like to have the SOAPEnvelope from a stream, I can do it like this:

//create the SOAP Envelope
Reader in = new InputStreamReader(socket.getInputStream());
XMLStreamReader xmlreader =
XMLInputFactory.newInstance().createXMLStreamReader(in);
StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader, null);
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();



But if I've already stored the soap-text in a String ...

// copy the data from udp packet
byte[] buffer = packet.getData();
String data = new String(buffer);

... then there is the problem that the string 'data' must be converted in
a
stream to use XMLStreamReader and StAXSOAPModelBuilder. Is this the only
solution?


In the JavaDoc of StAXOMBuilder is written that StAXOMBuilder will build
a
generic memory model from any XML input source, such as a file, string,
stream, etc..

How it works for files and streams is clear, but how does it look like
for
strings???

I need this for a UDPTransportListener.



Thanks for any help,
Chris












--
The best way to predict the future is to invent it - Alan Kay

Reply via email to