hammant 2003/01/05 03:41:40 Modified: altrmi build.xml default.properties altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket SocketCustomStreamFactoryHelper.java SocketCustomStreamInvocationHandler.java SocketObjectStreamFactoryHelper.java SocketObjectStreamHostContext.java SocketObjectStreamInvocationHandler.java Added: altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket AbstractSocketStreamSSHInvocationHandler.java AltrmiUserInfo.java SocketCustomStreamSSHHostContext.java SocketCustomStreamSSHInvocationHandler.java altrmi/lib jsch-0-0-9.jar Log: Start of work allowing SSH connections to server. This is client side only. Revision Changes Path 1.61 +1 -0 jakarta-avalon-excalibur/altrmi/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/build.xml,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- build.xml 5 Jan 2003 10:37:10 -0000 1.60 +++ build.xml 5 Jan 2003 11:41:39 -0000 1.61 @@ -30,6 +30,7 @@ <pathelement path="${cornerstone-api.jar}"/> <pathelement path="${phoenix-client.jar}"/> <pathelement path="${phoenix-metagenerate.jar}"/> + <pathelement path="${jsch.jar}"/> <pathelement path="jetty-download/Jetty-${jetty.rel}/Jetty-${jetty.rel}/lib/javax.servlet.jar"/> <pathelement path="jetty-download/Jetty-${jetty.rel}/Jetty-${jetty.rel}/lib/org.mortbay.jetty.jar"/> </path> 1.18 +1 -0 jakarta-avalon-excalibur/altrmi/default.properties Index: default.properties =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/default.properties,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- default.properties 3 Jan 2003 00:17:16 -0000 1.17 +++ default.properties 5 Jan 2003 11:41:39 -0000 1.18 @@ -33,6 +33,7 @@ cornerstone-api.jar=./lib/cornerstone-api.jar phoenix-client.jar=./lib/phoenix-client.jar phoenix-metagenerate.jar=./lib/phoenix-metagenerate.jar +jsch.jar=./lib/jsch-0-0-9.jar jakarta-commons-attributes.jar=./lib/commons-attributes-0.1.jar jakarta-commons-httpclient.jar=./lib/commons-httpclient.jar jakarta-commons-logging.jar=./lib/commons-logging.jar 1.6 +2 -3 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamFactoryHelper.java Index: SocketCustomStreamFactoryHelper.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamFactoryHelper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SocketCustomStreamFactoryHelper.java 26 Oct 2002 14:10:49 -0000 1.5 +++ SocketCustomStreamFactoryHelper.java 5 Jan 2003 11:41:40 -0000 1.6 @@ -7,7 +7,6 @@ */ package org.apache.excalibur.altrmi.client.impl.socket; -import java.io.IOException; import org.apache.excalibur.altrmi.client.AltrmiFactory; import org.apache.excalibur.altrmi.client.AltrmiHostContext; import org.apache.excalibur.altrmi.client.AltrmiInterfaceLookup; @@ -21,7 +20,7 @@ * 0 : 1 : 2 * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version $Revision$ */ public class SocketCustomStreamFactoryHelper extends AbstractFactoryHelper 1.7 +2 -6 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamInvocationHandler.java Index: SocketCustomStreamInvocationHandler.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamInvocationHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SocketCustomStreamInvocationHandler.java 16 Dec 2002 01:00:01 -0000 1.6 +++ SocketCustomStreamInvocationHandler.java 5 Jan 2003 11:41:40 -0000 1.7 @@ -7,21 +7,17 @@ */ package org.apache.excalibur.altrmi.client.impl.socket; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.excalibur.altrmi.client.impl.stream.ClientCustomStreamReadWriter; import org.apache.excalibur.altrmi.client.impl.ClientStreamReadWriter; import org.apache.excalibur.altrmi.common.AltrmiConnectionException; -import org.apache.excalibur.altrmi.common.AltrmiReply; -import org.apache.excalibur.altrmi.common.AltrmiRequest; -import org.apache.excalibur.altrmi.common.MethodRequest; /** * Class SocketCustomStreamInvocationHandler * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version $Revision$ */ public final class SocketCustomStreamInvocationHandler 1.5 +2 -3 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamFactoryHelper.java Index: SocketObjectStreamFactoryHelper.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamFactoryHelper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SocketObjectStreamFactoryHelper.java 26 Oct 2002 14:10:49 -0000 1.4 +++ SocketObjectStreamFactoryHelper.java 5 Jan 2003 11:41:40 -0000 1.5 @@ -7,7 +7,6 @@ */ package org.apache.excalibur.altrmi.client.impl.socket; -import java.io.IOException; import org.apache.excalibur.altrmi.client.AltrmiFactory; import org.apache.excalibur.altrmi.client.AltrmiHostContext; import org.apache.excalibur.altrmi.client.AltrmiInterfaceLookup; @@ -21,7 +20,7 @@ * 0 : 1 : 2 * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version $Revision$ */ public class SocketObjectStreamFactoryHelper extends AbstractFactoryHelper 1.7 +2 -3 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamHostContext.java Index: SocketObjectStreamHostContext.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamHostContext.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SocketObjectStreamHostContext.java 4 Jan 2003 22:17:19 -0000 1.6 +++ SocketObjectStreamHostContext.java 5 Jan 2003 11:41:40 -0000 1.7 @@ -13,7 +13,6 @@ import org.apache.excalibur.altrmi.common.AltrmiConnectionException; import java.io.PipedInputStream; -import java.io.IOException; import java.io.PipedOutputStream; import java.lang.reflect.Method; @@ -21,7 +20,7 @@ * Class SocketObjectStreamHostContext * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version $Revision$ */ public class SocketObjectStreamHostContext extends AbstractSameVmBindableHostContext 1.7 +2 -3 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamInvocationHandler.java Index: SocketObjectStreamInvocationHandler.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketObjectStreamInvocationHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SocketObjectStreamInvocationHandler.java 4 Jan 2003 22:17:19 -0000 1.6 +++ SocketObjectStreamInvocationHandler.java 5 Jan 2003 11:41:40 -0000 1.7 @@ -7,7 +7,6 @@ */ package org.apache.excalibur.altrmi.client.impl.socket; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.excalibur.altrmi.client.impl.stream.ClientObjectStreamReadWriter; @@ -18,7 +17,7 @@ * Class SocketObjectStreamInvocationHandler * * - * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Paul Hammant * @version $Revision$ */ public final class SocketObjectStreamInvocationHandler 1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/AbstractSocketStreamSSHInvocationHandler.java Index: AbstractSocketStreamSSHInvocationHandler.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.altrmi.client.impl.socket; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import org.apache.excalibur.altrmi.client.impl.ClientStreamReadWriter; import org.apache.excalibur.altrmi.client.impl.stream.StreamInvocationHandler; import org.apache.excalibur.altrmi.common.AltrmiConnectionException; import org.apache.excalibur.altrmi.common.ConnectionRefusedException; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.ChannelDirectTCPIP; /** * Class SocketCustomStreamInvocationHandler * * * @author Paul Hammant * @version $Revision: 1.1 $ */ public abstract class AbstractSocketStreamSSHInvocationHandler extends StreamInvocationHandler { private final String m_host; private final int m_port; private final String m_userID; private final String m_password; /** * AbstractSocketStreamInvocationHandler * * * @param host The host to connect to * @param port The port to conenct to * @param classLoader The class loader * * @throws AltrmiConnectionException If a problem connecting * */ public AbstractSocketStreamSSHInvocationHandler(String host, int port, String userID, String password, ClassLoader classLoader) throws AltrmiConnectionException { super(classLoader); m_host = host; m_port = port; m_userID = userID; m_password = password; try { connectToSSHAndPort(); } catch (IOException ioe) { throw new AltrmiConnectionException("Some problem with sockets.", ioe); } catch (JSchException e) { throw new AltrmiConnectionException("Cannot open SSH Connection.", e); } } /** * Method tryReconnect * * * @return connected or not. */ protected boolean tryReconnect() { try { connectToSSHAndPort(); return true; } catch (AltrmiConnectionException ce) { // TODO log ? return false; } catch (JSchException e) { // TODO log ? return false; } catch (IOException e) { // TODO log ? return false; } } private void connectToSSHAndPort() throws JSchException, IOException, AltrmiConnectionException { JSch jsch = new JSch(); Session session = jsch.getSession(m_host, 22); session.setUserInfo(new AltrmiUserInfo(m_userID, m_password)); session.connect(); Socket socket = new Socket(); ChannelDirectTCPIP channel = (ChannelDirectTCPIP) session.openChannel("direct-tcpip"); channel.setInputStream(socket.getInputStream()); channel.setOutputStream(socket.getOutputStream()); channel.setHost(m_host); channel.setPort(m_port); channel.connect(); setObjectReadWriter(createClientStreamReadWriter(socket.getInputStream(), socket.getOutputStream())); } protected abstract ClientStreamReadWriter createClientStreamReadWriter( InputStream in, OutputStream out) throws AltrmiConnectionException; } 1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/AltrmiUserInfo.java Index: AltrmiUserInfo.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.altrmi.client.impl.socket; import com.jcraft.jsch.UserInfo; /** * Class AltrmiUserInfo * * * @author Paul Hammant * @version $Revision: 1.1 $ */ public class AltrmiUserInfo implements UserInfo { private String m_userID; private String m_password; public AltrmiUserInfo(String userID, String password) { m_userID = userID; m_password = password; } public String getName() { return m_userID; } public String getPassphrase(String s) { return null; } public String getPassword() { return m_password; } public boolean promptNameAndPassword(String s) { return false; } public boolean promptNameAndPassphrase(String s) { return false; } public boolean prompt(String s) { return false; } public boolean retry() { return true; } } 1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamSSHHostContext.java Index: SocketCustomStreamSSHHostContext.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.altrmi.client.impl.socket; import org.apache.excalibur.altrmi.client.impl.piped.PipedCustomStreamHostContext; import org.apache.excalibur.altrmi.client.impl.AbstractSameVmBindableHostContext; import org.apache.excalibur.altrmi.client.impl.AbstractHostContext; import org.apache.excalibur.altrmi.common.AltrmiConnectionException; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.lang.reflect.Method; /** * Class SocketCustomStreamHostContext * * * @author Paul Hammant * @version $Revision: 1.1 $ */ public class SocketCustomStreamSSHHostContext extends AbstractSameVmBindableHostContext { private int m_port; /** * Constructor SocketCustomStreamHostContext * * * @param host * @param port * * @throws AltrmiConnectionException * */ public SocketCustomStreamSSHHostContext( String host, int port, String userID, String password ) throws AltrmiConnectionException { super( new SocketCustomStreamSSHInvocationHandler( host, port, userID, password, SocketCustomStreamSSHHostContext.class .getClassLoader() ) ); m_port = port; } /** * Constructor SocketCustomStreamHostContext * * * @param host * @param port * @param classLoader * * @throws AltrmiConnectionException * */ public SocketCustomStreamSSHHostContext( String host, int port, String userID, String password, ClassLoader classLoader ) throws AltrmiConnectionException { super( new SocketCustomStreamSSHInvocationHandler( host, port, userID, password, classLoader ) ); m_port = port; } /** * Make a HostContext for this using SameVM connections nstead of socket based ones. * @return the HostContext * @throws AltrmiConnectionException if a problem */ public AbstractHostContext makeSameVmHostContext() throws AltrmiConnectionException { PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(); try { Object binder = getOptmization("port=" + m_port); if (binder == null) { return null; } Object bound = bind(binder, in, out); if (bound == null) { return null; } PipedCustomStreamHostContext pipedCustomStreamHostContext = new PipedCustomStreamHostContext(in, out); pipedCustomStreamHostContext.initialize(); return pipedCustomStreamHostContext; } catch (Exception e) { throw new AltrmiConnectionException("Naming exception during bind :" + e.getMessage()); } } private Object bind(Object object, PipedInputStream inputStream, PipedOutputStream outputStream) { try { Object[] parms = new Object[]{ inputStream, outputStream }; Method method = object.getClass().getMethod("bind", new Class[] { parms.getClass() }); return method.invoke(object, new Object[] { parms }); } catch (Exception e) { return null; } } } 1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/socket/SocketCustomStreamSSHInvocationHandler.java Index: SocketCustomStreamSSHInvocationHandler.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.altrmi.client.impl.socket; import java.io.InputStream; import java.io.OutputStream; import org.apache.excalibur.altrmi.client.impl.stream.ClientCustomStreamReadWriter; import org.apache.excalibur.altrmi.client.impl.ClientStreamReadWriter; import org.apache.excalibur.altrmi.common.AltrmiConnectionException; /** * Class SocketCustomStreamInvocationHandler * * * @author Paul Hammant * @version $Revision: 1.1 $ */ public final class SocketCustomStreamSSHInvocationHandler extends AbstractSocketStreamSSHInvocationHandler { /** * Constructor SocketCustomStreamInvocationHandler * * * @param host the host name * @param port the port * @param userID the User ID * @param password the password * @param classLoader the classloader for deserialization hints. * * @throws AltrmiConnectionException if a problem * */ public SocketCustomStreamSSHInvocationHandler( String host, int port, String userID, String password, ClassLoader classLoader ) throws AltrmiConnectionException { super( host, port, userID, password, classLoader ); } /** * Create a client stream read/writer * @param in the input stream * @param out the output stream * @return the read/writer * @throws AltrmiConnectionException if a problem */ protected ClientStreamReadWriter createClientStreamReadWriter( InputStream in, OutputStream out ) throws AltrmiConnectionException { return new ClientCustomStreamReadWriter( in, out, m_interfacesClassLoader ); } } 1.1 jakarta-avalon-excalibur/altrmi/lib/jsch-0-0-9.jar <<Binary file>>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>