You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Robert Chilvers <ro...@mtlehman.com> on 2007/02/07 00:01:13 UTC

Adding a HTTP Header to a Request

Hi All;

I am not sure if this is the best place for this question, but I am  
stuck.

I have a Axis2 client which I created from a service's WSDL using the  
xmlbeans data binding.  I am now trying to connect to the live  
service, but the service is behind a proxy server.  The proxy server  
monitors the HTTP headers, and based on custom field in the header  
will route the request to the correct machine.   I am trying to add  
the HTTP Header information to my code for the client, but I am not  
sure how to do this.  So far the best I have been able to do is this:

  //Set the HTTP Headers
ServiceClient sc = stub._getServiceClient();
Options options = sc.getOptions();
options.setProperty("myKey", "myValue");
sc.setOptions(options);
stub._setServiceClient(sc);

I am hoping somebody may be able to help me here, or at least point  
me to some reference that discuss this


Rob

Re: Adding a HTTP Header to a Request

Posted by Robert Chilvers <ro...@mtlehman.com>.
I actual figured this out and I decided to post my code incase anyone  
else hits this road block.  Thanks Sameera for the link it was a big  
help.


         ServiceClient _serviceClient = stub._getServiceClient();
         Options ops = _serviceClient.getOptions();
         if(ops==null){
             ops = new Options();
         }

         Header head = new Header();
         head.setName("MyKey");
         head.setValue("MyValue");

         ArrayList v = new ArrayList();
         v.add(head);

         ops.setProperty(HTTPConstants.HTTP_HEADERS, v);
         _serviceClient.setOptions(ops);

Rob


On 6-Feb-07, at 10:14 PM, Sameera Madushan wrote:

> Hi Robert
>
> Check this link,  sometimes it may help you.
>
> http://wso2.org/library/230
>
> Sameera
>
> On 2/7/07, Robert Chilvers <ro...@mtlehman.com> wrote:
> Hi All;
>
> I am not sure if this is the best place for this question, but I am  
> stuck.
>
> I have a Axis2 client which I created from a service's WSDL using  
> the xmlbeans data binding.  I am now trying to connect to the live  
> service, but the service is behind a proxy server.  The proxy  
> server monitors the HTTP headers, and based on custom field in the  
> header will route the request to the correct machine.   I am trying  
> to add the HTTP Header information to my code for the client, but I  
> am not sure how to do this.  So far the best I have been able to do  
> is this:
>
>  //Set the HTTP Headers
> ServiceClient sc = stub._getServiceClient();
> Options options = sc.getOptions();
> options.setProperty("myKey", "myValue");
> sc.setOptions(options);
> stub._setServiceClient(sc);
>
> I am hoping somebody may be able to help me here, or at least point  
> me to some reference that discuss this
>
>
> Rob
>


Re: Adding a HTTP Header to a Request

Posted by Sameera Madushan <sa...@gmail.com>.
Hi Robert

Check this link,  sometimes it may help you.

http://wso2.org/library/230

Sameera

On 2/7/07, Robert Chilvers <ro...@mtlehman.com> wrote:
>
> Hi All;
>
> I am not sure if this is the best place for this question, but I am stuck.
>
> I have a Axis2 client which I created from a service's WSDL using the
> xmlbeans data binding.  I am now trying to connect to the live service, but
> the service is behind a proxy server.  The proxy server monitors the HTTP
> headers, and based on custom field in the header will route the request to
> the correct machine.   I am trying to add the HTTP Header information to my
> code for the client, but I am not sure how to do this.  So far the best I
> have been able to do is this:
>
> * //Set the HTTP Headers*
> *ServiceClient sc = stub._getServiceClient(); *
> *Options options = sc.getOptions();*
> *options.setProperty("myKey", "myValue"); *
> *sc.setOptions(options);*
> *stub._setServiceClient(sc);*
>
> I am hoping somebody may be able to help me here, or at least point me to
> some reference that discuss this
>
>
> Rob
>