Announcement Announcement Module
Collapse
No announcement yet.
How do I set the local IP address in Spring? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I set the local IP address in Spring?

    In the grinder I have the following Function that allows me to set the ip address that my client applet connects from when I use the Grinder's http classes. I am trying to test a spring based application so need to know what the spring equivalent of this function is?

    setLocalAddress

    void setLocalAddress(String localAddress)
    throws URLException
    Set the client IP address to use for outbound connections.
    The default client IP address, and hence the network interface, used for outbound HTTP requests is the first returned to the Java VM by the operating system. This method allows a different network interface to be specified that will be used for connections that are subsequently created. It does not affect existing socket connections that may have already been created for this HTTPPluginConnection.

    localAddress should correspond to a local network interface.If it doesn't a java.net.BindException will be thrown when the connection is first used.

    Parameters:
    localAddress - The local host name or IP address to bind to. Pass null to set the default local interface.
    Throws:
    URLException - If localAddress could not be resolved.
    http://grinder.sourceforge.net/g3/sc...a.lang.String)

    If there is no equivalent in Spring can it be done with the base Java classes?

    I have been searching for over a week looking for this so will appreciate and try any suggestions.

    Dave.

  • #2
    Some things I have tried:

    org.springframework.integration.ip.CommonSocketOpt ions
    org.springframework.integration.ip.tcp.TcpNetSendi ngMessageHandler
    org.springframework.integration.ip.AbstractInterne tProtocolSendingMessageHandler
    org.springframework.integration.ip.tcp.connection. TcpNetServerConnectionFactory

    But none worked...

    This seems pretty damning?
    http://static.springsource.org/sprin...e/html/ip.html
    local-address N Y On a multi-homed system, specifies an IP address for the interface to which the socket will be bound.
    I would still like to know if there is a way to acheive setting the client (local) ip address.

    Dave.

    Comment


    • #3
      Another attempt that didn't work though it looked promising:

      *sys-package-mgr*: processing new jar, 'H:\mypath\commons-httpclient-3.1.jar'
      *sys-package-mgr*: processing modified jar, 'H:\mypath\spring-context.jar'

      Code:
      import org.apache.commons.httpclient.HostConfiguration;
      ...
          HostConfiguration hc = new HostConfiguration();
      ...
          hc.setLocalAddress(localAddress);
      While this didn't error it didn't change the client IP address either. I wonder if i'm in the right track or not?

      Dave.

      Comment


      • #4
        Another thing I've tried that didn't work....


        Code:
        	import java.lang.System
        	System.setProperty("java.rmi.server.hostname", SessionDict['IPAddress']);
        	System.setProperty("httpclient.localaddress", SessionDict['IPAddress']);

        Comment


        • #5
          Originally posted by damies View Post
          Another thing I've tried that didn't work....


          Code:
          	import java.lang.System
          	System.setProperty("java.rmi.server.hostname", SessionDict['IPAddress']);
          	System.setProperty("httpclient.localaddress", SessionDict['IPAddress']);
          I have just try it but it does not work...any things wrong here? du hoc singapore, du hoc, cong ty du hoc, du hoc my, du hoc uc, tu van du hoc

          Comment


          • #6
            louis2609,

            As I stated earlier that doesn't work. it was just one of the many I tried....

            I still have not found a solution for this, I did however find this post (but nothing else related to it:

            http://mail-archives.apache.org/mod_...bevocal.com%3E

            As I understand it, the Spring Libraries call HttpClient, which in turn creates the socket to the web server.

            I would be useful if someone can confirm this is the case and that it is due to the underlying HttpClient that is causing us to not be able to set the client's IP Address. Once Confirmed we can raise a feature request / bug.

            Dave.

            Comment

            Working...
            X