By the way, I forgot to mention, if you are sending some "official" HTTP headers, Axis will forcibly strip them. The only solution for now is to either modify the distributed HTTPSender or create your own modified HTTPSender and register it dynamically (again, I can provide code illustrating this dynamic registration).

See this bug:

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21812

Aaron


Aaron Hamid wrote:


Implement a javax.xml.rpc.handler.GenericHandler and register it on your client (if sending headers) or server (if receiving headers). On the client side you need to dynamically register your handler through the handlerregistry of your service. On the server side it is a matter of editing the deployment descriptor to include your handler.

In your client handler you can do:

public boolean handleRequest(MessageContext context) {
// get the headers object
Hashtable headers = (Hashtable) context.getProperty(HTTPConstants.REQUEST_HEADERS);
if (headers == null) {
headers = new Hashtable();
context.setProperty(HTTPConstants.REQUEST_HEADERS, headers);
}


    // add a header
    String someheadervalue = (String) context.getProperty("PROPS_KEY");
    headers.put("MYHEADER", someheadervalue);

    return true;
}

Now, you ask how the handler will know what header to set. Well, you have to use the _setProperty() call on your stub to propagate information to the handler. e.g.

((javax.xml.rpc.Stub)yourapi)._setProperty("PROPS_KEY", "here is the value of the header I want to set, thank you");

As an additional treat, these properties are apparently not accessible from the handler prior to Axis 1.1.

On the server side your handler needs to do something like:

public boolean handleRequest(javax.xml.rpc.handler.MessageContext context) {
// get the servletrequest object
HttpServletRequest request = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
if (request == null) return true;


    // look up your header
    String myheadervalue = (String) request.getHeader("MYHEADER");

System.out.println("my header was propagated with this value!: " + myheadervalue);

    return true;
}

Note that this requires usage of specific internal Axis classes/APIs (e.g. HTTPConstants properties set in the context), so it will probably not be portable (although I imagine other frameworks will provide similar mechanisms).

I can provide sample code and/or libraries if you need.

Aaron Hamid
CIT/I&D
Cornell University

Benjamin Flohr wrote:

Hi*,

we need to access the http headers and set them using information taken from
the fully formed SOAP envelope before it is posted. We managed to do this by
modifying the HttpSender and assigning it to the call as its handler.
Unfortunately we lose the typemapping for the serializer/deserializer and
can no
longer parse the incoming SOAP message. Is there a straightforward way to
alter
Http headers? Can anyone help?


thanks

Andrew and Benjamin







Reply via email to