1 20 21 package org.jacorb.orb.http; 22 23 import java.net.*; 24 import java.util.*; 25 import java.io.*; 26 27 import org.jacorb.util.*; 28 import org.jacorb.orb.*; 29 import org.jacorb.orb.giop.*; 30 31 33 public final class ServerConnection 34 extends org.jacorb.orb.connection.ServerConnection 35 { 36 private boolean connected = true; 37 private int readcount = 0; 38 private boolean readyParsed = false; 39 Object oldrequest; 40 Object requestwait = new Object (); 41 org.jacorb.orb.http.httpserver.ServeConnection realCon; 42 Socket mysock; 43 44 private ORB orb = null; 45 private int client_count = 0; 46 47 public ServerConnection( org.jacorb.orb.ORB orb, 48 boolean is_ssl, 49 Socket s, 50 java.io.InputStream _in_stream) 51 throws IOException 52 { 53 this.orb = orb; 54 mysock = s; 55 isSSL = is_ssl; 56 57 in_stream = new BufferedInputStream(_in_stream); 58 realCon = 59 new org.jacorb.orb.http.httpserver.ServeConnection(s,_in_stream); 60 String ip = mysock.getInetAddress().getHostAddress(); 61 if( ip.indexOf('/') > 0) 62 ip = ip.substring( ip.indexOf('/') + 1 ); 63 String host_and_port = ip + ":"+ mysock.getPort(); 64 String ssl = isSSL() ? "SSL " : ""; connection_info = host_and_port; 66 client_count = 1; 67 org.jacorb.util.Debug.output(1,"Accepted HTTP connection from " + host_and_port); 68 69 } 70 71 protected void abort() 72 throws EOFException 73 { 74 org.jacorb.util.Debug.output(3,"HTTPServerConnection to " + connection_info + " aborting..."); 75 throw new EOFException(); 76 77 } 78 79 82 83 public synchronized void closeConnection() 84 { 85 connected=false; 86 realCon.close(); 87 } 88 89 public boolean connected() 90 { 91 return connected; 92 } 93 94 public byte[] readBuffer() 95 throws java.io.IOException 96 { 97 readcount++; 98 in_stream = realCon.getInputStream(); 99 return super.readBuffer(); 100 } 101 102 public synchronized void reconnect() 103 throws org.omg.CORBA.COMM_FAILURE 104 { 105 connected=true; 106 } 107 108 111 112 public synchronized void sendCloseConnection() 113 throws org.omg.CORBA.COMM_FAILURE 114 { 115 String iaddr=mysock.getInetAddress().toString()+mysock.getPort(); 116 118 try 119 { 120 realCon.answerRequest(Messages.closeConnectionMessage()); 121 realCon.close(); 122 } 123 catch ( Exception e ) 124 { 125 throw new org.omg.CORBA.COMM_FAILURE 126 (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); 127 } 128 } 129 130 133 134 public void sendLocateReply( int request_id, 135 int status, 136 org.omg.CORBA.Object arg, 137 int giop_minor ) 138 throws org.omg.CORBA.COMM_FAILURE 139 { 140 143 144 synchronized( writeLock ) 145 { 146 String iaddr=mysock.getInetAddress().toString()+mysock.getPort(); 147 try 149 { 150 151 realCon.answerRequest(Messages.locateReplyMessage( request_id, 152 status, 153 arg, 154 giop_minor )); 155 realCon.close(); 156 157 } 158 catch ( Exception e ) 159 { 160 org.jacorb.util.Debug.output(2,e); 161 throw new org.omg.CORBA.COMM_FAILURE 162 (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); 163 } 164 } 165 } 166 167 public void sendReply( ReplyOutputStream os ) 168 throws IOException 169 { 170 synchronized( writeLock ) 171 { 172 String iaddr=mysock.getInetAddress().toString()+mysock.getPort(); 173 try 175 { 176 byte buf []; 177 if (os!=null) 186 { 187 realCon.answerRequest(os.getBufferCopy()); 188 os.close(); 189 } 190 else 191 { byte[] dummy={0}; 193 realCon.answerRequest(dummy); 194 } 195 197 realCon.close(); 200 } 201 catch ( Exception e ) 202 { 203 org.jacorb.util.Debug.output(2,e); 204 throw new org.omg.CORBA.COMM_FAILURE 205 (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); 206 } 207 } 208 } 209 210 211 public void setTimeOut(int timeout) 212 throws SocketException 213 { 214 } 216 } 217 | Popular Tags |