Thanks Sergey, Daniel. I am able to set the HTTP header now. I had to use
Message.PROTOCOL_HEADERS key to set the HTTP header. Here is my code:
public class HTTPHeaderOutInterceptor extends
AbstractPhaseInterceptor<Message> {
public HTTPHeaderOutInterceptor() {
super(Phase.WRITE);
}
public void handleMessage(Message message) throws Fault {
Map<String, List<String>> requestHeaders = (Map<String,
List<String>>) message.get(Message.PROTOCOL_HEADERS);
requestHeaders.put("session-id",Arrays.asList("sess#1"));
}
}
Thanks and regards,
Anand R
From: Daniel Kulp <[email protected]>
To: [email protected]
Cc: Sergey Beryozkin <[email protected]>
Date: 18-02-11 05:37 PM
Subject: Re: Query - Setting a custom HTTP request header
On Friday 18 February 2011 6:18:29 AM Sergey Beryozkin wrote:
> If you need to do it for a SOAP client then you can register a simple
> client out interceptor, may be with the Phase.WRITE, and modify the
> Message.REQUEST_HEADERS property on the current outbound message, this
> key will return you a Map<String, List<String>> map of request headers
>
You can do this without an interceptor as well. Grab the request context
and
create the Map like above, set the info in the map, set the map onto the
request context with that key.
Dan
> cheers, Sergey
>
> On Fri, Feb 18, 2011 at 11:08 AM, Anand R <[email protected]>
wrote:
> > Thanks Raman. I actually need to set a custom header on my HTTP
request.
> > I believe the sample code that you have provided sets the SOAP header.
> > Thanks and regards,
> > Anand R
> >
> >
> >
> > From: "Malisetti, Ramanjaneyulu" <[email protected]>
> > To: <[email protected]>
> > Date: 18-02-11 04:18 PM
> > Subject: RE: Query - Setting a custom HTTP request header
> >
> >
> >
> > How the client is created. If it is through Dispatch. You can do the
> > following way.
> >
> > resourceDispatch.getRequestContext().put(Header.HEADER_LIST,
> > getCustomerHeader());
> >
> > public Collection<Header> getCustomerHeader() throws
> > Exception {
> > SoapHeader sh_client_id=null;
> > SoapHeader sh_dev_pass=null;
> > SoapHeader sh_dev_email=null;
> >
> >
> > try {
> > Document d = createXMLDocument();
> > Element dev_email =
> > d.createElement("developer_email");
> > dev_email.setTextContent("......");
> > sh_dev_email = new SoapHeader(new
> > QName("http://www.google.com/api/adsense/v2",
"AccountServiceService"),
> > dev_email);
> > Element dev_pass =
> > d.createElement("developer_password");
> > dev_pass.setTextContent("......");
> > sh_dev_pass = new SoapHeader(new
> > QName("http://www.google.com/api/adsense/v2",
"AccountServiceService"),
> > dev_pass);
> > Element client_id =
> > d.createElement("client_id");
> > client_id.setTextContent("......");
> > sh_client_id = new SoapHeader(new
> > QName("http://www.google.com/api/adsense/v2",
"AccountServiceService"),
> > client_id);
> > }catch(Exception e) {
> > throw new
> > Exception(e.getMessage(), new
> > Throwable(e));
> > }
> > List<Header> lshd = new
> > ArrayList<Header>();
> > lshd.add(sh_dev_email);
> > lshd.add(sh_dev_pass);
> > lshd.add(sh_client_id);
> >
> > return lshd;
> > }
> >
> > Regards
> > Raman
> > -----Original Message-----
> > From: Anand R [mailto:[email protected]]
> > Sent: Friday, February 18, 2011 3:58 PM
> > To: [email protected]
> > Subject: Query - Setting a custom HTTP request header
> >
> > Hi,
> >
> > Is there a way to set a custom HTTP request header from a CXF client?
> > Thanks and regards,
> > Anand R
> >
> >
> >
> >
> >
> > DISCLAIMER:
> >
> > "The information in this e-mail and any attachment is intended only
for
> > the person to whom it is addressed and may contain confidential and/or
> > privileged material. If you have received this e-mail in error, kindly
> > contact the sender and destroy all copies of the original
communication.
> >
> > IBS makes no warranty, express or implied, nor guarantees the
accuracy,
> > adequacy or completeness of the information contained in this email or
> > any
> > attachment and is not liable for any errors, defects, omissions,
viruses
> >
> > or for resultant loss or damage, if any, direct or indirect."
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > DISCLAIMER:
> >
> > "The information in this e-mail and any attachment is intended only
for
> > the person to whom it is addressed and may contain confidential and/or
> > privileged material. If you have received this e-mail in error, kindly
> > contact the sender and destroy all copies of the original
communication.
> > IBS makes no warranty, express or implied, nor guarantees the
accuracy,
> > adequacy or completeness of the information contained in this email or
> > any attachment and is not liable for any errors, defects, omissions,
> > viruses or for resultant loss or damage, if any, direct or indirect."
--
Daniel Kulp
[email protected]
http://dankulp.com/blog
DISCLAIMER:
"The information in this e-mail and any attachment is intended only for
the person to whom it is addressed and may contain confidential and/or
privileged material. If you have received this e-mail in error, kindly
contact the sender and destroy all copies of the original communication.
IBS makes no warranty, express or implied, nor guarantees the accuracy,
adequacy or completeness of the information contained in this email or any
attachment and is not liable for any errors, defects, omissions, viruses
or for resultant loss or damage, if any, direct or indirect."