You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Anupama Vaid <An...@bluecasa.com> on 2009/04/29 22:07:57 UTC

Generating SecurityHeader from client

I am trying to get a security header generated in my SOAP request as
below but without any luck

 

  <soap:Header>

    <SecureHeader xmlns="http://tempuri.org/service">

      <UserName>username</UserName>

      <Password>password</Password>

    </SecureHeader>

  </soap:Header>

 

I used wsdl2java -client to generate client code. I see that the
generated code has ObjectFactory.java with a method
'createSecureHeader()' and also a SecureHeader.java, but can't figure
out how to use it. Any help?

 

Thanks,

Anu


Re: Generating SecurityHeader from client

Posted by "Anu@work" <an...@bluecasa.com>.
Thanks - that worked perfect. Seems very silly now!


dkulp wrote:
> 
> On Tue May 5 2009 4:33:37 pm Anu@work wrote:
>> I tried putting the soap header using
>> requestContext.put("Header.HEADER_LIST", headerList) also tried -exsh but
>> each time, this is the Payload I see in my logs
> 
> It's not:
>  requestContext.put("Header.HEADER_LIST", headerList)
> It should be:
>  requestContext.put(Header.HEADER_LIST, headerList)
> 
> Basically, remove the quotes and import the Header class.   (actually, 
> SoapHeader.HEADER_LIST should work as well since Header is the superclass)
> 
> Dan
> 
> 
>>
>> Payload: <soap:Envelope
>> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><EncryptV
>>alue
>> xmlns="http://tempuri.org/"><Value>626948725</Value></EncryptValue></soap:B
>>ody></soap:Envelope>
>>
>> How do I get the
>>   <soap:Header>
>>     <SecureHeader xmlns="http://tempuri.org/service">
>>       <UserName>username</UserName>
>>       <Password>password</Password>
>>     </SecureHeader>
>>   </soap:Header>
>>
>> in my Payload?
>>
>> Here's the code I used in client
>>
>>         SecureHeader sh = new SecureHeader();
>>         sh.setUserName("user");
>>         sh.setPassword("pass");
>>
>>         JAXBElement<SecureHeader> job = new JAXBElement<SecureHeader>(
>>              new QName("http://tempuri.org/", "SecureHeader"),
>> SecureHeader.class, null, sh);
>>
>>         SoapHeader hdr = new SoapHeader(
>>                 new QName("http://tempuri.org/", "MyService"),
>>                 job,
>>                 new JAXBDataBinding(sh.getClass()));
>>
>>         List<SoapHeader> holder = new ArrayList<SoapHeader>();
>>         holder.add(hdr);
>>
>>         // Set request context property.
>>         java.util.Map<String, Object> requestContext =
>>           ((javax.xml.ws.BindingProvider)port).getRequestContext();
>>
>>         requestContext.put("Header.HEADER_LIST", holder);
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/Generating-SecurityHeader-from-client-tp23306088p23395698.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Generating SecurityHeader from client

Posted by Daniel Kulp <dk...@apache.org>.
On Tue May 5 2009 4:33:37 pm Anu@work wrote:
> I tried putting the soap header using
> requestContext.put("Header.HEADER_LIST", headerList) also tried -exsh but
> each time, this is the Payload I see in my logs

It's not:
 requestContext.put("Header.HEADER_LIST", headerList)
It should be:
 requestContext.put(Header.HEADER_LIST, headerList)

Basically, remove the quotes and import the Header class.   (actually, 
SoapHeader.HEADER_LIST should work as well since Header is the superclass)

Dan


>
> Payload: <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><EncryptV
>alue
> xmlns="http://tempuri.org/"><Value>626948725</Value></EncryptValue></soap:B
>ody></soap:Envelope>
>
> How do I get the
>   <soap:Header>
>     <SecureHeader xmlns="http://tempuri.org/service">
>       <UserName>username</UserName>
>       <Password>password</Password>
>     </SecureHeader>
>   </soap:Header>
>
> in my Payload?
>
> Here's the code I used in client
>
>         SecureHeader sh = new SecureHeader();
>         sh.setUserName("user");
>         sh.setPassword("pass");
>
>         JAXBElement<SecureHeader> job = new JAXBElement<SecureHeader>(
>              new QName("http://tempuri.org/", "SecureHeader"),
> SecureHeader.class, null, sh);
>
>         SoapHeader hdr = new SoapHeader(
>                 new QName("http://tempuri.org/", "MyService"),
>                 job,
>                 new JAXBDataBinding(sh.getClass()));
>
>         List<SoapHeader> holder = new ArrayList<SoapHeader>();
>         holder.add(hdr);
>
>         // Set request context property.
>         java.util.Map<String, Object> requestContext =
>           ((javax.xml.ws.BindingProvider)port).getRequestContext();
>
>         requestContext.put("Header.HEADER_LIST", holder);

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

RE: Generating SecurityHeader from client

Posted by "Anu@work" <an...@bluecasa.com>.
I tried putting the soap header using
requestContext.put("Header.HEADER_LIST", headerList) also tried -exsh but
each time, this is the Payload I see in my logs

Payload: <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><EncryptValue
xmlns="http://tempuri.org/"><Value>626948725</Value></EncryptValue></soap:Body></soap:Envelope>

How do I get the 
  <soap:Header>
    <SecureHeader xmlns="http://tempuri.org/service">
      <UserName>username</UserName>
      <Password>password</Password>
    </SecureHeader>
  </soap:Header> 

in my Payload? 

Here's the code I used in client

        SecureHeader sh = new SecureHeader();
        sh.setUserName("user");
        sh.setPassword("pass");

        JAXBElement<SecureHeader> job = new JAXBElement<SecureHeader>(
             new QName("http://tempuri.org/", "SecureHeader"),
SecureHeader.class, null, sh); 
        
        SoapHeader hdr = new SoapHeader(
                new QName("http://tempuri.org/", "MyService"), 
                job,
                new JAXBDataBinding(sh.getClass()));

        List<SoapHeader> holder = new ArrayList<SoapHeader>();
        holder.add(hdr); 
                
        // Set request context property.
        java.util.Map<String, Object> requestContext =
          ((javax.xml.ws.BindingProvider)port).getRequestContext();
        
        requestContext.put("Header.HEADER_LIST", holder);

-- 
View this message in context: http://www.nabble.com/Generating-SecurityHeader-from-client-tp23306088p23395392.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Generating SecurityHeader from client

Posted by "Purohit, Manoj R " <ma...@citi.com>.
If you have generated client proxy properly it will have header elements as a method input parameter and then you can have it.

for implicit header wsdl to java does not generate it. To resolve this you have to enable -exsh switch.
(true/false)  Enables or disables processing of implicit SOAP headers (i.e. SOAP headers defined in the wsdl:binding but not wsdl:portType section.) Default is false.

HTH
Manoj

-----Original Message-----
From: Anupama Vaid [mailto:Anupama.Vaid@bluecasa.com]
Sent: Wednesday, April 29, 2009 4:08 PM
To: users@cxf.apache.org
Subject: Generating SecurityHeader from client

I am trying to get a security header generated in my SOAP request as
below but without any luck



  <soap:Header>

    <SecureHeader xmlns="http://tempuri.org/service">

      <UserName>username</UserName>

      <Password>password</Password>

    </SecureHeader>

  </soap:Header>



I used wsdl2java -client to generate client code. I see that the
generated code has ObjectFactory.java with a method
'createSecureHeader()' and also a SecureHeader.java, but can't figure
out how to use it. Any help?



Thanks,

Anu