diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-10-12 10:45:43 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-10-12 10:45:43 +0200 |
commit | f7ec04896f054614a1f08a66c4f7cf9fe71d8f6a (patch) | |
tree | 6d56b2613e3b5f15e7529dcc8afef495b9e566c7 /java | |
parent | Bug 4222 - cannot install to network drive (diff) | |
download | ice-f7ec04896f054614a1f08a66c4f7cf9fe71d8f6a.tar.bz2 ice-f7ec04896f054614a1f08a66c4f7cf9fe71d8f6a.tar.xz ice-f7ec04896f054614a1f08a66c4f7cf9fe71d8f6a.zip |
Added ConnectionInfo/EndpointInfo, bug 4280 & 3964
Diffstat (limited to 'java')
-rw-r--r-- | java/build.xml | 3 | ||||
-rw-r--r-- | java/src/Ice/ConnectionI.java | 10 | ||||
-rw-r--r-- | java/src/IceInternal/OpaqueEndpointI.java | 27 | ||||
-rw-r--r-- | java/src/IceInternal/RoutableReference.java | 2 | ||||
-rw-r--r-- | java/src/IceInternal/TcpEndpointI.java | 45 | ||||
-rw-r--r-- | java/src/IceInternal/TcpTransceiver.java | 21 | ||||
-rw-r--r-- | java/src/IceInternal/Transceiver.java | 1 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpointI.java | 65 | ||||
-rw-r--r-- | java/src/IceInternal/UdpTransceiver.java | 32 | ||||
-rw-r--r-- | java/src/IceSSL/EndpointI.java | 45 | ||||
-rw-r--r-- | java/src/IceSSL/TransceiverI.java | 43 | ||||
-rw-r--r-- | java/src/IceUtilInternal/Base64.java | 2 | ||||
-rw-r--r-- | java/test/Ice/background/EndpointI.java | 13 | ||||
-rw-r--r-- | java/test/Ice/background/Test.ice | 4 | ||||
-rw-r--r-- | java/test/Ice/background/Transceiver.java | 6 | ||||
-rw-r--r-- | java/test/Ice/proxy/AllTests.java | 34 |
16 files changed, 249 insertions, 104 deletions
diff --git a/java/build.xml b/java/build.xml index b8125bb6586..63baedf8144 100644 --- a/java/build.xml +++ b/java/build.xml @@ -115,7 +115,8 @@ <pathelement path="${slice.dir}" /> </includepath> <fileset dir="${slice.dir}/IceSSL"> - <include name="Endpoint.ice" /> + <include name="EndpointInfo.ice" /> + <include name="ConnectionInfo.ice" /> </fileset> </slice2java> diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index 87ae7165e24..88ff87fa40b 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -1239,6 +1239,16 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne return _endpoint.timeout(); // No mutex protection necessary, _endpoint is immutable. } + public synchronized ConnectionInfo + getInfo() + { + if(_exception != null) + { + throw (Ice.LocalException)_exception.fillInStackTrace(); + } + return _transceiver.getInfo(); + } + // // Only used by the SSL plug-in. // diff --git a/java/src/IceInternal/OpaqueEndpointI.java b/java/src/IceInternal/OpaqueEndpointI.java index 51006ba5f5c..f4c9a8e1f3a 100644 --- a/java/src/IceInternal/OpaqueEndpointI.java +++ b/java/src/IceInternal/OpaqueEndpointI.java @@ -9,7 +9,7 @@ package IceInternal; -final class OpaqueEndpointI extends EndpointI implements Ice.OpaqueEndpoint +final class OpaqueEndpointI extends EndpointI { public OpaqueEndpointI(String str) @@ -134,6 +134,31 @@ final class OpaqueEndpointI extends EndpointI implements Ice.OpaqueEndpoint } // + // Return the endpoint information. + // + public Ice.EndpointInfo + getInfo() + { + return new Ice.OpaqueEndpointInfo(-1, false, _rawBytes) + { + public short type() + { + return _type; + } + + public boolean datagram() + { + return false; + } + + public boolean secure() + { + return false; + } + }; + } + + // // Return the endpoint type // public short diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java index d5fc69633f1..eb087099655 100644 --- a/java/src/IceInternal/RoutableReference.java +++ b/java/src/IceInternal/RoutableReference.java @@ -657,7 +657,7 @@ public class RoutableReference extends Reference // for(EndpointI endpoint : allEndpoints) { - if(!(endpoint instanceof Ice.OpaqueEndpoint)) + if(!(endpoint instanceof IceInternal.OpaqueEndpointI)) { endpoints.add(endpoint); } diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index 15689f61566..44fc624af8d 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -9,7 +9,7 @@ package IceInternal; -final class TcpEndpointI extends EndpointI implements Ice.TcpEndpoint +final class TcpEndpointI extends EndpointI { final static short TYPE = 1; @@ -231,6 +231,31 @@ final class TcpEndpointI extends EndpointI implements Ice.TcpEndpoint } // + // Return the endpoint information. + // + public Ice.EndpointInfo + getInfo() + { + return new Ice.TcpEndpointInfo(_timeout, _compress, _host, _port) + { + public short type() + { + return TYPE; + } + + public boolean datagram() + { + return false; + } + + public boolean secure() + { + return false; + } + }; + } + + // // Return the endpoint type // public short @@ -330,24 +355,6 @@ final class TcpEndpointI extends EndpointI implements Ice.TcpEndpoint } // - // Get the host name. - // - public String - host() - { - return _host; - } - - // - // Get the port number. - // - public int - port() - { - return _port; - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new diff --git a/java/src/IceInternal/TcpTransceiver.java b/java/src/IceInternal/TcpTransceiver.java index 6d4a2901f5e..fef0558e62c 100644 --- a/java/src/IceInternal/TcpTransceiver.java +++ b/java/src/IceInternal/TcpTransceiver.java @@ -221,6 +221,27 @@ final class TcpTransceiver implements Transceiver return _desc; } + public Ice.ConnectionInfo + getInfo() + { + assert(_fd != null); + Ice.TcpConnectionInfo info = new Ice.TcpConnectionInfo(); + java.net.Socket socket = _fd.socket(); + info.localAddress = socket.getLocalAddress().getHostAddress(); + info.localPort = socket.getLocalPort(); + if(socket.getInetAddress() != null) + { + info.remoteAddress = socket.getInetAddress().getHostAddress(); + info.remotePort = socket.getPort(); + } + else + { + info.remoteAddress = ""; + info.remotePort = -1; + } + return info; + } + public void checkSendSize(Buffer buf, int messageSizeMax) { diff --git a/java/src/IceInternal/Transceiver.java b/java/src/IceInternal/Transceiver.java index 6cecdd4cab5..a57bac6590a 100644 --- a/java/src/IceInternal/Transceiver.java +++ b/java/src/IceInternal/Transceiver.java @@ -43,5 +43,6 @@ public interface Transceiver String type(); String toString(); + Ice.ConnectionInfo getInfo(); void checkSendSize(Buffer buf, int messageSizeMax); } diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index c81838ab617..846b4f41c48 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -9,7 +9,7 @@ package IceInternal; -final class UdpEndpointI extends EndpointI implements Ice.UdpEndpoint +final class UdpEndpointI extends EndpointI { final static short TYPE = 3; @@ -397,6 +397,32 @@ final class UdpEndpointI extends EndpointI implements Ice.UdpEndpoint } // + // Return the endpoint information. + // + public Ice.EndpointInfo + getInfo() + { + return new Ice.UdpEndpointInfo(-1, _compress, _host, _port, _protocolMajor, _protocolMinor, _encodingMajor, + _encodingMinor, _mcastInterface, _mcastTtl) + { + public short type() + { + return TYPE; + } + + public boolean datagram() + { + return true; + } + + public boolean secure() + { + return false; + } + }; + } + + // // Return the endpoint type // public short @@ -493,43 +519,6 @@ final class UdpEndpointI extends EndpointI implements Ice.UdpEndpoint } // - // Get the host name. - // - public String - host() - { - return _host; - } - - // - // Get the port number. - // - public int - port() - { - return _port; - } - - // - // Get the multicast interface. - // - public String - mcastInterface() - { - return _mcastInterface; - } - - // - // Get the multicast time-to-live. - // - public int - mcastTtl() - { - return _mcastTtl; - } - - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new diff --git a/java/src/IceInternal/UdpTransceiver.java b/java/src/IceInternal/UdpTransceiver.java index 70533314e95..10f4c531935 100644 --- a/java/src/IceInternal/UdpTransceiver.java +++ b/java/src/IceInternal/UdpTransceiver.java @@ -229,6 +229,38 @@ final class UdpTransceiver implements Transceiver } } + public Ice.ConnectionInfo + getInfo() + { + assert(_fd != null); + + Ice.UdpConnectionInfo info = new Ice.UdpConnectionInfo(); + java.net.DatagramSocket socket = _fd.socket(); + info.localAddress = socket.getLocalAddress().getHostAddress(); + info.localPort = socket.getLocalPort(); + if(socket.getInetAddress() != null) + { + info.remoteAddress = socket.getInetAddress().getHostAddress(); + info.remotePort = socket.getPort(); + } + else + { + info.remoteAddress = ""; + info.remotePort = -1; + } + if(_mcastAddr != null) + { + info.mcastAddress = _mcastAddr.getAddress().getHostAddress(); + info.mcastPort = _mcastAddr.getPort(); + } + else + { + info.mcastAddress = ""; + info.mcastPort = -1; + } + return info; + } + public void checkSendSize(Buffer buf, int messageSizeMax) { diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java index c3a3a4e05a5..77e70e0671d 100644 --- a/java/src/IceSSL/EndpointI.java +++ b/java/src/IceSSL/EndpointI.java @@ -9,7 +9,7 @@ package IceSSL; -final class EndpointI extends IceInternal.EndpointI implements IceSSL.SslEndpoint +final class EndpointI extends IceInternal.EndpointI { final static short TYPE = 2; @@ -231,6 +231,31 @@ final class EndpointI extends IceInternal.EndpointI implements IceSSL.SslEndpoin } // + // Return the endpoint information. + // + public Ice.EndpointInfo + getInfo() + { + return new IceSSL.SSLEndpointInfo(_timeout, _compress, _host, _port) + { + public short type() + { + return TYPE; + } + + public boolean datagram() + { + return false; + } + + public boolean secure() + { + return true; + } + }; + } + + // // Return the endpoint type // public short @@ -330,24 +355,6 @@ final class EndpointI extends IceInternal.EndpointI implements IceSSL.SslEndpoin } // - // Get the host name. - // - public String - host() - { - return _host; - } - - // - // Get the port number. - // - public int - port() - { - return _port; - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new diff --git a/java/src/IceSSL/TransceiverI.java b/java/src/IceSSL/TransceiverI.java index 60a434e7719..54687c5f052 100644 --- a/java/src/IceSSL/TransceiverI.java +++ b/java/src/IceSSL/TransceiverI.java @@ -274,6 +274,49 @@ final class TransceiverI implements IceInternal.Transceiver return _desc; } + public Ice.ConnectionInfo + getInfo() + { + assert(_fd != null); + + IceSSL.SSLConnectionInfo info = new IceSSL.SSLConnectionInfo(); + java.net.Socket socket = _fd.socket(); + info.localAddress = socket.getLocalAddress().getHostAddress(); + info.localPort = socket.getLocalPort(); + if(socket.getInetAddress() != null) + { + info.remoteAddress = socket.getInetAddress().getHostAddress(); + info.remotePort = socket.getPort(); + } + else + { + info.remoteAddress = ""; + info.remotePort = -1; + } + SSLSession session = _engine.getSession(); + info.cipher = session.getCipherSuite(); + try + { + java.util.ArrayList<String> certs = new java.util.ArrayList<String>(); + for(java.security.cert.Certificate c : session.getPeerCertificates()) + { + StringBuffer s = new StringBuffer("-----BEGIN CERTIFICATE-----\n"); + s.append(IceUtilInternal.Base64.encode(c.getEncoded())); + s.append("\n-----END CERTIFICATE-----"); + certs.add(s.toString()); + } + info.certs = certs.toArray(new String[0]); + } + catch(java.security.cert.CertificateEncodingException ex) + { + } + catch(javax.net.ssl.SSLPeerUnverifiedException ex) + { + // No peer certificates. + } + return info; + } + public void checkSendSize(IceInternal.Buffer buf, int messageSizeMax) { diff --git a/java/src/IceUtilInternal/Base64.java b/java/src/IceUtilInternal/Base64.java index ae8211bafee..18ad4a83e6e 100644 --- a/java/src/IceUtilInternal/Base64.java +++ b/java/src/IceUtilInternal/Base64.java @@ -82,7 +82,7 @@ encode(byte[] plainSeq) while((retval.length() - iter) > 76) { - outString.append(retval.substring(iter, 76)); + outString.append(retval.substring(iter, iter + 76)); outString.append("\r\n"); iter += 76; } diff --git a/java/test/Ice/background/EndpointI.java b/java/test/Ice/background/EndpointI.java index 07249955651..7ae4acaa674 100644 --- a/java/test/Ice/background/EndpointI.java +++ b/java/test/Ice/background/EndpointI.java @@ -8,9 +8,7 @@ // ********************************************************************** package test.Ice.background; -import test.Ice.background.Test.TestEndpoint; - -final class EndpointI extends IceInternal.EndpointI implements TestEndpoint +final class EndpointI extends IceInternal.EndpointI { final static short TYPE_BASE = 100; @@ -41,6 +39,15 @@ final class EndpointI extends IceInternal.EndpointI implements TestEndpoint } // + // Return the endpoint information/ + // + public Ice.EndpointInfo + getInfo() + { + return _endpoint.getInfo(); + } + + // // Return the endpoint type // public short diff --git a/java/test/Ice/background/Test.ice b/java/test/Ice/background/Test.ice index caf9d9c995c..f438500460d 100644 --- a/java/test/Ice/background/Test.ice +++ b/java/test/Ice/background/Test.ice @@ -43,10 +43,6 @@ interface BackgroundController void writeException(bool enable); }; -local interface TestEndpoint extends Ice::Endpoint -{ -}; - }; #endif diff --git a/java/test/Ice/background/Transceiver.java b/java/test/Ice/background/Transceiver.java index 392b3227721..e5c247ae95e 100644 --- a/java/test/Ice/background/Transceiver.java +++ b/java/test/Ice/background/Transceiver.java @@ -103,6 +103,12 @@ final class Transceiver implements IceInternal.Transceiver return _transceiver.toString(); } + public Ice.ConnectionInfo + getInfo() + { + return _transceiver.getInfo(); + } + public void checkSendSize(IceInternal.Buffer buf, int messageSizeMax) { diff --git a/java/test/Ice/proxy/AllTests.java b/java/test/Ice/proxy/AllTests.java index af03b87fee6..4d1f804e9c6 100644 --- a/java/test/Ice/proxy/AllTests.java +++ b/java/test/Ice/proxy/AllTests.java @@ -652,23 +652,23 @@ public class AllTests Ice.ObjectPrx p = communicator.stringToProxy("test -t:tcp -h tcphost -p 10000 -t 1200 -z:udp -h udphost -p 10001 --interface eth0 --ttl 5:opaque -t 100 -v ABCD"); Ice.Endpoint[] endps = p.ice_getEndpoints(); - test(endps[0] instanceof Ice.TcpEndpoint); - Ice.TcpEndpoint tcpEndpoint = (Ice.TcpEndpoint)endps[0]; - test(tcpEndpoint.host().equals("tcphost")); - test(tcpEndpoint.port() == 10000); - test(tcpEndpoint.timeout() == 1200); - test(tcpEndpoint.compress()); - - test(endps[1] instanceof Ice.UdpEndpoint); - Ice.UdpEndpoint udpEndpoint = (Ice.UdpEndpoint)endps[1]; - test(udpEndpoint.host().equals("udphost")); - test(udpEndpoint.port() == 10001); - test(udpEndpoint.mcastInterface().equals("eth0")); - test(udpEndpoint.mcastTtl() == 5); - test(udpEndpoint.timeout() == -1); - test(!udpEndpoint.compress()); - - test(endps[2] instanceof Ice.OpaqueEndpoint); + test(endps[0].getInfo() instanceof Ice.TcpEndpointInfo); + Ice.TcpEndpointInfo tcpEndpoint = (Ice.TcpEndpointInfo)endps[0].getInfo(); + test(tcpEndpoint.host.equals("tcphost")); + test(tcpEndpoint.port == 10000); + test(tcpEndpoint.timeout == 1200); + test(tcpEndpoint.compress); + + test(endps[1].getInfo() instanceof Ice.UdpEndpointInfo); + Ice.UdpEndpointInfo udpEndpoint = (Ice.UdpEndpointInfo)endps[1].getInfo(); + test(udpEndpoint.host.equals("udphost")); + test(udpEndpoint.port == 10001); + test(udpEndpoint.mcastInterface.equals("eth0")); + test(udpEndpoint.mcastTtl == 5); + test(udpEndpoint.timeout == -1); + test(!udpEndpoint.compress); + + test(endps[2].getInfo() instanceof Ice.OpaqueEndpointInfo); out.println("ok"); |