summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/include/Ice/Protocol.h27
-rw-r--r--cpp/src/Ice/Outgoing.cpp4
-rw-r--r--cpp/src/Ice/OutgoingAsync.cpp4
-rw-r--r--cpp/src/Ice/ReferenceFactory.cpp31
-rw-r--r--cpp/src/Ice/UdpEndpointI.cpp28
-rw-r--r--cpp/test/Ice/proxy/AllTests.cpp94
-rw-r--r--cs/src/Ice/Outgoing.cs8
-rw-r--r--cs/src/Ice/OutgoingAsync.cs4
-rw-r--r--cs/src/Ice/Protocol.cs27
-rw-r--r--cs/src/Ice/ReferenceFactory.cs27
-rw-r--r--cs/src/Ice/UdpEndpointI.cs28
-rw-r--r--cs/test/Ice/proxy/AllTests.cs99
-rw-r--r--java/src/IceInternal/Outgoing.java8
-rw-r--r--java/src/IceInternal/OutgoingAsync.java4
-rw-r--r--java/src/IceInternal/Protocol.java27
-rw-r--r--java/src/IceInternal/ReferenceFactory.java26
-rw-r--r--java/src/IceInternal/UdpEndpointI.java28
-rw-r--r--java/test/Ice/proxy/AllTests.java93
18 files changed, 354 insertions, 213 deletions
diff --git a/cpp/include/Ice/Protocol.h b/cpp/include/Ice/Protocol.h
index 8470a4549d4..4ea8f2062e2 100644
--- a/cpp/include/Ice/Protocol.h
+++ b/cpp/include/Ice/Protocol.h
@@ -188,11 +188,36 @@ checkSupportedEncoding(const Ice::EncodingVersion& v)
}
//
+// Either return the given protocol if not compatible, or the greatest
+// supported protocol otherwise.
+//
+inline const Ice::ProtocolVersion
+getCompatibleProtocol(const Ice::ProtocolVersion& v)
+{
+ if(v.major != Ice::currentProtocol.major)
+ {
+ return v; // Unsupported protocol, return as is.
+ }
+ else if(v.minor < Ice::currentProtocol.minor)
+ {
+ return v; // Supported protocol.
+ }
+ else
+ {
+ //
+ // Unsupported but compatible, use the currently supported
+ // protocol, that's the best we can do.
+ //
+ return Ice::currentProtocol;
+ }
+}
+
+//
// Either return the given encoding if not compatible, or the greatest
// supported encoding otherwise.
//
inline const Ice::EncodingVersion&
-checkForCompatibleEncoding(const Ice::EncodingVersion& v)
+getCompatibleEncoding(const Ice::EncodingVersion& v)
{
if(v.major != Ice::currentEncoding.major)
{
diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp
index 51f41bedd2b..acd4856aace 100644
--- a/cpp/src/Ice/Outgoing.cpp
+++ b/cpp/src/Ice/Outgoing.cpp
@@ -87,12 +87,12 @@ IceInternal::Outgoing::Outgoing(RequestHandler* handler, const string& operation
_handler(handler),
_observer(observer),
_state(StateUnsent),
- _encoding(checkForCompatibleEncoding(handler->getReference()->getEncoding())),
+ _encoding(getCompatibleEncoding(handler->getReference()->getEncoding())),
_is(handler->getReference()->getInstance().get(), Ice::currentProtocolEncoding),
_os(handler->getReference()->getInstance().get(), Ice::currentProtocolEncoding),
_sent(false)
{
- checkSupportedProtocol(handler->getReference()->getProtocol());
+ checkSupportedProtocol(getCompatibleProtocol(handler->getReference()->getProtocol()));
switch(_handler->getReference()->getMode())
{
diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp
index 04e9eabdc02..9d15133ad8a 100644
--- a/cpp/src/Ice/OutgoingAsync.cpp
+++ b/cpp/src/Ice/OutgoingAsync.cpp
@@ -426,7 +426,7 @@ IceInternal::OutgoingAsync::OutgoingAsync(const ObjectPrx& prx,
const Ice::LocalObjectPtr& cookie) :
AsyncResult(prx->ice_getCommunicator(), prx->__reference()->getInstance(), operation, delegate, cookie),
_proxy(prx),
- _encoding(checkForCompatibleEncoding(prx->__reference()->getEncoding()))
+ _encoding(getCompatibleEncoding(prx->__reference()->getEncoding()))
{
}
@@ -438,7 +438,7 @@ IceInternal::OutgoingAsync::__prepare(const std::string& operation, OperationMod
_mode = mode;
_sentSynchronously = false;
- checkSupportedProtocol(_proxy->__reference()->getProtocol());
+ checkSupportedProtocol(getCompatibleProtocol(_proxy->__reference()->getProtocol()));
_observer.attach(_proxy.get(), operation, context);
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp
index b4193f3a374..57c01f213bf 100644
--- a/cpp/src/Ice/ReferenceFactory.cpp
+++ b/cpp/src/Ice/ReferenceFactory.cpp
@@ -190,6 +190,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
Reference::Mode mode = Reference::ModeTwoway;
bool secure = false;
Ice::EncodingVersion encoding = _instance->defaultsAndOverrides()->defaultEncoding;
+ Ice::ProtocolVersion protocol = Protocol_1_0;
string adapter;
while(true)
@@ -372,7 +373,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
throw ex;
}
- try
+ try
{
encoding = Ice::stringToEncodingVersion(argument);
}
@@ -385,6 +386,28 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
break;
}
+ case 'p':
+ {
+ if(argument.empty())
+ {
+ Ice::ProxyParseException ex(__FILE__, __LINE__);
+ ex.str = "no argument provided for -p option in `" + s + "'";
+ throw ex;
+ }
+
+ try
+ {
+ protocol = Ice::stringToProtocolVersion(argument);
+ }
+ catch(const Ice::VersionParseException& e)
+ {
+ Ice::ProxyParseException ex(__FILE__, __LINE__);
+ ex.str = "invalid protocol version `" + argument + "' in `" + s + "':\n" + e.str;
+ throw ex;
+ }
+ break;
+ }
+
default:
{
ProxyParseException ex(__FILE__, __LINE__);
@@ -396,7 +419,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
if(beg == string::npos)
{
- return create(ident, facet, mode, secure, Protocol_1_0, encoding, vector<EndpointIPtr>(), "", propertyPrefix);
+ return create(ident, facet, mode, secure, protocol, encoding, vector<EndpointIPtr>(), "", propertyPrefix);
}
vector<EndpointIPtr> endpoints;
@@ -484,7 +507,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
}
}
- return create(ident, facet, mode, secure, Protocol_1_0, encoding, endpoints, "", propertyPrefix);
+ return create(ident, facet, mode, secure, protocol, encoding, endpoints, "", propertyPrefix);
break;
}
case '@':
@@ -548,7 +571,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP
adapter = Ice::UTF8ToNative(_instance->initializationData().stringConverter, adapter);
- return create(ident, facet, mode, secure, Protocol_1_0, encoding, endpoints, adapter, propertyPrefix);
+ return create(ident, facet, mode, secure, protocol, encoding, endpoints, adapter, propertyPrefix);
break;
}
default:
diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp
index 8d812e591dc..87cb12aafee 100644
--- a/cpp/src/Ice/UdpEndpointI.cpp
+++ b/cpp/src/Ice/UdpEndpointI.cpp
@@ -157,13 +157,29 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin
}
const_cast<bool&>(_compress) = true;
}
- else if(option == "-v")
+ else if(option == "-v" || option == "-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.empty())
+ {
+ EndpointParseException ex(__FILE__, __LINE__);
+ ex.str = "no argument provided for " + option + " option in endpoint `udp " + str + "'";
+ throw ex;
+ }
+ try
+ {
+ Ice::Byte major, minor;
+ IceInternal::stringToMajorMinor(argument, major, minor);
+ if(major != 1 || minor != 0)
+ {
+ _instance->initializationData().logger->warning("deprecated udp endpoint option: " + option);
+ }
+ }
+ catch(const VersionParseException& e)
+ {
+ EndpointParseException ex(__FILE__, __LINE__);
+ ex.str = "invalid version `" + argument + "' in endpoint `udp " + str + "':\n" + e.str;
+ throw ex;
+ }
}
else if(option == "--interface")
{
diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp
index 8715475f4a4..e9eba2918d4 100644
--- a/cpp/test/Ice/proxy/AllTests.cpp
+++ b/cpp/test/Ice/proxy/AllTests.cpp
@@ -220,6 +220,12 @@ allTests(const Ice::CommunicatorPtr& communicator)
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->ice_toString() == "test -t");
+
+ b1 = communicator->stringToProxy("test -p 6.5 -e 1.0");
+ test(b1->ice_toString() == "test -t -p 6.5");
+
try
{
b1 = communicator->stringToProxy("test:tcp@adapterId");
@@ -623,61 +629,6 @@ allTests(const Ice::CommunicatorPtr& communicator)
cout << "ok" << endl;
- cout << "testing protocol versioning... " << flush;
- {
- Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
- out->write(cl);
- vector<Ice::Byte> inBytes;
- out->finished(inBytes);
-
- // Protocol version 1.1
- inBytes[9] = 1;
- inBytes[10] = 1;
-
- Ice::InputStreamPtr in = Ice::createInputStream(communicator, inBytes);
- Test::MyClassPrx cl11;
- in->read(cl11);
- cl11 = cl11->ice_collocationOptimized(false);
- if(communicator->getProperties()->getPropertyAsInt("Ice.IPv6") == 0)
- {
- string protocol = communicator->getProperties()->getPropertyWithDefault("Ice.Default.Protocol", "tcp");
- test(cl11->ice_toString() == "test -t -p 1.1 -e 1.1:" + protocol + " -h 127.0.0.1 -p 12010");
- }
- try
- {
- cl11->ice_ping();
- test(false);
- }
- catch(const Ice::UnsupportedProtocolException&)
- {
- }
- try
- {
- cl11->end_ice_ping(cl11->begin_ice_ping());
- test(false);
- }
- catch(const Ice::UnsupportedProtocolException&)
- {
- }
- try
- {
- cl11->ice_flushBatchRequests();
- test(false);
- }
- catch(const Ice::UnsupportedProtocolException&)
- {
- }
- try
- {
- cl11->end_ice_flushBatchRequests(cl11->begin_ice_flushBatchRequests());
- test(false);
- }
- catch(const Ice::UnsupportedProtocolException&)
- {
- }
- }
- cout << "ok" << endl;
-
cout << "testing encoding versioning... " << flush;
string ref20 = "test -e 2.0:default -p 12010";
Test::MyClassPrx cl20 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref20));
@@ -754,6 +705,39 @@ allTests(const Ice::CommunicatorPtr& communicator)
cout << "ok" << endl;
+ cout << "testing protocol versioning... " << flush;
+
+ ref20 = "test -p 2.0:default -p 12010";
+ cl20 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref20));
+ try
+ {
+ cl20->ice_collocationOptimized(false)->ice_ping();
+ test(false);
+ }
+ catch(const Ice::UnsupportedProtocolException&)
+ {
+ // Server 2.0 proxy doesn't support 1.0 version.
+ }
+
+ ref10 = "test -p 1.0:default -p 12010";
+ cl10 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref10));
+ cl10->ice_ping();
+
+ // 1.3 isn't supported but since a 1.3 proxy supports 1.0, the
+ // call will use the 1.0 encoding
+ ref13 = "test -p 1.3:default -p 12010";
+ cl13 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref13));
+ cl13->ice_ping();
+ try
+ {
+ cl13->end_ice_ping(cl13->begin_ice_ping());
+ }
+ catch(const Ice::CollocationOptimizationException&)
+ {
+ }
+
+ cout << "ok" <<endl;
+
cout << "testing opaque endpoints... " << flush;
try
diff --git a/cs/src/Ice/Outgoing.cs b/cs/src/Ice/Outgoing.cs
index 6a8e32b86e8..0071c17d87f 100644
--- a/cs/src/Ice/Outgoing.cs
+++ b/cs/src/Ice/Outgoing.cs
@@ -30,10 +30,10 @@ namespace IceInternal
_sent = false;
_handler = handler;
_observer = observer;
- _encoding = Protocol.checkForCompatibleEncoding(handler.getReference().getEncoding());
+ _encoding = Protocol.getCompatibleEncoding(handler.getReference().getEncoding());
_os = new BasicStream(_handler.getReference().getInstance(), Ice.Util.currentProtocolEncoding);
- Protocol.checkSupportedProtocol(_handler.getReference().getProtocol());
+ Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(_handler.getReference().getProtocol()));
writeHeader(operation, mode, context);
}
@@ -49,9 +49,9 @@ namespace IceInternal
_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/cs/src/Ice/OutgoingAsync.cs b/cs/src/Ice/OutgoingAsync.cs
index 609819e20e0..01d0a54c711 100644
--- a/cs/src/Ice/OutgoingAsync.cs
+++ b/cs/src/Ice/OutgoingAsync.cs
@@ -798,7 +798,7 @@ namespace IceInternal
cookie)
{
proxy_ = (Ice.ObjectPrxHelperBase)prx;
- _encoding = Protocol.checkForCompatibleEncoding(proxy_.reference__().getEncoding());
+ _encoding = Protocol.getCompatibleEncoding(proxy_.reference__().getEncoding());
}
public void prepare__(string operation, Ice.OperationMode mode, Dictionary<string, string> context,
@@ -809,7 +809,7 @@ namespace IceInternal
_mode = mode;
sentSynchronously_ = false;
- Protocol.checkSupportedProtocol(proxy_.reference__().getProtocol());
+ Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(proxy_.reference__().getProtocol()));
if(explicitContext && context == null)
{
diff --git a/cs/src/Ice/Protocol.cs b/cs/src/Ice/Protocol.cs
index 6dd4b1cf9d2..c62eb2ffbd4 100644
--- a/cs/src/Ice/Protocol.cs
+++ b/cs/src/Ice/Protocol.cs
@@ -115,11 +115,36 @@ namespace IceInternal
}
//
+ // Either return the given protocol if not compatible, or the greatest
+ // supported protocol otherwise.
+ //
+ internal static Ice.ProtocolVersion
+ getCompatibleProtocol(Ice.ProtocolVersion v)
+ {
+ if(v.major != Ice.Util.currentProtocol.major)
+ {
+ return v; // Unsupported protocol, return as is.
+ }
+ else if(v.minor < Ice.Util.currentProtocol.minor)
+ {
+ return v; // Supported protocol.
+ }
+ else
+ {
+ //
+ // Unsupported but compatible, use the currently supported
+ // protocol, that's the best we can do.
+ //
+ return Ice.Util.currentProtocol;
+ }
+ }
+
+ //
// Either return the given encoding if not compatible, or the greatest
// supported encoding otherwise.
//
internal static Ice.EncodingVersion
- checkForCompatibleEncoding(Ice.EncodingVersion v)
+ getCompatibleEncoding(Ice.EncodingVersion v)
{
if(v.major != Ice.Util.currentEncoding.major)
{
diff --git a/cs/src/Ice/ReferenceFactory.cs b/cs/src/Ice/ReferenceFactory.cs
index d27045d0572..421bbdcd115 100644
--- a/cs/src/Ice/ReferenceFactory.cs
+++ b/cs/src/Ice/ReferenceFactory.cs
@@ -171,6 +171,7 @@ namespace IceInternal
Reference.Mode mode = Reference.Mode.ModeTwoway;
bool secure = false;
Ice.EncodingVersion encoding = instance_.defaultsAndOverrides().defaultEncoding;
+ Ice.ProtocolVersion protocol = Ice.Util.Protocol_1_0;
string adapter = "";
while(true)
@@ -362,6 +363,25 @@ namespace IceInternal
break;
}
+ case 'p':
+ {
+ if(argument == null)
+ {
+ throw new Ice.ProxyParseException("no argument provided for -p option `" + 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();
@@ -373,7 +393,7 @@ namespace IceInternal
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);
}
List<EndpointI> endpoints = new List<EndpointI>();
@@ -464,7 +484,7 @@ namespace IceInternal
}
EndpointI[] ep = endpoints.ToArray();
- return create(ident, facet, mode, secure, Ice.Util.Protocol_1_0, encoding, ep, null, propertyPrefix);
+ return create(ident, facet, mode, secure, protocol, encoding, ep, null, propertyPrefix);
}
else if(s[beg] == '@')
{
@@ -523,8 +543,7 @@ namespace IceInternal
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/cs/src/Ice/UdpEndpointI.cs b/cs/src/Ice/UdpEndpointI.cs
index 9038ad81e4f..d69179c4fd4 100644
--- a/cs/src/Ice/UdpEndpointI.cs
+++ b/cs/src/Ice/UdpEndpointI.cs
@@ -162,13 +162,29 @@ namespace IceInternal
_compress = true;
}
- 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)
+ {
+ Ice.EndpointParseException e = new Ice.EndpointParseException();
+ e.str = "no argument provided for " + option + " option in endpoint " + "`udp " + str + "'";
+ throw e;
+ }
+
+ 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 ex)
+ {
+ Ice.EndpointParseException e = new Ice.EndpointParseException();
+ e.str = "invalid version `" + argument + "' in endpoint `udp " + str + "':\n" + ex.str;
+ throw e;
+ }
}
else if(option.Equals("--interface"))
{
diff --git a/cs/test/Ice/proxy/AllTests.cs b/cs/test/Ice/proxy/AllTests.cs
index aa4446aa611..a74b64ae13c 100644
--- a/cs/test/Ice/proxy/AllTests.cs
+++ b/cs/test/Ice/proxy/AllTests.cs
@@ -219,6 +219,20 @@ public class AllTests : TestCommon.TestApp
b1 = communicator.stringToProxy("test -s");
test(b1.ice_isSecure());
+ test(b1.ice_getEncodingVersion().Equals(Ice.Util.currentEncoding));
+
+ b1 = communicator.stringToProxy("test -e 1.0");
+ test(b1.ice_getEncodingVersion().major == 1 && b1.ice_getEncodingVersion().minor == 0);
+
+ 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");
@@ -540,59 +554,6 @@ public class AllTests : TestCommon.TestApp
test(Ice.CollectionComparer.Equals(c, c2));
WriteLine("ok");
- Write("testing protocol versioning... ");
- 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);
- Test.MyClassPrx cl11 = Test.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"));
- }
- try
- {
- cl11.ice_ping();
- test(false);
- }
- catch(Ice.UnsupportedProtocolException)
- {
- }
- try
- {
- cl11.end_ice_ping(cl11.begin_ice_ping());
- test(false);
- }
- catch(Ice.UnsupportedProtocolException)
- {
- }
- try
- {
- cl11.ice_flushBatchRequests();
- test(false);
- }
- catch(Ice.UnsupportedProtocolException)
- {
- }
- try
- {
- cl11.end_ice_flushBatchRequests(cl11.begin_ice_flushBatchRequests());
- test(false);
- }
- catch(Ice.UnsupportedProtocolException)
- {
- }
- }
- WriteLine("ok");
-
Write("testing encoding versioning... ");
Flush();
string ref20 = "test -e 2.0:default -p 12010";
@@ -670,6 +631,38 @@ public class AllTests : TestCommon.TestApp
WriteLine("ok");
+ Write("testing protocol versioning... ");
+ Flush();
+ ref20 = "test -p 2.0:default -p 12010";
+ cl20 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref20));
+ try
+ {
+ cl20.ice_collocationOptimized(false).ice_ping();
+ test(false);
+ }
+ catch(Ice.UnsupportedProtocolException)
+ {
+ // Server 2.0 proxy doesn't support 1.0 version.
+ }
+
+ ref10 = "test -p 1.0:default -p 12010";
+ cl10 = Test.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 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13));
+ cl13.ice_ping();
+ try
+ {
+ cl13.end_ice_ping(cl13.begin_ice_ping());
+ }
+ catch(Ice.CollocationOptimizationException)
+ {
+ }
+ WriteLine("ok");
+
Write("testing opaque endpoints... ");
Flush();
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();