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 "SAINI, Nishant, IDC" <Ni...@rbs.com> on 2008/04/15 09:56:58 UTC

Axis2 - How to set a header attribute from client that can be get in a Handler

Hi,

My Web Service is deployed in Apache Tomcat + Axis2.war and I am calling it using RPCServiceClient. I am tying to set a String attribute to SOAP header from RPC Client. But the attribute is not found in the SOAPEnvelope in the handler put by me on the server.

My client code is:
        RPCServiceClient serviceClient = new RPCServiceClient();
        Options options = serviceClient.getOptions();
        EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/SimpleService");
        options.setTo(targetEPR);
        serviceClient.addStringHeader(new QName("http://ws.practice.com", "attr1"), "Attr1_Value");
        QName opGetName = new QName("http://ws.practice.com", "getName");
        Object[] opGetNameArgs = new Object[] {"1"};
        Class[] returnTypes = new Class[] { String.class };
        Object[] response = serviceClient.invokeBlocking(opGetName, opGetNameArgs, returnTypes);
        String result = (String) response[0];

The result obtained is fine but I am not able to get the "attr1" on the server side.

The handler's invoke method on server side is as follows:
    public InvocationResponse invoke(MessageContext mc) throws AxisFault {
        org.apache.axiom.soap.SOAPEnvelope env =  mc.getEnvelope();
        SOAPHeader header = env.getHeader();
        Iterator iter = header.getAllAttributes();
        while(iter.hasNext()) {
            System.out.println(iter.next());
        }
        InvocationResponse ir = InvocationResponse.CONTINUE;
        return ir;
    }

The iterator on server side contains no objects.

Please provide your valuable suggestions and feedback.

Thanks and regards,

Nishant Saini
Application Developer
RBS India Development Centre (P) Ltd

T  +91 124 672 4125
M +91 99 71 800 549
nishant.saini@rbs.com
Unitech Business Park, Block F, Sector 41, South City, Phase 1,
Gurgaon - 122001, Haryana, India

The views expressed in above mail are not necessarily of my employer.

 I love the internet...Nowhere else do you find stupidity and wisdom in equal abundance.

***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. 
Authorised and regulated by the Financial Services Authority 
 
This e-mail message is confidential and for use by the 
addressee only. If the message is received by anyone other 
than the addressee, please return the message to the sender 
by replying to it and then delete the message from your 
computer. Internet e-mails are not necessarily secure. The 
Royal Bank of Scotland plc does not accept responsibility for 
changes made to this message after it was sent. 

Whilst all reasonable care has been taken to avoid the 
transmission of viruses, it is the responsibility of the recipient to 
ensure that the onward transmission, opening or use of this 
message and any attachments will not adversely affect its 
systems or data. No responsibility is accepted by The 
Royal Bank of Scotland plc in this regard and the recipient should carry 
out such virus and other checks as it considers appropriate. 
Visit our websites at: 
www.rbs.com
www.rbs.com/gbm
www.rbsgc.com
***********************************************************************************

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Axis2 - How to set a header attribute from client that can be get in a Handler

Posted by Deepal jayasinghe <de...@gmail.com>.
This might help you
> http://wso2.org/library/327

> Hi,
>
> My Web Service is deployed in Apache Tomcat + Axis2.war and I am calling it using RPCServiceClient. I am tying to set a String attribute to SOAP header from RPC Client. But the attribute is not found in the SOAPEnvelope in the handler put by me on the server.
>
> My client code is:
>         RPCServiceClient serviceClient = new RPCServiceClient();
>         Options options = serviceClient.getOptions();
>         EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/SimpleService");
>         options.setTo(targetEPR);
>         serviceClient.addStringHeader(new QName("http://ws.practice.com", "attr1"), "Attr1_Value");
>         QName opGetName = new QName("http://ws.practice.com", "getName");
>         Object[] opGetNameArgs = new Object[] {"1"};
>         Class[] returnTypes = new Class[] { String.class };
>         Object[] response = serviceClient.invokeBlocking(opGetName, opGetNameArgs, returnTypes);
>         String result = (String) response[0];
>
> The result obtained is fine but I am not able to get the "attr1" on the server side.
>
> The handler's invoke method on server side is as follows:
>     public InvocationResponse invoke(MessageContext mc) throws AxisFault {
>         org.apache.axiom.soap.SOAPEnvelope env =  mc.getEnvelope();
>         SOAPHeader header = env.getHeader();
>         Iterator iter = header.getAllAttributes();
>         while(iter.hasNext()) {
>             System.out.println(iter.next());
>         }
>         InvocationResponse ir = InvocationResponse.CONTINUE;
>         return ir;
>     }
>
> The iterator on server side contains no objects.
>
> Please provide your valuable suggestions and feedback.
>
> Thanks and regards,
>
> Nishant Saini
> Application Developer
> RBS India Development Centre (P) Ltd
>
> T  +91 124 672 4125
> M +91 99 71 800 549
> nishant.saini@rbs.com
> Unitech Business Park, Block F, Sector 41, South City, Phase 1,
> Gurgaon - 122001, Haryana, India
>
> The views expressed in above mail are not necessarily of my employer.
>
>  I love the internet...Nowhere else do you find stupidity and wisdom in equal abundance.
>
> ***********************************************************************************
> The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. 
> Authorised and regulated by the Financial Services Authority 
>  
> This e-mail message is confidential and for use by the 
> addressee only. If the message is received by anyone other 
> than the addressee, please return the message to the sender 
> by replying to it and then delete the message from your 
> computer. Internet e-mails are not necessarily secure. The 
> Royal Bank of Scotland plc does not accept responsibility for 
> changes made to this message after it was sent. 
>
> Whilst all reasonable care has been taken to avoid the 
> transmission of viruses, it is the responsibility of the recipient to 
> ensure that the onward transmission, opening or use of this 
> message and any attachments will not adversely affect its 
> systems or data. No responsibility is accepted by The 
> Royal Bank of Scotland plc in this regard and the recipient should carry 
> out such virus and other checks as it considers appropriate. 
> Visit our websites at: 
> www.rbs.com
> www.rbs.com/gbm
> www.rbsgc.com
> ***********************************************************************************
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org