1 22 package org.jboss.proxy.ejb; 23 24 import java.security.Principal ; 25 import java.util.Map ; 26 import javax.management.MBeanException ; 27 import javax.management.MBeanServer ; 28 import javax.management.ObjectName ; 29 import javax.transaction.Transaction ; 30 31 import org.omg.CORBA.BAD_OPERATION ; 32 import org.omg.CORBA.InterfaceDef ; 33 import org.omg.CORBA.ORBPackage.InvalidName ; 34 import org.omg.CORBA.portable.InvokeHandler ; 35 import org.omg.CORBA.portable.InputStream ; 36 import org.omg.CORBA.portable.OutputStream ; 37 import org.omg.CORBA.portable.ResponseHandler ; 38 import org.omg.CORBA.portable.UnknownException ; 39 import org.omg.PortableServer.Current ; 40 import org.omg.PortableServer.POA ; 41 42 import org.jboss.iiop.CorbaORB; 43 import org.jboss.iiop.csiv2.SASCurrent; 44 import org.jboss.iiop.rmi.RmiIdlUtil; 45 import org.jboss.iiop.rmi.marshal.strategy.SkeletonStrategy; 46 import org.jboss.invocation.Invocation; 47 import org.jboss.invocation.InvocationKey; 48 import org.jboss.invocation.InvocationType; 49 import org.jboss.invocation.PayloadKey; 50 import org.jboss.invocation.iiop.ReferenceData; 51 import org.jboss.invocation.iiop.ServantWithMBeanServer; 52 import org.jboss.logging.Logger; 53 import org.jboss.tm.iiop.TxServerInterceptor; 54 import org.jboss.security.SimplePrincipal; 55 56 57 68 public class EjbObjectCorbaServant 69 extends ServantWithMBeanServer 70 implements InvokeHandler , LocalIIOPInvoker 71 { 72 73 76 private final ObjectName containerName; 77 78 81 private final ClassLoader containerClassLoader; 82 83 87 private final Current poaCurrent; 88 89 92 private final Map methodInvokerMap; 93 94 98 private final String [] repositoryIds; 99 100 103 private final InterfaceDef interfaceDef; 104 105 108 private final Logger logger; 109 110 113 private final boolean traceEnabled; 114 115 118 private MBeanServer mbeanServer; 119 120 124 private SASCurrent sasCurrent; 125 126 129 public EjbObjectCorbaServant(ObjectName containerName, 130 ClassLoader containerClassLoader, 131 Current poaCurrent, 132 Map methodInvokerMap, 133 String [] repositoryIds, 134 InterfaceDef interfaceDef, 135 Logger logger) 136 { 137 this.containerName = containerName; 138 this.containerClassLoader = containerClassLoader; 139 this.poaCurrent = poaCurrent; 140 this.methodInvokerMap = methodInvokerMap; 141 this.repositoryIds = repositoryIds; 142 this.interfaceDef = interfaceDef; 143 this.logger = logger; 144 this.traceEnabled = logger.isTraceEnabled(); 145 try 146 { 147 this.sasCurrent = (SASCurrent) 148 CorbaORB.getInstance().resolve_initial_references("SASCurrent"); 149 } 150 catch (InvalidName invalidName) 151 { 152 this.sasCurrent = null; 153 } 154 } 155 156 158 161 public void setMBeanServer(MBeanServer mbeanServer) 162 { 163 this.mbeanServer = mbeanServer; 164 } 165 166 168 171 public org.omg.CORBA.Object _get_interface_def() 172 { 173 if (interfaceDef != null) 174 return interfaceDef; 175 else 176 return super._get_interface_def(); 177 } 178 179 181 185 public String [] _all_interfaces(POA poa, byte[] objectId) 186 { 187 return (String []) repositoryIds.clone(); 188 } 189 190 195 public OutputStream _invoke(String opName, 196 InputStream in, 197 ResponseHandler handler) 198 { 199 200 if (traceEnabled) 201 { 202 logger.trace("EJBObject invocation: " + opName); 203 } 204 205 ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); 206 Thread.currentThread().setContextClassLoader(containerClassLoader); 207 try 208 { 209 SkeletonStrategy op = (SkeletonStrategy) methodInvokerMap.get(opName); 210 if (op == null) 211 { 212 logger.debug("Unable to find opname '" + opName + "' valid operations:" + methodInvokerMap.keySet()); 213 throw new BAD_OPERATION (opName); 214 } 215 216 Object id; 217 try 218 { 219 id = ReferenceData.extractObjectId(poaCurrent.get_object_id()); 220 if (traceEnabled && id != null) 221 logger.trace(" id class is " 222 + id.getClass().getName()); 223 } 224 catch (Exception e) 225 { 226 logger.error("Error getting EJBObject id", e); 227 throw new UnknownException (e); 228 } 229 230 org.omg.CORBA_2_3.portable.OutputStream out; 231 try 232 { 233 Object retVal; 234 235 if (opName.equals("_get_handle")) 236 { 237 retVal = new HandleImplIIOP(_this_object()); 238 } 239 else 240 { 241 Transaction tx = TxServerInterceptor.getCurrentTransaction(); 242 SimplePrincipal principal = null; 243 char[] password = null; 244 if (sasCurrent != null) 245 { 246 byte[] username = sasCurrent.get_incoming_username(); 247 byte[] credential = sasCurrent.get_incoming_password(); 248 String name = new String (username, "UTF-8"); 249 int domainIndex = name.indexOf('@'); 250 if (domainIndex > 0) 251 name = name.substring(0, domainIndex); 252 if (name.length() == 0) 253 { 254 byte[] incomingName = 255 sasCurrent.get_incoming_principal_name(); 256 if (incomingName.length > 0) 257 { 258 name = new String (incomingName, "UTF-8"); 259 domainIndex = name.indexOf('@'); 260 if (domainIndex > 0) 261 name = name.substring(0, domainIndex); 262 principal = new SimplePrincipal(name); 263 password = name.toCharArray(); 266 } 267 } 268 else 269 { 270 principal = new SimplePrincipal(name); 271 password = new String (credential, "UTF-8").toCharArray(); 272 } 273 274 } 275 Object [] params = 276 op.readParams((org.omg.CORBA_2_3.portable.InputStream ) in); 277 Invocation inv = new Invocation(id, 278 op.getMethod(), 279 params, 280 tx, 281 principal, 282 password ); 283 inv.setValue(InvocationKey.INVOKER_PROXY_BINDING, 284 "iiop", 285 PayloadKey.AS_IS); 286 inv.setType(InvocationType.REMOTE); 287 retVal = mbeanServer.invoke(containerName, 288 "invoke", 289 new Object []{inv}, 290 Invocation.INVOKE_SIGNATURE); 291 292 } 293 out = (org.omg.CORBA_2_3.portable.OutputStream ) 294 handler.createReply(); 295 if (op.isNonVoid()) 296 { 297 op.writeRetval(out, retVal); 298 } 299 } 300 catch (Exception e) 301 { 302 if (traceEnabled) 303 { 304 logger.trace("Exception in EJBObject invocation", e); 305 } 306 if (e instanceof MBeanException ) 307 { 308 e = ((MBeanException ) e).getTargetException(); 309 } 310 RmiIdlUtil.rethrowIfCorbaSystemException(e); 311 out = (org.omg.CORBA_2_3.portable.OutputStream ) 312 handler.createExceptionReply(); 313 op.writeException(out, e); 314 } 315 return out; 316 } 317 finally 318 { 319 Thread.currentThread().setContextClassLoader(oldCl); 320 } 321 } 322 323 325 331 public Object invoke(String opName, 332 Object [] arguments, 333 Transaction tx, 334 Principal identity, 335 Object credential) 336 throws Exception 337 { 338 if (traceEnabled) 339 { 340 logger.trace("EJBObject local invocation: " + opName); 341 } 342 343 ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); 344 Thread.currentThread().setContextClassLoader(containerClassLoader); 345 346 try 347 { 348 SkeletonStrategy op = (SkeletonStrategy) methodInvokerMap.get(opName); 349 if (op == null) 350 { 351 throw new BAD_OPERATION (opName); 352 } 353 354 Object id; 355 try 356 { 357 id = ReferenceData.extractObjectId(poaCurrent.get_object_id()); 358 if (traceEnabled && id != null) 359 { 360 logger.trace(" id class is " 361 + id.getClass().getName()); 362 } 363 } 364 catch (Exception e) 365 { 366 logger.error("Error getting EJBObject id", e); 367 throw new UnknownException (e); 368 } 369 370 Invocation inv = new Invocation(id, 371 op.getMethod(), 372 arguments, 373 tx, 374 null, 375 null ); 376 inv.setValue(InvocationKey.INVOKER_PROXY_BINDING, 377 "iiop", 378 PayloadKey.AS_IS); 379 inv.setType(InvocationType.REMOTE); 380 return mbeanServer.invoke(containerName, 381 "invoke", 382 new Object []{inv}, 383 Invocation.INVOKE_SIGNATURE); 384 } 385 catch (MBeanException e) 386 { 387 throw e.getTargetException(); 388 } 389 finally 390 { 391 Thread.currentThread().setContextClassLoader(oldCl); 392 } 393 } 394 395 } 396 | Popular Tags |