corbamessagemediatorimpl.java
来自「JAVA 所有包」· Java 代码 · 共 2,135 行 · 第 1/5 页
JAVA
2,135 行
msg.getRequestId(), LocateReplyMessage.OBJECT_HERE, null); } else { reply = MessageBase.createLocateReply( orb, msg.getGIOPVersion(), msg.getEncodingVersion(), msg.getRequestId(), LocateReplyMessage.OBJECT_FORWARD, ior); } // REVISIT: Should we catch SystemExceptions? } catch (AddressingDispositionException ex) { // create a response containing the expected target // addressing disposition. reply = MessageBase.createLocateReply( orb, msg.getGIOPVersion(), msg.getEncodingVersion(), msg.getRequestId(), LocateReplyMessage.LOC_NEEDS_ADDRESSING_MODE, null); addrDisp = ex.expectedAddrDisp(); } catch (RequestCanceledException ex) { return; // no need to send reply } catch ( Exception ex ) { // REVISIT If exception is not OBJECT_NOT_EXIST, it should // have a different reply // This handles OBJECT_NOT_EXIST exceptions thrown in // the subcontract or obj manager. Send back UNKNOWN_OBJECT. reply = MessageBase.createLocateReply( orb, msg.getGIOPVersion(), msg.getEncodingVersion(), msg.getRequestId(), LocateReplyMessage.UNKNOWN_OBJECT, null); } CDROutputObject outputObject = createAppropriateOutputObject(messageMediator, msg, reply); messageMediator.setOutputObject(outputObject); outputObject.setMessageMediator(messageMediator); reply.write(outputObject); // outputObject.setMessage(reply); // REVISIT - not necessary if (ior != null) { ior.write(outputObject); } if (addrDisp != -1) { AddressingDispositionHelper.write(outputObject, addrDisp); } } private CDROutputObject createAppropriateOutputObject( CorbaMessageMediator messageMediator, Message msg, LocateReplyMessage reply) { CDROutputObject outputObject; if (msg.getGIOPVersion().lessThan(GIOPVersion.V1_2)) { // locate msgs 1.0 & 1.1 :=> grow, // REVISIT - build from factory outputObject = new CDROutputObject( (ORB) messageMediator.getBroker(), this, GIOPVersion.V1_0, (CorbaConnection) messageMediator.getConnection(), reply, ORBConstants.STREAM_FORMAT_VERSION_1); } else { // 1.2 :=> stream // REVISIT - build from factory outputObject = new CDROutputObject( (ORB) messageMediator.getBroker(), messageMediator, reply, ORBConstants.STREAM_FORMAT_VERSION_1); } return outputObject; } public void handleThrowableDuringServerDispatch( CorbaMessageMediator messageMediator, Throwable throwable, CompletionStatus completionStatus) { if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) { dprint(".handleThrowableDuringServerDispatch: " + opAndId(messageMediator) + ": " + throwable); } // If we haven't unmarshaled the header, we probably don't // have enough information to even send back a reply. // REVISIT // Cannot do this check. When target addressing disposition does // not match (during header unmarshaling) it throws an exception // to be handled here. /* if (! ((CDRInputObject)messageMediator.getInputObject()) .unmarshaledHeader()) { return; } */ handleThrowableDuringServerDispatch(messageMediator, throwable, completionStatus, 1); } // REVISIT - catch and ignore RequestCanceledException. protected void handleThrowableDuringServerDispatch( CorbaMessageMediator messageMediator, Throwable throwable, CompletionStatus completionStatus, int iteration) { if (iteration > 10) { if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) { dprint(".handleThrowableDuringServerDispatch: " + opAndId(messageMediator) + ": cannot handle: " + throwable); } // REVISIT - should we close connection? RuntimeException rte = new RuntimeException("handleThrowableDuringServerDispatch: " + "cannot create response."); rte.initCause(throwable); throw rte; } try { if (throwable instanceof ForwardException) { ForwardException fex = (ForwardException)throwable ; createLocationForward( messageMediator, fex.getIOR(), null ) ; return; } if (throwable instanceof AddressingDispositionException) { handleAddressingDisposition( messageMediator, (AddressingDispositionException)throwable); return; } // Else. SystemException sex = convertThrowableToSystemException(throwable, completionStatus); createSystemExceptionResponse(messageMediator, sex, null); return; } catch (Throwable throwable2) { // User code (e.g., postinvoke, interceptors) may change // the exception, so we end up back here. // Report the changed exception. handleThrowableDuringServerDispatch(messageMediator, throwable2, completionStatus, iteration + 1); return; } } protected SystemException convertThrowableToSystemException( Throwable throwable, CompletionStatus completionStatus) { if (throwable instanceof SystemException) { return (SystemException)throwable; } if (throwable instanceof RequestCanceledException) { // Reporting an exception response causes the // poa current stack, the interceptor stacks, etc. // to be balanced. It also notifies interceptors // that the request was cancelled. return wrapper.requestCanceled( throwable ) ; } // NOTE: We do not trap ThreadDeath above Throwable. // There is no reason to stop the thread. It is // just a worker thread. The ORB never throws // ThreadDeath. Client code may (e.g., in ServantManagers, // interceptors, or servants) but that should not // effect the ORB threads. So it is just handled // generically. // // Last resort. // If user code throws a non-SystemException report it generically. // return wrapper.runtimeexception( CompletionStatus.COMPLETED_MAYBE, throwable ) ; } protected void handleAddressingDisposition( CorbaMessageMediator messageMediator, AddressingDispositionException ex) { short addrDisp = -1; // from iiop.RequestProcessor. // Respond with expected target addressing disposition. switch (messageMediator.getRequestHeader().getType()) { case Message.GIOPRequest : ReplyMessage replyHeader = MessageBase.createReply( (ORB)messageMediator.getBroker(), messageMediator.getGIOPVersion(), messageMediator.getEncodingVersion(), messageMediator.getRequestId(), ReplyMessage.NEEDS_ADDRESSING_MODE, null, null); // REVISIT: via acceptor factory. CDROutputObject outputObject = new CDROutputObject( (ORB)messageMediator.getBroker(), this, messageMediator.getGIOPVersion(), (CorbaConnection)messageMediator.getConnection(), replyHeader, ORBConstants.STREAM_FORMAT_VERSION_1); messageMediator.setOutputObject(outputObject); outputObject.setMessageMediator(messageMediator); replyHeader.write(outputObject); AddressingDispositionHelper.write(outputObject, ex.expectedAddrDisp()); return; case Message.GIOPLocateRequest : LocateReplyMessage locateReplyHeader = MessageBase.createLocateReply( (ORB)messageMediator.getBroker(), messageMediator.getGIOPVersion(), messageMediator.getEncodingVersion(), messageMediator.getRequestId(), LocateReplyMessage.LOC_NEEDS_ADDRESSING_MODE, null); addrDisp = ex.expectedAddrDisp(); // REVISIT: via acceptor factory. outputObject = createAppropriateOutputObject(messageMediator, messageMediator.getRequestHeader(), locateReplyHeader); messageMediator.setOutputObject(outputObject); outputObject.setMessageMediator(messageMediator); locateReplyHeader.write(outputObject); IOR ior = null; if (ior != null) { ior.write(outputObject); } if (addrDisp != -1) { AddressingDispositionHelper.write(outputObject, addrDisp); } return; } } public CorbaMessageMediator createResponse( CorbaMessageMediator messageMediator, ServiceContexts svc) { // REVISIT: ignore service contexts during framework transition. // They are set in SubcontractResponseHandler to the wrong connection. // Then they would be set again here and a duplicate contexts // exception occurs. return createResponseHelper( messageMediator, getServiceContextsForReply(messageMediator, null)); } public CorbaMessageMediator createUserExceptionResponse( CorbaMessageMediator messageMediator, ServiceContexts svc) { // REVISIT - same as above return createResponseHelper( messageMediator, getServiceContextsForReply(messageMediator, null), true); } public CorbaMessageMediator createUnknownExceptionResponse( CorbaMessageMediator messageMediator, UnknownException ex) { // NOTE: This service context container gets augmented in // tail call. ServiceContexts contexts = null; SystemException sys = new UNKNOWN( 0, CompletionStatus.COMPLETED_MAYBE); contexts = new ServiceContexts( (ORB)messageMediator.getBroker() ); UEInfoServiceContext uei = new UEInfoServiceContext(sys); contexts.put( uei ) ; return createSystemExceptionResponse(messageMediator, sys, contexts); } public CorbaMessageMediator createSystemExceptionResponse( CorbaMessageMediator messageMediator, SystemException ex, ServiceContexts svc) { if (messageMediator.getConnection() != null) { // It is possible that fragments of response have already been // sent. Then an error may occur (e.g. marshaling error like // non serializable object). In that case it is too late // to send the exception. We just return the existing fragmented // stream here. This will cause an incomplete last fragment // to be sent. Then the other side will get a marshaling error // when attempting to unmarshal. // REVISIT: Impl - make interface method to do the following. CorbaMessageMediatorImpl mediator = (CorbaMessageMediatorImpl) ((CorbaConnection)messageMediator.getConnection()) .serverRequestMapGet(messageMediator.getRequestId()); OutputObject existingOutputObject = null; if (mediator != null) { existingOutputObject = mediator.getOutputObject(); } // REVISIT: need to think about messageMediator containing correct // pointer to output object. if (existingOutputObject != null && mediator.sentFragment() && ! mediator.sentFullMessage()) { return mediator; } } // Only do this if interceptors have been initialized on this request // and have not completed their lifecycle (otherwise the info stack // may be empty or have a different request's entry on top). if (messageMediator.executePIInResponseConstructor()) { // REVISIT: not necessary in framework now? // Inform Portable Interceptors of the SystemException. This is // required to be done here because the ending interception point // is called in the when creating the response below // but we do not currently write the SystemException into the // response until after the ending point is called. ((ORB)messageMediator.getBroker()).getPIHandler().setServerPIInfo( ex ); } if (((ORB)messageMediator.getBroker()).subcontractDebugFlag && ex != null) { dprint(".createSystemExceptionResponse: " + opAndId(messageMediator), ex); } ServiceContexts serviceContexts = getServiceContextsForReply(messageMediator, svc); // NOTE: We MUST add the service context before creating // the response since service contexts are written to the // stream when the response object is created. addExceptionDetailMessage(messageMediator, ex, serviceContexts); CorbaMessageMediator response = createResponseHelper(messageMediator, serviceContexts, false); // NOTE: From here on, it is too late to add more service contexts. // They have already been serialized to the stream (and maybe fragments // sent). ORBUtility.writeSystemException( ex, (OutputStream)response.getOutputObject()); return response; } private void addExceptionDetailMessage(CorbaMessageMediator mediator, SystemException ex, ServiceContexts serviceContexts) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); ex.printStackTrace(pw); pw.flush(); // NOTE: you must flush or baos will be empty. EncapsOutputStream encapsOutputStream = new EncapsOutputStream((ORB)mediator.getBroker()); encapsOutputStream.putEndian(); encapsOutputStream.write_wstring(baos.toString()); UnknownServiceContext serviceContext = new UnknownServiceContext(ExceptionDetailMessage.value, encapsOutputStream.toByteArray()); serviceContexts.put(serviceContext); } public CorbaMessageMediator createLocationForward( CorbaMessageMediator messageMediator, IOR ior, ServiceContexts svc) { ReplyMessage reply = MessageBase.createReply( (ORB)messageMediator.getBroker(), messageMediator.getGIOPVersion(), messageMediator.getEncodingVersion(), messageMediator.getRequestId(), ReplyMessage.LOCATION_FORWARD, getServiceContextsForReply(messageMediator, svc), ior); return createResponseHelper(messageMediator, reply, ior); } protected CorbaMessageMediator createResponseHelper( CorbaMessageMediator
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?