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/src | |
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/src')
-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 |
11 files changed, 214 insertions, 79 deletions
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; } |