Hi Alain,
Hi Rodrigo,

that's great! Your solution-samples are looking incredible. I hope, I'll
find time to realise it the next days.

I'm just a bit confused about the client-config.wsdd-file because I
don't have such a file right now.
Sure I know the server-config.wsdd, but a clientprogram will not be
deployed, or will it?

And if the program never used this wsdd before, how can I tell it to do
so?
My experiences with axis are quite simple yet, so I am not sure I
haven't overlooked something important about this.

BTW: At the moment I'm using libraries from axis 1.3 (Download archive
from october 05).

Anyway, let me tell you I really appreciate to your support so far.

Carsten


Am Dienstag, den 16.05.2006, 16:47 +0200 schrieb Rodrigo Ruiz:
> CommonsHTTPSender is easier to subclass and modify. I pass you a
> simple  
> subclass that could do the trick :-)
> 
> HTH, 
> Rodrigo
> 
> 
> 
> package org.rodrisoft;
> 
> import java.io.FileInputStream; 
> import java.io.InputStream; 
> import java.net.InetAddress; 
> import java.net.URL; 
> import java.util.HashMap; 
> import java.util.Hashtable; 
> import java.util.Iterator; 
> import java.util.Map; 
> import java.util.Properties;
> 
> import org.apache.axis.MessageContext; 
> import org.apache.axis.transport.http.CommonsHTTPSender; 
> import org.apache.commons.httpclient.HostConfiguration; 
> import org.apache.commons.httpclient.HttpClient;
> 
> /** 
>   * Sender implementation that uses Jakarta Commons HTTP for  
> transmission, and 
>   * implements a routing map table to select a local address
> depending  
> on the 
>   * remote address to connect to. 
>   * <p> 
>   * This sender can be configured in the client-config.wsdd file like
> this: 
>   * <pre> 
>   * &lt;transport name="http" 
>   *               pivot="java:org.rodrisoft.RoutedCommonsHTTPSender"> 
>   *   &lt;parameter name="map-file"
> value="path/to/map/file.properties"/> 
>   *   &lt;parameter name="map:remote-addr" value="10.33.5.67"/> 
>   * &lt;/transport> 
>   * </pre> 
>   * <p> 
>   * The first parameter specifies a .properties file containing pairs
> in 
>   * the form: 
>   * 
>   * <pre> 
>   *   remote-addr=remote-addr 
>   * </pre> 
>   * 
>   * The second parameter is an example of how to specify a single
> route 
>   * table entry directly in the .wsdd file. 
>   * <p> 
>   * The first parameter allows to share the route table among several 
>   * protocols. 
>   * <p> 
>   * The local binding address can also be specified through the
> message 
>   * context. This allows services and handlers set the local address,
> and 
>   * provide smarter routing algorithms. 
>   * <p> 
>   * Original work from Davanum Srinivas. 
>   * 
>   * @author Davanum Srinivas ([EMAIL PROTECTED]) 
>   * @author Rodrigo Ruiz ([EMAIL PROTECTED]) 
>   * @version 1.0 
>   */ 
> public class RoutedCommonsHTTPSender extends CommonsHTTPSender {
> 
>    /** 
>     * <code>serialVersionUID</code> attribute. 
>     */ 
>    private static final long serialVersionUID = -8610352356067978620L;
> 
>    /** 
>     * MessageContext Property name for setting the local bind
> address. 
>     */ 
>    public static final String LOCAL_BIND_ADDRESS =
> "local.bind.address";
> 
>    /** 
>     * Local Bind Address Route Map. 
>     */ 
>    private final Map routeTable = new HashMap();
> 
>    /** 
>     * Flag that controls bindMap synchronization. 
>     */ 
>    private boolean dirty = true;
> 
>    public synchronized void setOption(String name, Object value) { 
>      this.dirty = true; 
>      super.setOption(name, value); 
>    }
> 
>    public synchronized boolean setOptionDefault(String name, 
>                                                 Object value) { 
>      this.dirty = true; 
>      return super.setOptionDefault(name, value); 
>    }
> 
>    public synchronized void setOptions(Hashtable options) { 
>      this.dirty = true; 
>      super.setOptions(options); 
>    }
> 
>    protected HostConfiguration getHostConfiguration(HttpClient
> client, 
>        MessageContext context, URL targetURL) {
> 
>      HostConfiguration config = super.getHostConfiguration(client, 
>                                                            context, 
>                                                            targetURL);
> 
>      if (targetURL != null) { 
>        String remoteHost = targetURL.getHost(); 
>        InetAddress localAddr = getRouteFor(context, remoteHost); 
>        if (localAddr != null) { 
>          config.setLocalAddress(localAddr); 
>        } 
>      }
> 
>      return config; 
>    }
> 
>    /** 
>     * This utility method allows to force the route table to be
> rebuilt. 
>     * It can be useful if the route table file is modified, and we
> can 
>     * manage to get the instance of this handler. 
>     */ 
>    public void rebuildTable() { 
>      this.dirty = true; 
>    }
> 
>    /** 
>     * Gets a route for the specified remote address, allowing it to
> be 
>     * specified through a Message Context parameter. 
>     * 
>     * @param ctx   The message context 
>     * @param host  The remote host to map 
>     * @return      The mapped address, or null if none found 
>     */ 
>    protected InetAddress getRouteFor(MessageContext ctx, String host)
> { 
>      Object value = ctx.getProperty(LOCAL_BIND_ADDRESS); 
>      if (value instanceof InetAddress) { 
>        return (InetAddress)value; 
>      }
> 
>      if (value != null) { 
>        String hostName = value.toString(); 
>        try { 
>          return InetAddress.getByName(hostName); 
>        } catch (Exception e) { 
>          log.error("Could not resolve local bind address " +
> hostName); 
>        } 
>      }
> 
>      // No value defined in the MessageContext. Use route map.
> 
>      value = getRouteTable().get(host); 
>      if (value instanceof InetAddress) { 
>        return (InetAddress)value; 
>      }
> 
>      if (value != null) { 
>        String hostName = value.toString(); 
>        try { 
>          return InetAddress.getByName(hostName); 
>        } catch (Exception e) { 
>          log.error("Could not resolve local bind address " +
> hostName); 
>        } 
>      }
> 
>      return null; 
>    }
> 
>    /** 
>     * Gets the route mapping table. 
>     * 
>     * @return The route mapping table 
>     */ 
>    protected synchronized Map getRouteTable() { 
>      if (dirty) { 
>        routeTable.clear();
> 
>        Hashtable options = getOptions(); 
>        String mapFile = (String)options.get("map-file"); 
>        if (mapFile != null) { 
>          InputStream is = null; 
>          try { 
>            is = new FileInputStream(mapFile); 
>            Properties props = new Properties(); 
>            props.load(is); 
>            options.putAll(props); 
>          } catch (Exception e) { 
>            log.error("Could not load route mapping table at " +
> mapFile); 
>          } 
>        }
> 
>        for (Iterator it = options.entrySet().iterator();
> it.hasNext();) { 
>          Map.Entry entry = (Map.Entry)it.next(); 
>          Object key = entry.getKey(); 
>          if (key instanceof String) { 
>            String skey = (String)key; 
>            if (skey.startsWith("map:")) { 
>              String remoteHost = skey.substring(4).trim(); 
>              String localHost = ((String)entry.getValue()).trim(); 
>              try { 
>                InetAddress localAddr =
> InetAddress.getByName(localHost); 
>                routeTable.put(remoteHost, localAddr); 
>              } catch (Exception e) { 
>                log.warn("Could not resolve local bind address " 
>                         + localHost, e); 
>                routeTable.put(remoteHost, localHost); 
>              } 
>            } 
>          } 
>        } 
>        dirty = false; 
>      }
> 
>      return routeTable; 
>    } 
> }
> 
> 
> 
> --  
> ------------------------------------------------------------------- 
> GRIDSYSTEMS                    Rodrigo Ruiz Aguayo 
> Parc Bit - Son Espanyol 
> 07120 Palma de Mallorca        mailto:[EMAIL PROTECTED] 
> Baleares - EspaƱa              Tel:+34-971435085 Fax:+34-971435082 
> http://www.gridsystems.com 
> -------------------------------------------------------------------
> 
> 
> --  
> No virus found in this outgoing message. 
> Checked by AVG Free Edition. 
> Version: 7.1.392 / Virus Database: 268.5.6/339 - Release Date:
> 14/05/2006
> 
> 

Reply via email to