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 Asma Maalej <am...@laas.fr> on 2009/09/23 16:47:38 UTC

access to SOAP Body Element (Axis2 API)

Hello

Using Axis2.1.4.1, and in order to recover methods name of a web service 
within a handler code, I tried to access to the SOAP message and extract 
it from the SOAPBody. Then, I tried to use "SOAPBodyElement" Class
as shown below :
*****
SOAPEnvelope soapenv = messageContext.getEnvelope();
SOAPBodyElement  soapb = (SOAPBodyElement) soapenv.getFirstElement();
String methodname = soapb.getLocalName();
************

but when I invoke the web service to which I engaged the module that 
contains the above-mentioned handler, an exception launch :
****
org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be cast 
to org.apache.axiom.soap.impl.llom.SOAPBodyElement 
****

and when I tried to convert "SOAPBodyElement" to "SOAPBodyImpl" it 
launch the same exception but this time

****
org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be cast 
to org.apache.axiom.soap.impl.llom.SOAPBodyImpl
****
 If you have any idea, don't hesitate to help me with, please

thanks

-- 
Asma MÂALEJ BESBES
Laboratoire LAAS - CNRS
Toulouse - France
Tèl: +33 (0)5 61 33 62 63
Mobile: +33 (0)6 72 18 36 56
E-mail: amaalej@laas.fr


Re: access to SOAP Body Element (Axis2 API)

Posted by Amila Suriarachchi <am...@gmail.com>.
On Thu, Sep 24, 2009 at 9:33 PM, Asma Maalej <am...@laas.fr> wrote:

> Hello
>
> thank you for your reply but I already tried it, as  follows:
> ****
> SOAPBody sb = soapenv.getBody();
> OMElement soapb = (OMElement) sb.getFirstElement();
> ****
>
> but this time, I get the following exception :
> ****
> [INFO] OMException in getSOAPBuilder
> org.apache.axiom.soap.SOAPProcessingException: First Element must contain
> the local name, Envelope , but found html
>

you are getting and html page. look at the response with the tcpmon[1]

[1] http://ws.apache.org/commons/tcpmon/index.html

thanks,
Amila.

>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:251)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:209)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:191)
>   at
> org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:156)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:105)
>   at
> org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:677)
>   at
> org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:182)
>   at
> org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
>   at
> org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
>   at
> org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
>   at
> org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
>   at
> org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
>   at
> org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
>   at doc.FlexServStub.say_hello(FlexServStub.java:198)
>   at doc.FlexServClient.main(FlexServClient.java:33)
> [INFO] Remaining input stream :[]
> org.apache.axis2.AxisFault: First Element must contain the local name,
> Envelope , but found html
>   at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
>   at
> org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:90)
>   at
> org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
>   at
> org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
>   at
> org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
>   at
> org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
>   at doc.FlexServStub.say_hello(FlexServStub.java:198)
>   at doc.FlexServClient.main(FlexServClient.java:33)
> Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element
> must contain the local name, Envelope , but found html
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:251)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:209)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:191)
>   at
> org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:156)
>   at
> org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:105)
>   at
> org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:677)
>   at
> org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:182)
>   at
> org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
>   at
> org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
>   ... 6 more
> ****
>
> If you have any suggestion, don't hesitate to procure me, please
> Amila Suriarachchi a écrit :
>
>>
>>
>> On Wed, Sep 23, 2009 at 8:17 PM, Asma Maalej <amaalej@laas.fr <mailto:
>> amaalej@laas.fr>> wrote:
>>
>>    Hello
>>
>>    Using Axis2.1.4.1, and in order to recover methods name of a web
>>    service within a handler code, I tried to access to the SOAP
>>    message and extract it from the SOAPBody. Then, I tried to use
>>    "SOAPBodyElement" Class
>>    as shown below :
>>    *****
>>    SOAPEnvelope soapenv = messageContext.getEnvelope();
>>    SOAPBodyElement  soapb = (SOAPBodyElement) soapenv.getFirstElement();
>>
>>
>> use soapenv.getBody().getFirstElement()
>>
>> thanks,
>> Amila.
>>
>>
>>    String methodname = soapb.getLocalName();
>>    ************
>>
>>    but when I invoke the web service to which I engaged the module
>>    that contains the above-mentioned handler, an exception launch :
>>    ****
>>    org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be
>>    cast to org.apache.axiom.soap.impl.llom.SOAPBodyElement ****
>>
>>    and when I tried to convert "SOAPBodyElement" to "SOAPBodyImpl" it
>>    launch the same exception but this time
>>
>>    ****
>>    org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be
>>    cast to org.apache.axiom.soap.impl.llom.SOAPBodyImpl
>>    ****
>>    If you have any idea, don't hesitate to help me with, please
>>
>>    thanks
>>
>>    --    Asma MĀALEJ BESBES
>>    Laboratoire LAAS - CNRS
>>    Toulouse - France
>>    Tčl: +33 (0)5 61 33 62 63
>>    Mobile: +33 (0)6 72 18 36 56
>>    E-mail: amaalej@laas.fr <ma...@laas.fr>
>>
>>
>>
>>
>> --
>> Amila Suriarachchi
>> WSO2 Inc.
>> blog: http://amilachinthaka.blogspot.com/
>>
>
>
> --
> Asma MÂALEJ BESBES
> Laboratoire LAAS - CNRS
> Toulouse - France
> Tèl: +33 (0)5 61 33 62 63
>
> Mobile: +33 (0)6 72 18 36 56
> E-mail: amaalej@laas.fr
>
>


-- 
Amila Suriarachchi
WSO2 Inc.
blog: http://amilachinthaka.blogspot.com/

Re: access to SOAP Body Element (Axis2 API)

Posted by Asma Maalej <am...@laas.fr>.
Hello

thank you for your reply but I already tried it, as  follows:
****
SOAPBody sb = soapenv.getBody();
OMElement soapb = (OMElement) sb.getFirstElement();
****

but this time, I get the following exception :
****
[INFO] OMException in getSOAPBuilder
org.apache.axiom.soap.SOAPProcessingException: First Element must 
contain the local name, Envelope , but found html
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:251)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:209)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:191)
    at 
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:156)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:105)
    at 
org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:677)
    at 
org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:182)
    at 
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
    at 
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
    at 
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
    at 
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
    at 
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
    at 
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
    at doc.FlexServStub.say_hello(FlexServStub.java:198)
    at doc.FlexServClient.main(FlexServClient.java:33)
[INFO] Remaining input stream :[]
org.apache.axis2.AxisFault: First Element must contain the local name, 
Envelope , but found html
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
    at 
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:90)
    at 
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
    at 
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
    at 
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
    at 
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
    at doc.FlexServStub.say_hello(FlexServStub.java:198)
    at doc.FlexServClient.main(FlexServClient.java:33)
Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element 
must contain the local name, Envelope , but found html
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:251)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:209)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:191)
    at 
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:156)
    at 
org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:105)
    at 
org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:677)
    at 
org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:182)
    at 
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
    at 
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
    ... 6 more
****

If you have any suggestion, don't hesitate to procure me, please
Amila Suriarachchi a écrit :
>
>
> On Wed, Sep 23, 2009 at 8:17 PM, Asma Maalej <amaalej@laas.fr 
> <ma...@laas.fr>> wrote:
>
>     Hello
>
>     Using Axis2.1.4.1, and in order to recover methods name of a web
>     service within a handler code, I tried to access to the SOAP
>     message and extract it from the SOAPBody. Then, I tried to use
>     "SOAPBodyElement" Class
>     as shown below :
>     *****
>     SOAPEnvelope soapenv = messageContext.getEnvelope();
>     SOAPBodyElement  soapb = (SOAPBodyElement) soapenv.getFirstElement();
>
>
> use soapenv.getBody().getFirstElement()
>
> thanks,
> Amila.
>
>
>     String methodname = soapb.getLocalName();
>     ************
>
>     but when I invoke the web service to which I engaged the module
>     that contains the above-mentioned handler, an exception launch :
>     ****
>     org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be
>     cast to org.apache.axiom.soap.impl.llom.SOAPBodyElement ****
>
>     and when I tried to convert "SOAPBodyElement" to "SOAPBodyImpl" it
>     launch the same exception but this time
>
>     ****
>     org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be
>     cast to org.apache.axiom.soap.impl.llom.SOAPBodyImpl
>     ****
>     If you have any idea, don't hesitate to help me with, please
>
>     thanks
>
>     -- 
>     Asma MĀALEJ BESBES
>     Laboratoire LAAS - CNRS
>     Toulouse - France
>     Tčl: +33 (0)5 61 33 62 63
>     Mobile: +33 (0)6 72 18 36 56
>     E-mail: amaalej@laas.fr <ma...@laas.fr>
>
>
>
>
> -- 
> Amila Suriarachchi
> WSO2 Inc.
> blog: http://amilachinthaka.blogspot.com/


-- 
Asma MÂALEJ BESBES
Laboratoire LAAS - CNRS
Toulouse - France
Tèl: +33 (0)5 61 33 62 63
Mobile: +33 (0)6 72 18 36 56
E-mail: amaalej@laas.fr


Re: access to SOAP Body Element (Axis2 API)

Posted by Amila Suriarachchi <am...@gmail.com>.
On Wed, Sep 23, 2009 at 8:17 PM, Asma Maalej <am...@laas.fr> wrote:

> Hello
>
> Using Axis2.1.4.1, and in order to recover methods name of a web service
> within a handler code, I tried to access to the SOAP message and extract it
> from the SOAPBody. Then, I tried to use "SOAPBodyElement" Class
> as shown below :
> *****
> SOAPEnvelope soapenv = messageContext.getEnvelope();
> SOAPBodyElement  soapb = (SOAPBodyElement) soapenv.getFirstElement();
>

use soapenv.getBody().getFirstElement()

thanks,
Amila.


String methodname = soapb.getLocalName();
> ************
>
> but when I invoke the web service to which I engaged the module that
> contains the above-mentioned handler, an exception launch :
> ****
> org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be cast to
> org.apache.axiom.soap.impl.llom.SOAPBodyElement ****
>
> and when I tried to convert "SOAPBodyElement" to "SOAPBodyImpl" it launch
> the same exception but this time
>
> ****
> org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be cast to
> org.apache.axiom.soap.impl.llom.SOAPBodyImpl
> ****
> If you have any idea, don't hesitate to help me with, please
>
> thanks
>
> --
> Asma MĀALEJ BESBES
> Laboratoire LAAS - CNRS
> Toulouse - France
> Tčl: +33 (0)5 61 33 62 63
> Mobile: +33 (0)6 72 18 36 56
> E-mail: amaalej@laas.fr
>
>


-- 
Amila Suriarachchi
WSO2 Inc.
blog: http://amilachinthaka.blogspot.com/

RE: access to SOAP Body Element (Axis2 API)

Posted by Adam Elnagger <ae...@lampreynetworks.com>.
When extracting the body from a SOAP envelope you want the second element.
The first element under the envelope should be the header, which is why you
get an exception for attempting to cast the header to a body. It may help to
have a better understanding of the anatomy of a SOAP message.
http://www.w3.org/TR/soap12-part1/ may be of some help.

-----Original Message-----
From: Asma Maalej [mailto:amaalej@laas.fr] 
Sent: Wednesday, September 23, 2009 10:48 AM
To: axis-user@ws.apache.org
Subject: access to SOAP Body Element (Axis2 API)

Hello

Using Axis2.1.4.1, and in order to recover methods name of a web service 
within a handler code, I tried to access to the SOAP message and extract 
it from the SOAPBody. Then, I tried to use "SOAPBodyElement" Class
as shown below :
*****
SOAPEnvelope soapenv = messageContext.getEnvelope();
SOAPBodyElement  soapb = (SOAPBodyElement) soapenv.getFirstElement();
String methodname = soapb.getLocalName();
************

but when I invoke the web service to which I engaged the module that 
contains the above-mentioned handler, an exception launch :
****
org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be cast 
to org.apache.axiom.soap.impl.llom.SOAPBodyElement 
****

and when I tried to convert "SOAPBodyElement" to "SOAPBodyImpl" it 
launch the same exception but this time

****
org.apache.axiom.soap.impl.llom.soap12.SOAP12HeaderImpl cannot be cast 
to org.apache.axiom.soap.impl.llom.SOAPBodyImpl
****
 If you have any idea, don't hesitate to help me with, please

thanks

-- 
Asma MÂALEJ BESBES
Laboratoire LAAS - CNRS
Toulouse - France
Tèl: +33 (0)5 61 33 62 63
Mobile: +33 (0)6 72 18 36 56
E-mail: amaalej@laas.fr