⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corbaserverrequestdispatcherimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /** Always throws OBJECT_NOT_EXIST if operation is not a special method.    * If operation is _non_existent or _not_existent, this will just     * return without performing any action, so that _non_existent can return    * false.  Always throws OBJECT_NOT_EXIST for any other special method.    * Update for issue 4385.    */    protected void handleNullServant(String operation, NullServant nserv )     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".handleNullServant->: " + operation);	    }	    SpecialMethod specialMethod = 		SpecialMethod.getSpecialMethod(operation);	    if ((specialMethod == null) || 		!specialMethod.isNonExistentMethod()) {		if (orb.subcontractDebugFlag) {		    dprint(".handleNullServant: " + operation 			   + ": throwing OBJECT_NOT_EXIST");		}		throw nserv.getException() ;	    }	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".handleNullServant<-: " + operation);	    }	}    }    protected void consumeServiceContexts(CorbaMessageMediator request)     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".consumeServiceContexts->: " 		       + opAndId(request));	    }	    ServiceContexts ctxts = request.getRequestServiceContexts();	    ServiceContext sc ;	    GIOPVersion giopVersion = request.getGIOPVersion();	    // we cannot depend on this since for our local case, we do not send	    // in this service context.  Can we rely on just the CodeSetServiceContext?	    // boolean rtSC = false; // Runtime ServiceContext	    boolean hasCodeSetContext = processCodeSetContext(request, ctxts);	    if (orb.subcontractDebugFlag) {		dprint(".consumeServiceContexts: " + opAndId(request)		       + ": GIOP version: " + giopVersion);		dprint(".consumeServiceContexts: " + opAndId(request)		       + ": as code set context? " + hasCodeSetContext);	    }	    sc = ctxts.get(		SendingContextServiceContext.SERVICE_CONTEXT_ID ) ;	    if (sc != null) {		SendingContextServiceContext scsc =		    (SendingContextServiceContext)sc ;		IOR ior = scsc.getIOR() ;		try {		    ((CorbaConnection)request.getConnection())			.setCodeBaseIOR(ior);		} catch (ThreadDeath td) {		    throw td ;		} catch (Throwable t) {		    throw wrapper.badStringifiedIor( t ) ;		}	    }	    // the RTSC is sent only once during session establishment.  We	    // need to find out if the CodeBaseRef is already set.  If yes,	    // then also the rtSC flag needs to be set to true	    // this is not possible for the LocalCase since there is no	    // IIOPConnection for the LocalCase	    // used for a case where we have JDK 1.3 supporting 1.0 protocol,	    // but sending 2 service contexts, that is not normal as per	    // GIOP rules, based on above information, we figure out that we	    // are talking to the legacy ORB and set the ORB Version Accordingly.	    // this special case tell us that it is legacy SUN orb	    // and not a foreign one	    // rtSC is not available for localcase due to which this generic	    // path would fail if relying on rtSC	    //if (giopVersion.equals(GIOPVersion.V1_0) && hasCodeSetContext && rtSC)	    boolean isForeignORB = false;	    if (giopVersion.equals(GIOPVersion.V1_0) && hasCodeSetContext) {		if (orb.subcontractDebugFlag) {		    dprint(".consumeServiceCOntexts: " + opAndId(request)			   + ": Determined to be an old Sun ORB");		}		    		orb.setORBVersion(ORBVersionFactory.getOLD()) ;		// System.out.println("setting legacy ORB version");	    } else {		// If it didn't include our ORB version service context (below),		// then it must be a foreign ORB.		isForeignORB = true;	    }	    // try to get the ORBVersion sent as part of the ServiceContext	    // if any	    sc = ctxts.get( ORBVersionServiceContext.SERVICE_CONTEXT_ID ) ;	    if (sc != null) {		ORBVersionServiceContext ovsc =		   (ORBVersionServiceContext) sc;		ORBVersion version = ovsc.getVersion();		orb.setORBVersion(version);		isForeignORB = false;	    }	    if (isForeignORB) {		if (orb.subcontractDebugFlag) {		    dprint(".consumeServiceContexts: " + opAndId(request)			   + ": Determined to be a foreign ORB");		}		orb.setORBVersion(ORBVersionFactory.getFOREIGN());	    }	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".consumeServiceContexts<-: " + opAndId(request));	    }	}    }        protected CorbaMessageMediator dispatchToServant(        java.lang.Object servant, 	CorbaMessageMediator req, 	byte[] objectId, ObjectAdapter objectAdapter)     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".dispatchToServant->: " + opAndId(req));	    }	    CorbaMessageMediator response = null ;	    String operation = req.getOperationName() ;	    SpecialMethod method = SpecialMethod.getSpecialMethod(operation) ;	    if (method != null) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatchToServant: " + opAndId(req)			   + ": Handling special method");		}		response = method.invoke(servant, req, objectId, objectAdapter);		return response ;	    } 	    	    // Invoke on the servant using the portable DSI skeleton	    if (servant instanceof org.omg.CORBA.DynamicImplementation) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatchToServant: " + opAndId(req)			   + ": Handling old style DSI type servant");		}		org.omg.CORBA.DynamicImplementation dynimpl = 		    (org.omg.CORBA.DynamicImplementation)servant;		ServerRequestImpl sreq = new ServerRequestImpl(req, orb);		// Note: When/if dynimpl.invoke calls arguments() or		// set_exception() then intermediate points are run.		dynimpl.invoke(sreq);				response = handleDynamicResult(sreq, req);	    } else if (servant instanceof org.omg.PortableServer.DynamicImplementation) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatchToServant: " + opAndId(req)			   + ": Handling POA DSI type servant");		}		org.omg.PortableServer.DynamicImplementation dynimpl = 		    (org.omg.PortableServer.DynamicImplementation)servant;		ServerRequestImpl sreq = new ServerRequestImpl(req, orb);		// Note: When/if dynimpl.invoke calls arguments() or		// set_exception() then intermediate points are run.		dynimpl.invoke(sreq);				response = handleDynamicResult(sreq, req);	    } else {		if (orb.subcontractDebugFlag) {		    dprint(".dispatchToServant: " + opAndId(req)			   + ": Handling invoke handler type servant");		}		InvokeHandler invhandle = (InvokeHandler)servant ;		OutputStream stream =		    (OutputStream)invhandle._invoke(                      operation, 		      (org.omg.CORBA.portable.InputStream)req.getInputObject(),		      req);		response = (CorbaMessageMediator) 		    ((OutputObject)stream).getMessageMediator();	    }	    return response ;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".dispatchToServant<-: " + opAndId(req));	    }	}    }    protected CorbaMessageMediator handleDynamicResult(        ServerRequestImpl sreq,	CorbaMessageMediator req)     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".handleDynamicResult->: " + opAndId(req));	    }	    CorbaMessageMediator response = null ;	    // Check if ServerRequestImpl.result() has been called	    Any excany = sreq.checkResultCalled();	    if (excany == null) { // normal return		if (orb.subcontractDebugFlag) {		    dprint(".handleDynamicResult: " + opAndId(req)			   + ": handling normal result");		}		// Marshal out/inout/return parameters into the ReplyMessage		response = sendingReply(req);		OutputStream os = (OutputStream) response.getOutputObject();		sreq.marshalReplyParams(os);	    }  else {		if (orb.subcontractDebugFlag) {		    dprint(".handleDynamicResult: " + opAndId(req) 			   + ": handling error");		}		response = sendingReply(req, excany);	    }	    return response ;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".handleDynamicResult<-: " + opAndId(req));	    }	}    }    protected CorbaMessageMediator sendingReply(CorbaMessageMediator req)    {	try {	    if (orb.subcontractDebugFlag) {		dprint(".sendingReply->: " + opAndId(req));	    }	    ServiceContexts scs = new ServiceContexts(orb);	    return req.getProtocolHandler().createResponse(req, scs);	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".sendingReply<-: " + opAndId(req));	    }	}    }    /** Must always be called, just after the servant's method returns.     *  Creates the ReplyMessage header and puts in the transaction context     *  if necessary.     */    protected CorbaMessageMediator sendingReply(CorbaMessageMediator req, Any excany)    { 	try {	    if (orb.subcontractDebugFlag) {		dprint(".sendingReply/Any->: " + opAndId(req));	    }	    ServiceContexts scs = new ServiceContexts(orb);	    // Check if the servant set a SystemException or	    // UserException	    CorbaMessageMediator resp;	    String repId=null;	    try {		repId = excany.type().id();	    } catch (org.omg.CORBA.TypeCodePackage.BadKind e) {		throw wrapper.problemWithExceptionTypecode( e ) ;	    }	    if (ORBUtility.isSystemException(repId)) {		if (orb.subcontractDebugFlag) {		    dprint(".sendingReply/Any: " + opAndId(req)			   + ": handling system exception");		}		// Get the exception object from the Any		InputStream in = excany.create_input_stream();		SystemException ex = ORBUtility.readSystemException(in);		// Marshal the exception back		resp = req.getProtocolHandler()		    .createSystemExceptionResponse(req, ex, scs);	    } else {		if (orb.subcontractDebugFlag) {		    dprint(".sendingReply/Any: " + opAndId(req)			   + ": handling user exception");		}		resp = req.getProtocolHandler()		    .createUserExceptionResponse(req, scs);		OutputStream os = (OutputStream)resp.getOutputObject();		excany.write_value(os);	    }	    return resp;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".sendingReply/Any<-: " + opAndId(req));	    }	}    }    /**     * Handles setting the connection's code sets if required.     * Returns true if the CodeSetContext was in the request, false     * otherwise.     */    protected boolean processCodeSetContext(	CorbaMessageMediator request, ServiceContexts contexts)     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".processCodeSetContext->: " + opAndId(request));	    }	    ServiceContext sc = contexts.get( 		CodeSetServiceContext.SERVICE_CONTEXT_ID);	    if (sc != null) {		// Somehow a code set service context showed up in the local case.		if (request.getConnection() == null) {		    return true;		}		// If it's GIOP 1.0, it shouldn't have this context at all.  Our legacy		// ORBs sent it and we need to know if it's here to make ORB versioning		// decisions, but we don't use the contents.		if (request.getGIOPVersion().equals(GIOPVersion.V1_0)) {		    return true;		}		CodeSetServiceContext cssc = (CodeSetServiceContext)sc ;		CodeSetComponentInfo.CodeSetContext csctx = cssc.getCodeSetContext();		// Note on threading:		//		// getCodeSetContext and setCodeSetContext are synchronized		// on the Connection.  At worst, this will result in 		// multiple threads entering this block and calling 		// setCodeSetContext but not actually changing the		// values on the Connection.		//		// Alternative would be to lock the connection for the		// whole block, but it's fine either way.		// The connection's codeSetContext is null until we've received a		// request with a code set context with the negotiated code sets.		if (((CorbaConnection)request.getConnection())		    .getCodeSetContext() == null)                 {		    // Use these code sets on this connection		    if (orb.subcontractDebugFlag) {			dprint(".processCodeSetContext: " + opAndId(request)			       + ": Setting code sets to: " + csctx);		    }		    ((CorbaConnection)request.getConnection())			.setCodeSetContext(csctx);		    // We had to read the method name using ISO 8859-1		    // (which is the default in the CDRInputStream for		    // char data), but now we may have a new char		    // code set.  If it isn't ISO8859-1, we must tell		    // the CDR stream to null any converter references		    // it has created so that it will reacquire		    // the code sets again using the new info.		    //		    // This should probably compare with the stream's		    // char code set rather than assuming it's ISO8859-1.		    // (However, the operation name is almost certainly		    // ISO8859-1 or ASCII.)		    if (csctx.getCharCodeSet() != 			OSFCodeSetRegistry.ISO_8859_1.getNumber()) {			((MarshalInputStream)request.getInputObject())			    .resetCodeSetConverters();		    }		}	    }	    // If no code set information is ever sent from the client,	    // the server will use ISO8859-1 for char and throw an	    // exception for any wchar transmissions.	    //	    // In the local case, we use ORB provided streams for	    // marshaling and unmarshaling.  Currently, they use	    // ISO8859-1 for char/string and UTF16 for wchar/wstring.	    return sc != null ;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".processCodeSetContext<-: " + opAndId(request));	    }	}    }    protected void dprint(String msg)    {        ORBUtility.dprint("CorbaServerRequestDispatcherImpl", msg);    }    protected String opAndId(CorbaMessageMediator mediator)    {	return ORBUtility.operationNameAndRequestId(mediator);    }}// End of file.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -