You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by ai...@gmx.de on 2005/08/13 13:29:06 UTC

AXIOM-SOAP-Problem

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


RE: [Axis2] [0.9] AW: AXIOM-SOAP-Problem

Posted by Eran Chinthaka <ch...@opensource.lk>.
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:jgreif@alumni.princeton.edu]
> Gesendet: Samstag, 13. August 2005 15:56
> An: axis-user@ws.apache.org
> 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
> 
> aii@gmx.de 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
> >
> >
> >
> >
> 




[Axis2] [0.9] AW: AXIOM-SOAP-Problem

Posted by ai...@gmx.de.
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.java:
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.java:
464)
	at
org.apache.axis2.om.impl.llom.builder.StAXBuilder.processAttributes(StAXBuil
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.createOMElement
(StAXSOAPModelBuilder.java:166)
	at
org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder.next(StAXSOAPMo
delBuilder.java:302)
	at
org.apache.axis2.om.impl.llom.OMElementImpl.getNextSibling(OMElementImpl.jav
a:268)
	at
org.apache.axis2.om.impl.llom.traverse.OMChildrenQNameIterator.hasNext(OMChi
ldrenQNameIterator.java:74)
	at
org.apache.axis2.om.impl.llom.OMElementImpl.getFirstChildWithName(OMElementI
mpl.java:232)
	at
org.apache.axis2.soap.impl.llom.SOAPEnvelopeImpl.getHeader(SOAPEnvelopeImpl.
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>(StAXSOAP
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.java:
52)
	... 13 more
-#- </Exception> --------------------------------------------------------#--

-----Ursprüngliche Nachricht-----
Von: Jeff Greif [mailto:jgreif@alumni.princeton.edu] 
Gesendet: Samstag, 13. August 2005 15:56
An: axis-user@ws.apache.org
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

aii@gmx.de 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
>
>
>  
>


Re: AXIOM-SOAP-Problem

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
I think you can do this:
  String data = new String(packet.getData());
  StringReader sr = new StringReader(data);
  XMLStreamReader xmlReader
     = XMLInputFactory.newInstance().createXMLStreamReader(sr);

Jeff

aii@gmx.de 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
>
>
>  
>