Added with a test: https://issues.apache.org/jira/browse/WSCOMMONS-552
2010/7/21 Andreas Veithen <[email protected]> > On Wed, Jul 21, 2010 at 12:02, Cencio1980 <[email protected]> wrote: > > Ok, i found th solution.... > > > > I checked the AXIS2's SAAJ implementation and i copy the > > SOAPEnvelope.addHeader() > > method: > > > > public SOAPHeader addHeader() throws SOAPException { > > org.apache.axiom.soap.SOAPHeader header = omSOAPEnvelope.getHeader(); > > if (header == null) { > > ... > > header = new > > > SOAP11HeaderImpl(omSOAPEnvelope,(SOAPFactory)this.element.getOMFactory()); > > saajSOAPHeader = new SOAPHeaderImpl(header); > > saajSOAPHeader.setParentElement(this); > > .... > > ((NodeImpl)omSOAPEnvelope.getHeader()).setUserData(SAAJ_NODE, > > saajSOAPHeader, null); > > } > > ... > > } > > > > This still give null on omSOAPEnvelope.getHeader(). > > Debugging this code i found that the Header element is created after the > > Body Element, and not as first Envelope's child. So i fixed it adding > those > > lines: > > > > NodeImpl body = (NodeImpl)omSOAPEnvelope.getFirstChild(); > > omSOAPEnvelope.setLastChild(body); > > omSOAPEnvelope.setFirstChild(header); > > ((NodeImpl)omSOAPEnvelope.getHeader()).setNextOMSibling(body); > > > > and now it works!! > > > > Should i have to open a bug? > > Yes, please create a JIRA issue and provide a self-contained test case > that reproduces the issue and that only uses the public Axiom API > (i.e. that doesn't use internal classes from the > org.apache.axiom.soap.impl.dom package). > > > > > 2010/7/19 Cencio1980 <[email protected]> > > > >> There is no difference, but i tryed calling > >> > >> hdr = ((org.apache.axiom.soap.SOAPFactory) > >> > soapMessage.getSOAPEnvelope().getOMFactory()).createSOAPHeader(soapMessage.getSOAPEnvelope()); > >> > >> as in the sample included in my last mail, with same result. > >> > >> > >> 2010/7/16 Andreas Veithen <[email protected]> > >> > >> You should not use the SOAP11HeaderImpl constructor directly, but > >>> instead use the corresponding method on SOAPFactory. Maybe that's the > >>> cause of the issue. > >>> > >>> Andreas > >>> > >>> On Fri, Jul 16, 2010 at 11:24, Cencio1980 <[email protected]> > wrote: > >>> > Hi Andreas, > >>> > > >>> > i found that i was using a wrong way to add HeaderBlocks. Now, when i > >>> add > >>> > them to an existing SOAPHeader it works fine. > >>> > > >>> > Still remain the problems when the Envelope hasn't a Header. > >>> > > >>> > I create a new one with > >>> > new SOAP11HeaderImpl( > >>> > soapMessage.getSOAPEnvelope(), > >>> > (org.apache.axiom.soap.SOAPFactory) > >>> > soapMessage.getSOAPEnvelope().getOMFactory()); > >>> > > >>> > I can serialize the returned SOAPHeader as many time i want, but if i > >>> try to > >>> > get it from the envelope: > >>> > soapMessage.getSOAPEnvelope().getHeader() > >>> > it's null, and if i serialize the envelope, it will not appear. > >>> > > >>> > Seems i create it, but without attaching it to the envelope. > >>> > I checked the axiom source code, but i didn't find where the new > >>> SOAPHeader > >>> > is setted as envelope's first children.... > >>> > > >>> > Before opening a Jira, i want to be sure that i'm using the api in > the > >>> right > >>> > way. > >>> > > >>> > Thanks for any help, > >>> > Lorenzo > >>> > > >>> > P.S. > >>> > In attachment a simple test case (look at README). > >>> > I tryed with axiom 1.2.8 and 1.2.9 on java 1.5 > >>> > > >>> > > >>> > > >>> > 2010/7/14 Andreas Veithen <[email protected]> > >>> >> > >>> >> Hi Lorenzo, > >>> >> > >>> >> Can you please open a JIRA issue [1] for this problem with the > >>> >> following additional information: > >>> >> > >>> >> * The Axiom version you are using. > >>> >> * A test case that reproduces the problem. > >>> >> > >>> >> Thanks, > >>> >> > >>> >> Andreas > >>> >> > >>> >> [1] https://issues.apache.org/jira/browse/WSCOMMONS > >>> >> > >>> >> On Wed, Jul 14, 2010 at 17:29, Cencio1980 <[email protected]> > >>> wrote: > >>> >> > Hi all, > >>> >> > > >>> >> > i have a servlet that works on SOAP 1.1 Message , but usually > doesn't > >>> >> > need > >>> >> > to access to soap:Body content. > >>> >> > i obtain an org.apache.axiom.soap.impl.dom.SOAPMessageImpl in this > >>> way: > >>> >> > > >>> >> > XMLStreamReader xmlStreamReader = > >>> >> > > >>> >> > > >>> > XMLInputFactory.newInstance().createXMLStreamReader(((HttpServletRequest) > >>> >> > req).getInputStream()); > >>> >> > org.apache.axiom.soap.SOAPFactory mf = new > >>> >> > org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory(); > >>> >> > org.apache.axiom.om.OMXMLParserWrapper parser = new > >>> >> > StAXSOAPModelBuilder(xmlStreamReader,mf,null); > >>> >> > org.apache.axiom.soap.impl.dom.SOAPMessageImpl soapMessage = > >>> >> > (org.apache.axiom.soap.impl.dom.SOAPMessageImpl) > >>> >> > ((StAXSOAPModelBuilder)parser).getSoapMessage(); > >>> >> > > >>> >> > then i tryed to add an HeaderBlock, but if i call method > serialize() > >>> on > >>> >> > the > >>> >> > header several times, only first time i can see new HeaderBlock, > then > >>> >> > i'll > >>> >> > loose it. > >>> >> > > >>> >> > After some tests i'll find that if i call build() method on the > >>> header > >>> >> > element: > >>> >> > soapMessage.getEnvelope().getHeader().build() > >>> >> > and i add new HeaderBlock, i can serialize the message header many > >>> times > >>> >> > without loosing new added HeaderBlock elements and without > building > >>> the > >>> >> > message Body using very few memory. > >>> >> > > >>> >> > Now the problem: what if the message hasn't the Header element? > >>> >> > soapMessage.getEnvelope().getHeader() is null > >>> >> > I have to add a new Header, but if i don't call the build() on the > >>> >> > Envelope > >>> >> > i'll loose it first time i serialize it and if i build the > envelope, > >>> >> > i'll > >>> >> > build also the Body with a huge memory load. > >>> >> > > >>> >> > There is a solution without building the entire soap:Body element? > >>> >> > > >>> >> > Thanks in advance for any help, > >>> >> > > >>> >> > - Lorenzo > >>> >> > > >>> > > >>> > > >>> > >> > >> > > >
