diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-04-27 13:05:25 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-04-27 13:05:25 +0200 |
commit | c5ee6fd5310199110dae6b2d01decbd20174d8db (patch) | |
tree | daf558482821eb3a1ffd496b06ba8bcc2edce841 /java/src | |
parent | Extra whitespace (diff) | |
download | ice-c5ee6fd5310199110dae6b2d01decbd20174d8db.tar.bz2 ice-c5ee6fd5310199110dae6b2d01decbd20174d8db.tar.xz ice-c5ee6fd5310199110dae6b2d01decbd20174d8db.zip |
Fixed ICE-6680 - WS transports are now provided by a separate IceWS plugin
Diffstat (limited to 'java/src')
13 files changed, 267 insertions, 129 deletions
diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactory.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactory.java index 985875e7be6..b4de848e3f9 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactory.java @@ -11,11 +11,16 @@ package com.zeroc.IceInternal; public interface EndpointFactory { + default void initialize() + { + // Nothing to do, can be overriden by specialization to finish initialization. + } + short type(); String protocol(); EndpointI create(java.util.ArrayList<String> args, boolean oaEndpoint); EndpointI read(com.zeroc.Ice.InputStream s); void destroy(); - EndpointFactory clone(ProtocolInstance instance, EndpointFactory delegate); + EndpointFactory clone(ProtocolInstance instance); } diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryManager.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryManager.java index e3646c311db..5ecf681e547 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryManager.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryManager.java @@ -16,11 +16,18 @@ public final class EndpointFactoryManager _instance = instance; } + public void initialize() + { + for(EndpointFactory f : _factories) + { + f.initialize(); + } + } + public synchronized void add(EndpointFactory factory) { - for(int i = 0; i < _factories.size(); i++) + for(EndpointFactory f : _factories) { - EndpointFactory f = _factories.get(i); if(f.type() == factory.type()) { assert(false); @@ -31,9 +38,8 @@ public final class EndpointFactoryManager public synchronized EndpointFactory get(short type) { - for(int i = 0; i < _factories.size(); i++) + for(EndpointFactory f : _factories) { - EndpointFactory f = _factories.get(i); if(f.type() == type) { return f; @@ -70,9 +76,8 @@ public final class EndpointFactoryManager EndpointFactory factory = null; - for(int i = 0; i < _factories.size(); i++) + for(EndpointFactory f : _factories) { - EndpointFactory f = _factories.get(i); if(f.protocol().equals(protocol)) { factory = f; @@ -159,7 +164,13 @@ public final class EndpointFactoryManager { e = factory.read(s); } - else + // + // If the factory failed to read the endpoint, return an opaque endpoint. This can + // occur if for example the factory delegates to another factory and this factory + // isn't available. In this case, the factory needs to make sure the stream position + // is preserved for reading the opaque endpoint. + // + if(e == null) { e = new OpaqueEndpointI(type, s); } @@ -171,9 +182,8 @@ public final class EndpointFactoryManager void destroy() { - for(int i = 0; i < _factories.size(); i++) + for(EndpointFactory f : _factories) { - EndpointFactory f = _factories.get(i); f.destroy(); } _factories.clear(); diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryWithUnderlying.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryWithUnderlying.java new file mode 100644 index 00000000000..747c38d7f37 --- /dev/null +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/EndpointFactoryWithUnderlying.java @@ -0,0 +1,92 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package com.zeroc.IceInternal; + +// +// The endpoint factory with underlying create endpoints that delegate to an underlying +// endpoint (e.g.: the SSL/WS endpoints are endpoints with underlying endpoints). +// +abstract public class EndpointFactoryWithUnderlying implements EndpointFactory +{ + public EndpointFactoryWithUnderlying(ProtocolInstance instance, short type) + { + _instance = instance; + _type = type; + } + + public void initialize() + { + // + // Get the endpoint factory for the underlying type and clone it with + // our protocol instance. + // + EndpointFactory factory = _instance.getEndpointFactory(_type); + if(factory != null) + { + _underlying = factory.clone(_instance); + _underlying.initialize(); + } + } + + public short type() + { + return _instance.type(); + } + + public String protocol() + { + return _instance.protocol(); + } + + public EndpointI create(java.util.ArrayList<String> args, boolean oaEndpoint) + { + if(_underlying == null) + { + return null; // Can't create an endpoint without underlying factory. + } + return createWithUnderlying(_underlying.create(args, oaEndpoint), args, oaEndpoint); + } + + public EndpointI read(com.zeroc.Ice.InputStream s) + { + if(_underlying == null) + { + return null; // Can't create an endpoint without underlying factory. + } + return readWithUnderlying(_underlying.read(s), s); + } + + public void destroy() + { + if(_underlying != null) + { + _underlying.destroy(); + } + _instance = null; + } + + public EndpointFactory clone(ProtocolInstance instance) + { + return cloneWithUnderlying(instance, _type); + } + + abstract public EndpointFactory cloneWithUnderlying(ProtocolInstance instance, short type); + + abstract protected EndpointI createWithUnderlying(EndpointI underlying, + java.util.ArrayList<String> args, + boolean oaEndpoint); + + abstract protected EndpointI readWithUnderlying(EndpointI underlying, com.zeroc.Ice.InputStream s); + + protected ProtocolInstance _instance; + + private final short _type; + private EndpointFactory _underlying; +}
\ No newline at end of file diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java index 75965e551b8..56f062d292a 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java @@ -1101,13 +1101,17 @@ public final class Instance implements java.util.function.Function<String, Class _endpointFactoryManager = new EndpointFactoryManager(this); - ProtocolInstance tcpProtocolInstance = - new ProtocolInstance(this, com.zeroc.Ice.TCPEndpointType.value, "tcp", false); - _endpointFactoryManager.add(new TcpEndpointFactory(tcpProtocolInstance)); + ProtocolInstance tcpProtocol = new ProtocolInstance(this, com.zeroc.Ice.TCPEndpointType.value, "tcp", false); + _endpointFactoryManager.add(new TcpEndpointFactory(tcpProtocol)); - ProtocolInstance udpProtocolInstance = - new ProtocolInstance(this, com.zeroc.Ice.UDPEndpointType.value, "udp", false); - _endpointFactoryManager.add(new UdpEndpointFactory(udpProtocolInstance)); + ProtocolInstance udpProtocol = new ProtocolInstance(this, com.zeroc.Ice.UDPEndpointType.value, "udp", false); + _endpointFactoryManager.add(new UdpEndpointFactory(udpProtocol)); + + ProtocolInstance wsProtocol = new ProtocolInstance(this, com.zeroc.Ice.WSEndpointType.value, "ws", false); + _endpointFactoryManager.add(new WSEndpointFactory(wsProtocol, com.zeroc.Ice.TCPEndpointType.value)); + + ProtocolInstance wssProtocol = new ProtocolInstance(this, com.zeroc.Ice.WSSEndpointType.value, "wss", true); + _endpointFactoryManager.add(new WSEndpointFactory(wssProtocol, com.zeroc.Ice.SSLEndpointType.value)); _pluginManager = new com.zeroc.Ice.PluginManagerI(communicator, this); @@ -1191,22 +1195,10 @@ public final class Instance implements java.util.function.Function<String, Class args = pluginManagerImpl.loadPlugins(args); // - // Add WS and WSS endpoint factories if TCP/SSL factories are installed. + // Initialize the endpoint factories once all the plugins are loaded. This gives + // the opportunity for the endpoint factories to find underyling factories. // - final EndpointFactory tcpFactory = _endpointFactoryManager.get(com.zeroc.Ice.TCPEndpointType.value); - if(tcpFactory != null) - { - final ProtocolInstance instance = - new ProtocolInstance(this, com.zeroc.Ice.WSEndpointType.value, "ws", false); - _endpointFactoryManager.add(new WSEndpointFactory(instance, tcpFactory.clone(instance, null))); - } - final EndpointFactory sslFactory = _endpointFactoryManager.get(com.zeroc.Ice.SSLEndpointType.value); - if(sslFactory != null) - { - final ProtocolInstance instance = - new ProtocolInstance(this, com.zeroc.Ice.WSSEndpointType.value, "wss", true); - _endpointFactoryManager.add(new WSEndpointFactory(instance, sslFactory.clone(instance, null))); - } + _endpointFactoryManager.initialize(); // // Create Admin facets, if enabled. diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/ProtocolInstance.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/ProtocolInstance.java index 7ec1c3022f5..d3c13d9ee35 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/ProtocolInstance.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/ProtocolInstance.java @@ -38,6 +38,11 @@ public class ProtocolInstance return _logger; } + public EndpointFactory getEndpointFactory(short type) + { + return _instance.endpointFactoryManager().get(type); + } + public String protocol() { return _protocol; diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/TcpEndpointFactory.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/TcpEndpointFactory.java index 1fa2907d43e..d4aa6740083 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/TcpEndpointFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/TcpEndpointFactory.java @@ -49,7 +49,7 @@ final class TcpEndpointFactory implements EndpointFactory } @Override - public EndpointFactory clone(ProtocolInstance instance, EndpointFactory delegate) + public EndpointFactory clone(ProtocolInstance instance) { return new TcpEndpointFactory(instance); } diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpEndpointFactory.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpEndpointFactory.java index e7b458e25a9..64cc4fb4a3f 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpEndpointFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UdpEndpointFactory.java @@ -49,7 +49,7 @@ final class UdpEndpointFactory implements EndpointFactory } @Override - public EndpointFactory clone(ProtocolInstance instance, EndpointFactory delegate) + public EndpointFactory clone(ProtocolInstance instance) { return new UdpEndpointFactory(instance); } diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/UnderlyingEndpointFactory.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UnderlyingEndpointFactory.java new file mode 100644 index 00000000000..6ed97724ddb --- /dev/null +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/UnderlyingEndpointFactory.java @@ -0,0 +1,90 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package com.zeroc.IceInternal; + +// +// The underlying endpoint factory creates endpoints with a factory of the given +// type. If this factory is of the EndpointFactoryWithUnderlying type, it will +// delegate to the given underlying factory (this is used by IceIAP/IceBT plugins +// for the BTS/iAPS endpoint factories). +// +public class UnderlyingEndpointFactory implements EndpointFactory +{ + public UnderlyingEndpointFactory(ProtocolInstance instance, short type, short underlying) + { + _instance = instance; + _type = type; + _underlying = underlying; + } + + public void initialize() + { + // + // Get the endpoint factory of the given endpoint type. If it's a factory that + // delegates to an underlying endpoint, clone it and instruct it to delegate to + // our underlying factory. + // + EndpointFactory factory = _instance.getEndpointFactory(_type); + if(factory != null && factory instanceof EndpointFactoryWithUnderlying) + { + EndpointFactoryWithUnderlying f = (EndpointFactoryWithUnderlying)factory; + _factory = f.cloneWithUnderlying(_instance, _underlying); + _factory.initialize(); + } + } + + public short type() + { + return _instance.type(); + } + + public String protocol() + { + return _instance.protocol(); + } + + public EndpointI create(java.util.ArrayList<String> args, boolean oaEndpoint) + { + if(_factory == null) + { + return null; + } + return _factory.create(args, oaEndpoint); + } + + public EndpointI read(com.zeroc.Ice.InputStream s) + { + if(_factory == null) + { + return null; + } + return _factory.read(s); + } + + public void destroy() + { + if(_factory != null) + { + _factory.destroy(); + } + _instance = null; + } + + public EndpointFactory clone(ProtocolInstance instance) + { + return new UnderlyingEndpointFactory(instance, _type, _underlying); + } + + protected ProtocolInstance _instance; + + private final short _type; + private final short _underlying; + private EndpointFactory _factory; +}
\ No newline at end of file diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/WSEndpointFactory.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/WSEndpointFactory.java index a21a7c3129d..23e0cbf2305 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/WSEndpointFactory.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/WSEndpointFactory.java @@ -9,51 +9,28 @@ package com.zeroc.IceInternal; -final public class WSEndpointFactory implements EndpointFactory +final public class WSEndpointFactory extends EndpointFactoryWithUnderlying { - public WSEndpointFactory(ProtocolInstance instance, EndpointFactory delegate) + public WSEndpointFactory(ProtocolInstance instance, short type) { - _instance = instance; - _delegate = delegate; + super(instance, type); } @Override - public short type() + public EndpointFactory cloneWithUnderlying(ProtocolInstance instance, short underlying) { - return _instance.type(); + return new WSEndpointFactory(instance, underlying); } @Override - public String protocol() + public EndpointI createWithUnderlying(EndpointI underlying, java.util.ArrayList<String> args, boolean oaEndpoint) { - return _instance.protocol(); + return new WSEndpoint(_instance, underlying, args); } @Override - public EndpointI create(java.util.ArrayList<String> args, boolean oaEndpoint) + public EndpointI readWithUnderlying(EndpointI underlying, com.zeroc.Ice.InputStream s) { - return new WSEndpoint(_instance, _delegate.create(args, oaEndpoint), args); + return new WSEndpoint(_instance, underlying, s); } - - @Override - public EndpointI read(com.zeroc.Ice.InputStream s) - { - return new WSEndpoint(_instance, _delegate.read(s), s); - } - - @Override - public void destroy() - { - _delegate.destroy(); - _instance = null; - } - - @Override - public EndpointFactory clone(ProtocolInstance instance, EndpointFactory delegate) - { - return new WSEndpointFactory(instance, delegate); - } - - private ProtocolInstance _instance; - private EndpointFactory _delegate; } diff --git a/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointFactoryI.java b/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointFactoryI.java index 66c2b391438..af2be3673cb 100644 --- a/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointFactoryI.java +++ b/java/src/IceBT/src/main/java/com/zeroc/IceBT/EndpointFactoryI.java @@ -53,9 +53,9 @@ final class EndpointFactoryI implements EndpointFactory } @Override - public EndpointFactory clone(ProtocolInstance inst, EndpointFactory del) + public EndpointFactory clone(ProtocolInstance instance) { - return new EndpointFactoryI(new Instance(_instance.communicator(), inst.type(), inst.protocol())); + return new EndpointFactoryI(new Instance(_instance.communicator(), instance.type(), instance.protocol())); } private Instance _instance; diff --git a/java/src/IceBT/src/main/java/com/zeroc/IceBT/PluginI.java b/java/src/IceBT/src/main/java/com/zeroc/IceBT/PluginI.java index 2da1c7920a7..e030dc92b21 100644 --- a/java/src/IceBT/src/main/java/com/zeroc/IceBT/PluginI.java +++ b/java/src/IceBT/src/main/java/com/zeroc/IceBT/PluginI.java @@ -9,29 +9,28 @@ package com.zeroc.IceBT; +import com.zeroc.IceInternal.ProtocolPluginFacade; +import com.zeroc.Ice.BTEndpointType; +import com.zeroc.Ice.BTSEndpointType; +import com.zeroc.Ice.SSLEndpointType; +import com.zeroc.IceInternal.UnderlyingEndpointFactory; + class PluginI implements com.zeroc.Ice.Plugin { public PluginI(com.zeroc.Ice.Communicator communicator) { - final com.zeroc.IceInternal.ProtocolPluginFacade facade = - com.zeroc.IceInternal.Util.getProtocolPluginFacade(communicator); + final ProtocolPluginFacade f = com.zeroc.IceInternal.Util.getProtocolPluginFacade(communicator); // // Register the endpoint factory. We have to do this now, rather than // in initialize, because the communicator may need to interpret // proxies before the plug-in is fully initialized. // - EndpointFactoryI factory = - new EndpointFactoryI(new Instance(communicator, com.zeroc.Ice.BTEndpointType.value, "bt")); - facade.addEndpointFactory(factory); + Instance bt = new Instance(communicator, BTEndpointType.value, "bt"); + f.addEndpointFactory(new EndpointFactoryI(bt)); - com.zeroc.IceInternal.EndpointFactory sslFactory = - facade.getEndpointFactory(com.zeroc.Ice.SSLEndpointType.value); - if(sslFactory != null) - { - Instance instance = new Instance(communicator, com.zeroc.Ice.BTSEndpointType.value, "bts"); - facade.addEndpointFactory(sslFactory.clone(instance, new EndpointFactoryI(instance))); - } + Instance bts = new Instance(communicator, BTSEndpointType.value, "bts"); + f.addEndpointFactory(new UnderlyingEndpointFactory(bts, SSLEndpointType.value, BTSEndpointType.value)); } @Override diff --git a/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/EndpointFactoryI.java b/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/EndpointFactoryI.java index 0b4df6a95af..1c3fac9d452 100644 --- a/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/EndpointFactoryI.java +++ b/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/EndpointFactoryI.java @@ -9,54 +9,35 @@ package com.zeroc.IceSSL; -import com.zeroc.IceInternal.EndpointFactory; - -final class EndpointFactoryI implements EndpointFactory +final class EndpointFactoryI extends com.zeroc.IceInternal.EndpointFactoryWithUnderlying { - EndpointFactoryI(Instance instance, EndpointFactory delegate) + EndpointFactoryI(Instance instance, short type) { + super(instance, type); _instance = instance; - _delegate = delegate; - } - - @Override - public short type() - { - return _instance.type(); - } - - @Override - public String protocol() - { - return _instance.protocol(); - } - - @Override - public com.zeroc.IceInternal.EndpointI create(java.util.ArrayList<String> args, boolean oaEndpoint) - { - return new EndpointI(_instance, _delegate.create(args, oaEndpoint)); } @Override - public com.zeroc.IceInternal.EndpointI read(com.zeroc.Ice.InputStream s) + public com.zeroc.IceInternal.EndpointFactory cloneWithUnderlying(com.zeroc.IceInternal.ProtocolInstance instance, + short underlying) { - return new EndpointI(_instance, _delegate.read(s)); + return new EndpointFactoryI(new Instance(_instance.engine(), instance.type(), instance.protocol()), underlying); } @Override - public void destroy() + public com.zeroc.IceInternal.EndpointI createWithUnderlying(com.zeroc.IceInternal.EndpointI underlying, + java.util.ArrayList<String> args, + boolean oaEndpoint) { - _delegate.destroy(); - _instance = null; + return new EndpointI(_instance, underlying); } @Override - public EndpointFactory clone(com.zeroc.IceInternal.ProtocolInstance inst, EndpointFactory delegate) + public com.zeroc.IceInternal.EndpointI readWithUnderlying(com.zeroc.IceInternal.EndpointI underlying, + com.zeroc.Ice.InputStream s) { - Instance instance = new Instance(_instance.engine(), inst.type(), inst.protocol()); - return new EndpointFactoryI(instance, delegate != null ? delegate : _delegate.clone(instance, null)); + return new EndpointI(_instance, underlying); } private Instance _instance; - private com.zeroc.IceInternal.EndpointFactory _delegate; } diff --git a/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/PluginI.java b/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/PluginI.java index be7fceb88bc..d028e2fc919 100644 --- a/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/PluginI.java +++ b/java/src/IceSSL/src/main/java/com/zeroc/IceSSL/PluginI.java @@ -9,12 +9,13 @@ package com.zeroc.IceSSL; +import com.zeroc.IceInternal.ProtocolPluginFacade; + class PluginI implements Plugin { public PluginI(com.zeroc.Ice.Communicator communicator) { - final com.zeroc.IceInternal.ProtocolPluginFacade facade = - com.zeroc.IceInternal.Util.getProtocolPluginFacade(communicator); + final ProtocolPluginFacade facade = com.zeroc.IceInternal.Util.getProtocolPluginFacade(communicator); _engine = new SSLEngine(facade); // @@ -22,22 +23,8 @@ class PluginI implements Plugin // in initialize, because the communicator may need to interpret // proxies before the plug-in is fully initialized. // - - // SSL based on TCP - com.zeroc.IceInternal.EndpointFactory tcp = facade.getEndpointFactory(com.zeroc.Ice.TCPEndpointType.value); - if(tcp != null) - { - Instance instance = new Instance(_engine, com.zeroc.Ice.SSLEndpointType.value, "ssl"); - facade.addEndpointFactory(new EndpointFactoryI(instance, tcp.clone(instance, null))); - } - - // SSL based on Bluetooth - com.zeroc.IceInternal.EndpointFactory bluetooth = facade.getEndpointFactory(com.zeroc.Ice.BTEndpointType.value); - if(bluetooth != null) - { - Instance instance = new Instance(_engine, com.zeroc.Ice.BTSEndpointType.value, "bts"); - facade.addEndpointFactory(new EndpointFactoryI(instance, bluetooth.clone(instance, null))); - } + Instance instance = new Instance(_engine, com.zeroc.Ice.SSLEndpointType.value, "ssl"); + facade.addEndpointFactory(new EndpointFactoryI(instance, com.zeroc.Ice.TCPEndpointType.value)); } @Override |