KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tunnels > agent > RemoteForwardingChannel


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.tunnels.agent;
21
22 import java.io.IOException JavaDoc;
23 import java.net.Socket JavaDoc;
24
25 import com.maverick.multiplex.Channel;
26 import com.maverick.multiplex.IOStreamConnector;
27 import com.maverick.util.ByteArrayWriter;
28 import com.sslexplorer.policyframework.LaunchSession;
29 import com.sslexplorer.tunnels.Tunnel;
30
31 public class RemoteForwardingChannel extends Channel {
32
33     public static final String JavaDoc CHANNEL_TYPE = "remote-tunnel";
34
35     private Tunnel tunnel;
36
37     Socket JavaDoc incomingConnection = null;
38     IOStreamConnector input;
39     IOStreamConnector output;
40     RemoteTunnel remoteTunnel;
41     LaunchSession launchSession;
42
43     public RemoteForwardingChannel(RemoteTunnel remoteTunnel, Socket JavaDoc incomingConnection, Tunnel tunnel, LaunchSession launchSession) {
44         super(CHANNEL_TYPE, 32768, 35000);
45         this.launchSession = launchSession;
46         this.remoteTunnel = remoteTunnel;
47         this.tunnel = tunnel;
48         this.incomingConnection = incomingConnection;
49     }
50
51     public RemoteTunnel getRemoteTunnel() {
52         return remoteTunnel;
53     }
54
55     public byte[] create() throws IOException JavaDoc {
56         ByteArrayWriter msg = new ByteArrayWriter();
57         msg.writeString(launchSession == null ? "" : launchSession.getId());
58         msg.writeInt(tunnel.getResourceId());
59         msg.writeString(tunnel.getResourceName());
60         msg.writeInt(tunnel.getType());
61         msg.writeString(tunnel.getTransport());
62         msg.writeString(tunnel.getSourceInterface());
63         msg.writeInt(tunnel.getSourcePort());
64         msg.writeInt(tunnel.getDestination().getPort());
65         msg.writeString(tunnel.getDestination().getHost());
66         msg.writeBoolean(false);
67         return msg.toByteArray();
68     }
69
70     public void onChannelClose() {
71         if (input != null)
72             input.close();
73         if (output != null)
74             output.close();
75         try {
76             if (incomingConnection != null)
77                 incomingConnection.close();
78         } catch (IOException JavaDoc e) {
79         }
80     }
81
82     public void onChannelOpen(byte[] data) {
83         if (incomingConnection != null) {
84             try {
85                 input = new IOStreamConnector(getInputStream(), incomingConnection.getOutputStream());
86                 output = new IOStreamConnector(incomingConnection.getInputStream(), getOutputStream());
87             } catch (IOException JavaDoc ex) {
88                 close();
89             }
90         }
91     }
92
93     public byte[] open(byte[] data) throws IOException JavaDoc {
94         return null;
95     }
96
97 }
98
Popular Tags