diff options
author | Benoit Foucher <benoit@zeroc.com> | 2013-01-15 18:46:12 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2013-01-15 18:46:12 +0100 |
commit | f561241d76b7a3d58a8652a8ae6642361f6d596b (patch) | |
tree | 06602625807c74e6476043eee42f304e15609592 /java | |
parent | Fixed(ICE-5184) -IceGridGUI will not allow me to enter port in connection cre... (diff) | |
download | ice-f561241d76b7a3d58a8652a8ae6642361f6d596b.tar.bz2 ice-f561241d76b7a3d58a8652a8ae6642361f6d596b.tar.xz ice-f561241d76b7a3d58a8652a8ae6642361f6d596b.zip |
Fixed ICE-5131 - parsing of -p <version> for proxies, tweaked UDP endpoint deprecation warning for -v/-e
Diffstat (limited to 'java')
-rw-r--r-- | java/src/IceInternal/Outgoing.java | 8 | ||||
-rw-r--r-- | java/src/IceInternal/OutgoingAsync.java | 4 | ||||
-rw-r--r-- | java/src/IceInternal/Protocol.java | 27 | ||||
-rw-r--r-- | java/src/IceInternal/ReferenceFactory.java | 26 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpointI.java | 28 | ||||
-rw-r--r-- | java/test/Ice/proxy/AllTests.java | 93 |
6 files changed, 113 insertions, 73 deletions
diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java index b176fed16df..903cf328384 100644 --- a/java/src/IceInternal/Outgoing.java +++ b/java/src/IceInternal/Outgoing.java @@ -23,10 +23,10 @@ public final class Outgoing implements OutgoingMessageCallback _sent = false; _handler = handler; _observer = observer; - _encoding = Protocol.checkForCompatibleEncoding(handler.getReference().getEncoding()); + _encoding = Protocol.getCompatibleEncoding(handler.getReference().getEncoding()); _os = new BasicStream(_handler.getReference().getInstance(), Protocol.currentProtocolEncoding); - Protocol.checkSupportedProtocol(_handler.getReference().getProtocol()); + Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(_handler.getReference().getProtocol())); writeHeader(operation, mode, context); } @@ -44,9 +44,9 @@ public final class Outgoing implements OutgoingMessageCallback _sent = false; _handler = handler; _observer = observer; - _encoding = Protocol.checkForCompatibleEncoding(handler.getReference().getEncoding()); + _encoding = Protocol.getCompatibleEncoding(handler.getReference().getEncoding()); - Protocol.checkSupportedProtocol(_handler.getReference().getProtocol()); + Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(_handler.getReference().getProtocol())); writeHeader(operation, mode, context); } diff --git a/java/src/IceInternal/OutgoingAsync.java b/java/src/IceInternal/OutgoingAsync.java index 7e89ec96058..f65f1aa221d 100644 --- a/java/src/IceInternal/OutgoingAsync.java +++ b/java/src/IceInternal/OutgoingAsync.java @@ -15,7 +15,7 @@ public class OutgoingAsync extends Ice.AsyncResult implements OutgoingAsyncMessa { super(prx.ice_getCommunicator(), ((Ice.ObjectPrxHelperBase)prx).__reference().getInstance(), operation, cb); _proxy = (Ice.ObjectPrxHelperBase)prx; - _encoding = Protocol.checkForCompatibleEncoding(_proxy.__reference().getEncoding()); + _encoding = Protocol.getCompatibleEncoding(_proxy.__reference().getEncoding()); } public void __prepare(String operation, Ice.OperationMode mode, java.util.Map<String, String> ctx, @@ -26,7 +26,7 @@ public class OutgoingAsync extends Ice.AsyncResult implements OutgoingAsyncMessa _mode = mode; _sentSynchronously = false; - Protocol.checkSupportedProtocol(_proxy.__reference().getProtocol()); + Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(_proxy.__reference().getProtocol())); if(explicitCtx && ctx == null) { diff --git a/java/src/IceInternal/Protocol.java b/java/src/IceInternal/Protocol.java index e1e88ce3511..e90a33bd64a 100644 --- a/java/src/IceInternal/Protocol.java +++ b/java/src/IceInternal/Protocol.java @@ -131,11 +131,36 @@ final public class Protocol } // + // Either return the given protocol if not compatible, or the greatest + // supported protocol otherwise. + // + static public Ice.ProtocolVersion + getCompatibleProtocol(Ice.ProtocolVersion v) + { + if(v.major != currentProtocol.major) + { + return v; // Unsupported protocol, return as is. + } + else if(v.minor < currentProtocol.minor) + { + return v; // Supported protocol. + } + else + { + // + // Unsupported but compatible, use the currently supported + // protocol, that's the best we can do. + // + return currentProtocol; + } + } + + // // Either return the given encoding if not compatible, or the greatest // supported encoding otherwise. // static public Ice.EncodingVersion - checkForCompatibleEncoding(Ice.EncodingVersion v) + getCompatibleEncoding(Ice.EncodingVersion v) { if(v.major != currentEncoding.major) { diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java index 16283cf3dbd..b418ec5d80e 100644 --- a/java/src/IceInternal/ReferenceFactory.java +++ b/java/src/IceInternal/ReferenceFactory.java @@ -164,6 +164,7 @@ public final class ReferenceFactory int mode = Reference.ModeTwoway; boolean secure = false; Ice.EncodingVersion encoding = _instance.defaultsAndOverrides().defaultEncoding; + Ice.ProtocolVersion protocol = Ice.Util.Protocol_1_0; String adapter = ""; while(true) @@ -356,6 +357,25 @@ public final class ReferenceFactory break; } + case 'p': + { + if(argument == null) + { + throw new Ice.ProxyParseException("no argument provided for -p option in `" + s + "'"); + } + + try + { + protocol = Ice.Util.stringToProtocolVersion(argument); + } + catch(Ice.VersionParseException e) + { + throw new Ice.ProxyParseException("invalid protocol version `" + argument + "' in `" + s + + "':\n" + e.str); + } + break; + } + default: { Ice.ProxyParseException e = new Ice.ProxyParseException(); @@ -367,7 +387,7 @@ public final class ReferenceFactory if(beg == -1) { - return create(ident, facet, mode, secure, Ice.Util.Protocol_1_0, encoding, null, null, propertyPrefix); + return create(ident, facet, mode, secure, protocol, encoding, null, null, propertyPrefix); } java.util.ArrayList<EndpointI> endpoints = new java.util.ArrayList<EndpointI>(); @@ -457,7 +477,7 @@ public final class ReferenceFactory EndpointI[] endp = new EndpointI[endpoints.size()]; endpoints.toArray(endp); - return create(ident, facet, mode, secure, Ice.Util.Protocol_1_0, encoding, endp, null, propertyPrefix); + return create(ident, facet, mode, secure, protocol, encoding, endp, null, propertyPrefix); } else if(s.charAt(beg) == '@') { @@ -516,7 +536,7 @@ public final class ReferenceFactory e.str = "empty adapter id in `" + s + "'"; throw e; } - return create(ident, facet, mode, secure, Ice.Util.Protocol_1_0, encoding, null, adapter, propertyPrefix); + return create(ident, facet, mode, secure, protocol, encoding, null, adapter, propertyPrefix); } Ice.ProxyParseException ex = new Ice.ProxyParseException(); diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index 2398fc43c98..151c6b13599 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -106,7 +106,6 @@ final class UdpEndpointI extends EndpointI } _connect = true; - break; } else if(option.equals("-z")) { @@ -117,15 +116,28 @@ final class UdpEndpointI extends EndpointI } _compress = true; - break; } - else if(option == "-v") + else if(option.equals("-v") || option.equals("-e")) { - _instance.initializationData().logger.warning("deprecated udp endpoint option: -v"); - } - else if(option == "-e") - { - _instance.initializationData().logger.warning("deprecated udp endpoint option: -e"); + if(argument == null) + { + throw new Ice.EndpointParseException("no argument provided for " + option + " option in endpoint " + + "`udp " + str + "'"); + } + + try + { + Ice.EncodingVersion v = Ice.Util.stringToEncodingVersion(argument); + if(v.major != 1 || v.minor != 0) + { + _instance.initializationData().logger.warning("deprecated udp endpoint option: " + option); + } + } + catch(Ice.VersionParseException e) + { + throw new Ice.EndpointParseException("invalid version `" + argument + "' in endpoint `udp " + + str + "':\n" + e.str); + } } else if(option.equals("--interface")) { diff --git a/java/test/Ice/proxy/AllTests.java b/java/test/Ice/proxy/AllTests.java index 601f75be495..809d3f9c0b6 100644 --- a/java/test/Ice/proxy/AllTests.java +++ b/java/test/Ice/proxy/AllTests.java @@ -233,6 +233,12 @@ public class AllTests b1 = communicator.stringToProxy("test -e 6.5"); test(b1.ice_getEncodingVersion().major == 6 && b1.ice_getEncodingVersion().minor == 5); + b1 = communicator.stringToProxy("test -p 1.0 -e 1.0"); + test(b1.toString().equals("test -t")); + + b1 = communicator.stringToProxy("test -p 6.5 -e 1.0"); + test(b1.toString().equals("test -t -p 6.5")); + try { b1 = communicator.stringToProxy("test:tcp@adapterId"); @@ -559,61 +565,6 @@ public class AllTests test(c.equals(c2)); out.println("ok"); - out.print("testing protocol versioning... "); - out.flush(); - { - Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); - outS.writeProxy(cl); - byte[] inBytes = outS.finished(); - - // Protocol version 1.1 - inBytes[9] = 1; - inBytes[10] = 1; - - Ice.InputStream inS = Ice.Util.createInputStream(communicator, inBytes); - MyClassPrx cl11 = MyClassPrxHelper.uncheckedCast(inS.readProxy().ice_collocationOptimized(false)); - if(communicator.getProperties().getPropertyAsInt("Ice.IPv6") == 0) - { - String protocol = communicator.getProperties().getPropertyWithDefault("Ice.Default.Protocol", "tcp"); - test(cl11.toString().equals("test -t -p 1.1 -e 1.1:" + protocol + " -h 127.0.0.1 -p 12010") || - // Android doesn't set Ice.DefaultHost to 127.0.0.1 - cl11.toString().equals("test -t -p 1.1 -e 1.1:" + protocol + " -p 12010")); - } - try - { - cl11.ice_ping(); - test(false); - } - catch(Ice.UnsupportedProtocolException ex) - { - } - try - { - cl11.end_ice_ping(cl11.begin_ice_ping()); - test(false); - } - catch(Ice.UnsupportedProtocolException ex) - { - } - try - { - cl11.ice_flushBatchRequests(); - test(false); - } - catch(Ice.UnsupportedProtocolException ex) - { - } - try - { - cl11.end_ice_flushBatchRequests(cl11.begin_ice_flushBatchRequests()); - test(false); - } - catch(Ice.UnsupportedProtocolException ex) - { - } - } - out.println("ok"); - out.print("testing encoding versioning... "); out.flush(); String ref20 = "test -e 2.0:default -p 12010"; @@ -689,6 +640,38 @@ public class AllTests out.println("ok"); + out.print("testing protocol versioning... "); + out.flush(); + ref20 = "test -p 2.0:default -p 12010"; + cl20 = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref20)); + try + { + cl20.ice_collocationOptimized(false).ice_ping(); + test(false); + } + catch(Ice.UnsupportedProtocolException ex) + { + // Server 2.0 proxy doesn't support 1.0 version. + } + + ref10 = "test -p 1.0:default -p 12010"; + cl10 = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10)); + cl10.ice_ping(); + + // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the + // call will use the 1.1 protocol + ref13 = "test -p 1.3:default -p 12010"; + cl13 = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13)); + cl13.ice_ping(); + try + { + cl13.end_ice_ping(cl13.begin_ice_ping()); + } + catch(Ice.CollocationOptimizationException ex) + { + } + out.println("ok"); + out.print("testing opaque endpoints... "); out.flush(); |