1 package org.jacorb.orb.giop; 2 3 22 23 import java.io.IOException ; 24 import java.util.*; 25 26 import org.apache.avalon.framework.logger.*; 27 import org.apache.avalon.framework.configuration.*; 28 29 import org.jacorb.orb.ORB; 30 import org.jacorb.orb.SystemExceptionHelper; 31 import org.jacorb.orb.dsi.ServerRequest; 32 import org.jacorb.poa.POA; 33 import org.jacorb.poa.POAConstants; 34 import org.jacorb.poa.util.POAUtil; 35 36 import org.omg.CONV_FRAME.CodeSetContext; 37 import org.omg.CORBA.CompletionStatus ; 38 import org.omg.CORBA.NO_PERMISSION ; 39 import org.omg.CORBA.OBJECT_NOT_EXIST ; 40 import org.omg.GIOP.LocateStatusType_1_2; 41 import org.omg.GIOP.ReplyStatusType_1_2; 42 43 44 53 54 public class ServerRequestListener 55 implements RequestListener, Configurable 56 { 57 private ORB orb = null; 58 private POA rootPOA = null; 59 60 61 private org.jacorb.config.Configuration configuration = null; 62 private Logger logger = null; 63 private boolean require_ssl = false; 64 65 public ServerRequestListener( org.omg.CORBA.ORB orb, 66 org.omg.PortableServer.POA rootPOA ) 67 { 68 this.orb = (ORB)orb; 69 this.rootPOA = (POA)rootPOA; 70 } 71 72 public void configure(Configuration myConfiguration) 73 throws ConfigurationException 74 { 75 this.configuration = (org.jacorb.config.Configuration)myConfiguration; 76 logger = 77 configuration.getNamedLogger("jacorb.giop.server.listener"); 78 79 boolean supportSSL = 80 configuration.getAttribute("jacorb.security.support_ssl","off").equals("on"); 81 82 if( supportSSL ) 83 { 84 int required = 85 configuration.getAttributeAsInteger("jacorb.security.ssl.server.required_options",16); 86 87 require_ssl = supportSSL && (required & 0x60) != 0; 90 } 91 } 92 93 public void requestReceived( byte[] request, 94 GIOPConnection connection ) 95 { 96 RequestInputStream in = 97 new RequestInputStream( orb, request ); 98 99 if( require_ssl && ! connection.isSSL() ) 100 { 101 ReplyOutputStream out = 102 new ReplyOutputStream( in.req_hdr.request_id, 103 ReplyStatusType_1_2.SYSTEM_EXCEPTION, 104 in.getGIOPMinor(), 105 false, 106 logger); 108 if (logger.isDebugEnabled()) 109 logger.debug("About to reject request because connection is not SSL."); 110 111 SystemExceptionHelper.write( out, 112 new NO_PERMISSION ( 3, CompletionStatus.COMPLETED_NO )); 113 114 try 115 { 116 connection.sendReply( out ); 117 } 118 catch( IOException e ) 119 { 120 if (logger.isWarnEnabled()) 121 logger.warn("IOException",e); 122 } 123 124 return; 125 } 126 127 if( Messages.responseExpected( in.req_hdr.response_flags )) 129 { 130 connection.incPendingMessages(); 131 } 132 133 if( ! connection.isTCSNegotiated() ) 134 { 135 if( in.getGIOPMinor() == 0 ) 137 { 138 connection.markTCSNegotiated(); 139 } 140 else 141 { 142 CodeSetContext ctx = 143 CodeSet.getCodeSetContext( in.req_hdr.service_context ); 144 145 if( ctx != null ) 146 { 147 connection.setCodeSets( ctx.char_data, ctx.wchar_data ); 148 connection.markTCSNegotiated(); 149 if (logger.isDebugEnabled()) 150 logger.debug("Received CodeSetContext. Using " + 151 CodeSet.csName( ctx.char_data ) + 152 " as TCS and " + 153 CodeSet.csName( ctx.wchar_data ) + 154 " as TCSW" ); 155 } 156 } 157 } 158 159 in.setCodeSet( connection.getTCS(), connection.getTCSW() ); 160 161 ServerRequest server_request = null; 162 163 try 164 { 165 server_request = 166 new ServerRequest( orb, in, connection ); 167 } 168 catch( org.jacorb.poa.except.POAInternalError pie ) 169 { 170 if (logger.isWarnEnabled()) 171 logger.warn("Received a request with a non-jacorb object key" ); 172 173 if( in.isLocateRequest() ) 174 { 175 LocateReplyOutputStream lr_out = 176 new LocateReplyOutputStream(in.req_hdr.request_id, 177 LocateStatusType_1_2._UNKNOWN_OBJECT, 178 in.getGIOPMinor() ); 179 180 try 181 { 182 connection.sendReply( lr_out ); 183 } 184 catch( IOException e ) 185 { 186 if (logger.isWarnEnabled()) 187 logger.warn("IOException",e); 188 } 189 } 190 else 191 { 192 ReplyOutputStream out = 193 new ReplyOutputStream( in.req_hdr.request_id, 194 ReplyStatusType_1_2.SYSTEM_EXCEPTION, 195 in.getGIOPMinor(), 196 false, 197 logger ); 199 SystemExceptionHelper.write( out, 200 new OBJECT_NOT_EXIST ( 0, CompletionStatus.COMPLETED_NO )); 201 202 try 203 { 204 connection.sendReply( out ); 205 } 206 catch( IOException e ) 207 { 208 if (logger.isWarnEnabled()) 209 logger.warn("IOException",e); 210 } 211 } 212 213 return; 214 } 215 216 deliverRequest( server_request ); 217 } 218 219 public void locateRequestReceived ( byte[] request, 220 GIOPConnection connection ) 221 { 222 requestReceived( request, connection ); 224 } 225 226 227 public void cancelRequestReceived( byte[] request, 228 GIOPConnection connection ) 229 { 230 } 231 232 private void deliverRequest( ServerRequest request ) 233 { 234 POA tmp_poa = rootPOA; 235 String res; 236 List scopes; 237 238 try 239 { 240 scopes = request.getScopes(); 242 243 for( int i = 0; i < scopes.size(); i++) 244 { 245 res = ((String )scopes.get (i)); 246 247 if( res.equals("")) 248 break; 249 250 264 265 try 266 { 267 tmp_poa = tmp_poa._getChildPOA( res ); 268 } 269 catch ( org.jacorb.poa.except.ParentIsHolding p ) 270 { 271 279 280 String [] rest_of_name = new String [scopes.size () - i]; 281 for( int j = 0; j < i; j++ ) 282 { 283 rest_of_name[j] = (String )scopes.get( j+i ); 284 } 285 286 request.setRemainingPOAName(rest_of_name); 287 288 break; 289 } 290 } 291 292 if( tmp_poa == null ) 293 { 294 throw new org.omg.CORBA.INTERNAL ("Request POA null!"); 295 } 296 else 297 { 298 299 tmp_poa._invoke( request ); 300 } 301 } 302 catch( org.omg.PortableServer.POAPackage.WrongAdapter wa ) 303 { 304 request.setSystemException( new org.omg.CORBA.OBJECT_NOT_EXIST ("unknown oid") ); 306 request.reply(); 307 } 308 catch( org.omg.CORBA.SystemException one ) 309 { 310 request.setSystemException( one ); 311 request.reply(); 312 } 313 catch( Throwable th ) 314 { 315 request.setSystemException( new org.omg.CORBA.UNKNOWN ( th.toString()) ); 316 request.reply(); 317 if (logger.isWarnEnabled()) 318 logger.warn("IOException",th); 319 } 321 } 322 } | Popular Tags |