diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/DssServiceRpcFactory.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/DssServiceRpcFactory.java deleted file mode 100644 index 7c321b188c5dcbf1afec05e443fefeaee3899dc5..0000000000000000000000000000000000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/DssServiceRpcFactory.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2010 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.openbis.dss.rpc.client; - -import java.io.File; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.List; - -import ch.systemsx.cisd.common.api.IRpcService; -import ch.systemsx.cisd.common.api.IRpcServiceNameServer; -import ch.systemsx.cisd.common.api.RpcServiceInterfaceDTO; -import ch.systemsx.cisd.common.api.RpcServiceInterfaceVersionDTO; -import ch.systemsx.cisd.common.spring.HttpInvokerUtils; -import ch.systemsx.cisd.common.ssl.SslCertificateHelper; - -/** - * Client-side factory for DssServiceRpc objects. - * <p> - * Create client-side proxies to server RPC interface objects. - * - * @author Chandrasekhar Ramakrishnan - */ -public class DssServiceRpcFactory implements IDssServiceRpcFactory -{ - private static final int SERVER_TIMEOUT_MIN = 5; - - private static final String NAME_SERVER_SUFFIX = "/rpc"; - - public List<RpcServiceInterfaceDTO> getSupportedInterfaces(String serverURL, - boolean getServerCertificateFromServer) throws IncompatibleAPIVersionsException - { - // We assume the location of the name server follows the convention - String nameServerURL = serverURL + NAME_SERVER_SUFFIX; - Class<IRpcServiceNameServer> clazz = IRpcServiceNameServer.class; - if (getServerCertificateFromServer) - { - new SslCertificateHelper(nameServerURL, getConfigDirectory(), "dss").setUpKeyStore(); - } - - IRpcServiceNameServer nameServer = - new ServiceProxyBuilder<IRpcServiceNameServer>(nameServerURL, clazz, - SERVER_TIMEOUT_MIN, 1).getServiceInterface(); - return nameServer.getSupportedInterfaces(); - } - - public <T extends IRpcService> T getService(RpcServiceInterfaceVersionDTO ifaceVersion, - Class<T> ifaceClazz, String serverURL, boolean getServerCertificateFromServer) - throws IncompatibleAPIVersionsException - { - String serviceURL = serverURL + ifaceVersion.getUrlSuffix(); - if (getServerCertificateFromServer) - { - new SslCertificateHelper(serviceURL, getConfigDirectory(), "dss").setUpKeyStore(); - } - - return new ServiceProxyBuilder<T>(serviceURL, ifaceClazz, SERVER_TIMEOUT_MIN, 1) - .getServiceInterface(); - } - - private File getConfigDirectory() - { - String homeDir = System.getProperty("dss.root"); - File configDir; - if (homeDir != null) - { - configDir = new File(homeDir, "etc"); - } else - { - homeDir = System.getProperty("user.home"); - configDir = new File(homeDir, ".dss"); - } - configDir.mkdirs(); - return configDir; - } -} - -/** - * Internal helper class for constructing service proxies; - * - * @author Chandrasekhar Ramakrishnan - */ -@SuppressWarnings("unchecked") -class ServiceProxyBuilder<T extends IRpcService> -{ - private final String serviceURL; - - private final Class<?> clazz; - - private final int serverTimeoutMin; - - private final int apiClientVersion; - - ServiceProxyBuilder(String serviceURL, Class<?> clazz, int serverTimeoutMin, - int apiClientVersion) - { - this.serviceURL = serviceURL; - this.clazz = clazz; - this.serverTimeoutMin = serverTimeoutMin; - this.apiClientVersion = apiClientVersion; - } - - T getServiceInterface() throws IncompatibleAPIVersionsException - { - T service = getRawServiceProxy(); - service = wrapProxyInServiceInvocationHandler(service); - final int apiServerVersion = service.getMajorVersion(); - final int apiMinClientVersion = service.getMinorVersion(); - if (apiClientVersion < apiMinClientVersion || apiClientVersion > apiServerVersion) - { - throw new IncompatibleAPIVersionsException(apiClientVersion, apiServerVersion, - apiMinClientVersion); - } - - return service; - } - - private T getRawServiceProxy() - { - return (T) HttpInvokerUtils.createStreamSupportingServiceStub(clazz, serviceURL, - serverTimeoutMin); - } - - private T wrapProxyInServiceInvocationHandler(T service) - { - final ClassLoader classLoader = DssServiceRpcFactory.class.getClassLoader(); - final ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(service); - final T proxy = (T) Proxy.newProxyInstance(classLoader, new Class[] - { clazz }, invocationHandler); - return proxy; - } - - /** - * An invocation handler that unwraps exceptions that occur in methods called via reflection. - * - * @author Chandrasekhar Ramakrishnan - */ - private static final class ServiceInvocationHandler implements InvocationHandler - { - private final IRpcService service; - - private ServiceInvocationHandler(IRpcService service) - { - this.service = service; - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - try - { - return method.invoke(service, args); - } catch (InvocationTargetException ex) - { - throw ex.getCause(); - } - } - } -} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/IDssServiceRpcFactory.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/IDssServiceRpcFactory.java deleted file mode 100644 index f49997ef951ea404dc5a0470e1b51c64e974d8e6..0000000000000000000000000000000000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/IDssServiceRpcFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.openbis.dss.rpc.client; - -import java.util.List; - -import ch.systemsx.cisd.common.api.IRpcService; -import ch.systemsx.cisd.common.api.RpcServiceInterfaceDTO; -import ch.systemsx.cisd.common.api.RpcServiceInterfaceVersionDTO; - -/** - * A factory for creating proxies to RPC services on a data store server. - * <p> - * Because of the inherent potential variability in the DSS RPC, the interface has been made - * flexible to provide clients simultaneous access to several different communication interfaces. - * - * @author Chandrasekhar Ramakrishnan - */ -public interface IDssServiceRpcFactory -{ - /** - * Get an array of RPC service interfaces supported by the server. - * - * @param serverURL The URL of the data store server to query. - * @param shouldGetServerCertificateFromServer If the URL scheme is https and - * shouldGetServerCertificateFromServer is true, the factory will retrieve the SSL - * certificate from the server. - */ - public abstract List<RpcServiceInterfaceDTO> getSupportedInterfaces(String serverURL, - boolean shouldGetServerCertificateFromServer) throws IncompatibleAPIVersionsException; - - /** - * Get get RPC service interface specified by <code>iface</code>. - */ - public abstract <T extends IRpcService> T getService( - RpcServiceInterfaceVersionDTO ifaceVersion, Class<T> ifaceClazz, String serverURL, - boolean getServerCertificateFromServer) throws IncompatibleAPIVersionsException; -} \ No newline at end of file diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/IncompatibleAPIVersionsException.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/IncompatibleAPIVersionsException.java deleted file mode 100644 index 03c577f1dfad378416d561a2e4374a0ad64ac7de..0000000000000000000000000000000000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/rpc/client/IncompatibleAPIVersionsException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.openbis.dss.rpc.client; - -import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; - -/** - * Exception that is thrown if the client can not talk to the server because of API version - * incompatibility. - * - * @author Chandrasekhar Ramakrishnan - */ -public class IncompatibleAPIVersionsException extends EnvironmentFailureException -{ - private static final long serialVersionUID = 1L; - - public IncompatibleAPIVersionsException(int clientVersion, int serverVersion, - int minimalClientVersion) - { - super((clientVersion < serverVersion) ? String.format( - "This client is too old for the server " - + "(client API version: %d, server requires at least version: %d", - clientVersion, minimalClientVersion) : String.format( - "This client is too new for the server " - + "(client API version: %d, server API version: %d", clientVersion, - serverVersion)); - } -}