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 "S.E.Parkin" <S....@newcastle.ac.uk> on 2003/05/06 13:16:57 UTC

Using a client-side handler to modify the target endpoint

Hi


I've recently started putting some code together for a client-side handler 
which automatically takes the target endpoint of a service, places this into a 
SOAP header entry, and then replaces it with another endpoint (which it is 
hoped can then point to a routing node, used to reliably forward the call to 
the endpoint that was originally targeted).

However, I'm having trouble insofar as I've got a Handler which extracts the 
SOAPEnvelope from the MessageContext and adds a new Header entry with the old 
endpoint address in it, but when I extract the Call object from the 
MessageContext and alter the target endpoint of this call, and then set the 
'call_object' property in the MessageContext again, although the endpoint has 
apparently been altered correctly in the MessageContext, the Call is still 
targeted at the original endpoint. A colleague has suggested that Axis is 
caching the endpoint for the call (irrespective of the message context) 
somewhere before reaching the client-side handler (which, if this is the case, 
would obviously make any endpoint alterations in the handler useless), and I'm 
wondering if this is what is actually happening, and if so where - otherwise, 
how else may I properly change the endpoint automatically in a handler?

Just for reference, here's my client wsdd file and the core functionality of 
the associated client handler ... :-)

-------------------
client-config.wsdd:
-------------------

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
            xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
 <transport name="http" 
pivot="java:org.apache.axis.transport.http.HTTPSender"/>
 <transport name="local" 
pivot="java:org.apache.axis.transport.local.LocalSender"/>
 <transport name="java" 
pivot="java:org.apache.axis.transport.java.JavaSender"/>
 <globalConfiguration>
  <requestFlow>
   <handler type="java:ClientHeaderHandler"/>
  </requestFlow>
 </globalConfiguration>
</deployment>


--------------------------------------------------
The body of the ClientHeaderHandler is as follows:
--------------------------------------------------

//extract the message from the context
Message requestMessage = msgContext.getRequestMessage();
            
//extract the original call object from the context
Call tempC = (Call)msgContext.getProperty("call_object");
//determine the address of the target endpoint
System.out.print("\nold endpoint is: " + tempC.getTargetEndpointAddress());
            
//get the envelope and add a new header storing the old endpoint address
SOAPEnvelope myEnv = requestMessage.getSOAPEnvelope();
myEnv.addHeader(new SOAPHeaderElement("http://testhost.com/", "target", 
tempC.getTargetEndpointAddress()));
            
//change the endpoint address and record this change in the message context
tempC.setTargetEndpointAddress("http://localhost:8080/axis/services/dfdfd");
msgContext.setProperty("call_object", tempC);
            
//check that the change of endpoint has been carried out correctly
Call tC = (Call)msgContext.getProperty("call_object");
System.out.print("\nnew endpoint is: " + tC.getTargetEndpointAddress());



Any help would be greatly appreciated.


Thanks,
Simon Parkin