Package org.jacorb.orb.portableInterceptor

Examples of org.jacorb.orb.portableInterceptor.ServerRequestInfoImpl


     * the main request processing routine
     */

    private void process()
    {
        ServerRequestInfoImpl info = null;

        // Notify parties interested in using information about a Transport
        controller.getORB().notifyTransportListeners(request.getConnection());

        if (controller.getORB().hasServerRequestInterceptors())
        {
            //RequestInfo attributes
            info = new ServerRequestInfoImpl(controller.getORB(),
                                             request,
                                             servant);

            InterceptorManager manager = controller.getORB().getInterceptorManager();
            info.setCurrent (manager.getEmptyCurrent());

            if(! invokeInterceptors( info,
                                     ServerInterceptorIterator.
                                     RECEIVE_REQUEST_SERVICE_CONTEXTS))
            {
                //an interceptor bailed out, so don't continue request
                //processing and return here. The service contexts for
                //the result have to be set, of course.
                ReplyOutputStream out = request.getReplyOutputStream();
                Enumeration ctx = info.getReplyServiceContexts();

                while( ctx.hasMoreElements() )
                {
                    out.addServiceContext( (ServiceContext) ctx.nextElement() );
                }

                return;
            }

            manager.setTSCurrent(info.current());
        }

        // TODO: The exception replies below should also trigger interceptors.
        // Requires some re-arranging of the entire method.
        if (Time.hasPassed (request.getRequestEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Request End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }
        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }

        Time.waitFor (request.getRequestStartTime());

        if (servantManager != null)
        {
            if (servantManager instanceof org.omg.PortableServer.ServantActivator)
            {
                invokeIncarnate();
            }
            else
            {
                invokePreInvoke();
            }
        }

        if (servant != null)
        {
            if (info != null)
            {
                info.setServant(servant);

                if (servant instanceof org.omg.CORBA.portable.InvokeHandler)
                {
                    if(! invokeInterceptors(info,
                                            ServerInterceptorIterator.RECEIVE_REQUEST ))
                    {
                        //an interceptor bailed out, so don't continue
                        //request processing and return here. The
                        //service contexts for the result have to be
                        //set, of course.

                        if( cookieHolder != null )
                        {
                            invokePostInvoke();
                        }

                        ReplyOutputStream out =
                            request.getReplyOutputStream();
                        Enumeration ctx =
                            info.getReplyServiceContexts();

                        while( ctx.hasMoreElements() )
                        {
                            out.addServiceContext( (ServiceContext) ctx.nextElement() );
                        }

                        return;
                    }
                }
                else if (servant instanceof org.omg.PortableServer.DynamicImplementation)
                {
                    request.setServerRequestInfo(info);
                }
            }

            invokeOperation();
        }

        // preinvoke and postinvoke are always called in pairs
        // but what happens if the servant is null

        if (cookieHolder != null)
        {
            invokePostInvoke();
        }

        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded after invocation",
                                            0, CompletionStatus.COMPLETED_YES));
        }

        if (info != null)
        {
            InterceptorManager manager =
                controller.getORB().getInterceptorManager();
            info.setCurrent (manager.getCurrent());

            short op = 0;
            switch(request.status().value())
            {
                case ReplyStatusType_1_2._NO_EXCEPTION :
                    op = ServerInterceptorIterator.SEND_REPLY;
                    info.setReplyStatus (SUCCESSFUL.value);
                    break;

                case ReplyStatusType_1_2._USER_EXCEPTION :
                    info.setReplyStatus (USER_EXCEPTION.value);
                    SystemExceptionHelper.insert(info.sending_exception,
                                                 new org.omg.CORBA.UNKNOWN("Stream-based UserExceptions are not available!"));
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                case ReplyStatusType_1_2._SYSTEM_EXCEPTION :
                    info.setReplyStatus (SYSTEM_EXCEPTION.value);
                    SystemExceptionHelper.insert(info.sending_exception,
                                                 request.getSystemException());
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                case ReplyStatusType_1_2._LOCATION_FORWARD :
                    info.setReplyStatus (LOCATION_FORWARD.value);
                    op = ServerInterceptorIterator.SEND_OTHER;
                    break;
            }

            invokeInterceptors(info, op);

            ReplyOutputStream out =
                request.get_out();
            Enumeration ctx =
                info.getReplyServiceContexts();

            while( ctx.hasMoreElements() )
            {
                out.addServiceContext( (ServiceContext) ctx.nextElement() );
            }
View Full Code Here


     * the main request processing routine
     */

    private void process()
    {
        ServerRequestInfoImpl info = null;

        // Notify parties interested in using information about a Transport
        controller.getORB().notifyTransportListeners(request.getConnection());

        if (controller.getORB().hasServerRequestInterceptors())
        {
            //RequestInfo attributes
            info = new ServerRequestInfoImpl(controller.getORB(),
                                             request,
                                             servant);

            InterceptorManager manager = controller.getORB().getInterceptorManager();
            info.setCurrent (manager.getEmptyCurrent());

            if(! invokeInterceptors( info,
                                     ServerInterceptorIterator.
                                     RECEIVE_REQUEST_SERVICE_CONTEXTS))
            {
                //an interceptor bailed out, so don't continue request
                //processing and return here. The service contexts for
                //the result have to be set, of course.
                ReplyOutputStream out = request.getReplyOutputStream();
                Enumeration ctx = info.getReplyServiceContexts();

                while( ctx.hasMoreElements() )
                {
                    out.addServiceContext( (ServiceContext) ctx.nextElement() );
                }

                return;
            }

            manager.setTSCurrent(info.current());
        }

        // TODO: The exception replies below should also trigger interceptors.
        // Requires some re-arranging of the entire method.
        if (Time.hasPassed (request.getRequestEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Request End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }
        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }

        Time.waitFor (request.getRequestStartTime());

        if (servantManager != null)
        {
            if (servantManager instanceof org.omg.PortableServer.ServantActivator)
            {
                invokeIncarnate();
            }
            else
            {
                invokePreInvoke();
            }
        }

        if (servant != null)
        {
            if (info != null)
            {
                info.setServant(servant);

                if (servant instanceof org.omg.CORBA.portable.InvokeHandler)
                {
                    if(! invokeInterceptors(info,
                                            ServerInterceptorIterator.RECEIVE_REQUEST ))
                    {
                        //an interceptor bailed out, so don't continue
                        //request processing and return here. The
                        //service contexts for the result have to be
                        //set, of course.

                        if( cookieHolder != null )
                        {
                            invokePostInvoke();
                        }

                        ReplyOutputStream out =
                            request.getReplyOutputStream();
                        Enumeration ctx =
                            info.getReplyServiceContexts();

                        while( ctx.hasMoreElements() )
                        {
                            out.addServiceContext( (ServiceContext) ctx.nextElement() );
                        }

                        return;
                    }
                }
                else if (servant instanceof org.omg.PortableServer.DynamicImplementation)
                {
                    request.setServerRequestInfo(info);
                }
            }

            invokeOperation();
        }

        // preinvoke and postinvoke are always called in pairs
        // but what happens if the servant is null

        if (cookieHolder != null)
        {
            invokePostInvoke();
        }

        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded after invocation",
                                            0, CompletionStatus.COMPLETED_YES));
        }

        if (info != null)
        {
            InterceptorManager manager =
                controller.getORB().getInterceptorManager();
            info.setCurrent (manager.getCurrent());

            short op = 0;
            switch(request.status().value())
            {
                case ReplyStatusType_1_2._NO_EXCEPTION :
                    op = ServerInterceptorIterator.SEND_REPLY;
                    info.setReplyStatus (SUCCESSFUL.value);
                    break;

                case ReplyStatusType_1_2._USER_EXCEPTION :
                    info.setReplyStatus (USER_EXCEPTION.value);
                    SystemExceptionHelper.insert(info.sending_exception,
                                                 new org.omg.CORBA.UNKNOWN("Stream-based UserExceptions are not available!"));
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                case ReplyStatusType_1_2._SYSTEM_EXCEPTION :
                    info.setReplyStatus (SYSTEM_EXCEPTION.value);
                    SystemExceptionHelper.insert(info.sending_exception,
                                                 request.getSystemException());
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                case ReplyStatusType_1_2._LOCATION_FORWARD :
                    info.setReplyStatus (LOCATION_FORWARD.value);
                    op = ServerInterceptorIterator.SEND_OTHER;
                    break;
            }

            invokeInterceptors(info, op);

            ReplyOutputStream out =
                request.get_out();
            Enumeration ctx =
                info.getReplyServiceContexts();

            while( ctx.hasMoreElements() )
            {
                out.addServiceContext( (ServiceContext) ctx.nextElement() );
            }
View Full Code Here

     * the main request processing routine
     */

    private void process()
    {
        ServerRequestInfoImpl info = null;

        // Notify parties interested in using information about a Transport
        controller.getORB().notifyTransportListeners(request.getConnection());

        if (controller.getORB().hasServerRequestInterceptors())
        {
            //RequestInfo attributes
            info = new ServerRequestInfoImpl(controller.getORB(),
                                             request,
                                             servant);

            InterceptorManager manager = controller.getORB().getInterceptorManager();
            info.setCurrent (manager.getEmptyCurrent());

            if(! invokeInterceptors( info,
                                     ServerInterceptorIterator.
                                     RECEIVE_REQUEST_SERVICE_CONTEXTS))
            {
                //an interceptor bailed out, so don't continue request
                //processing and return here. The service contexts for
                //the result have to be set, of course.
                ReplyOutputStream out = request.getReplyOutputStream();
                Enumeration ctx = info.getReplyServiceContexts();

                while( ctx.hasMoreElements() )
                {
                    out.addServiceContext( (ServiceContext) ctx.nextElement() );
                }

                return;
            }

            manager.setTSCurrent(info.current());
        }

        // TODO: The exception replies below should also trigger interceptors.
        // Requires some re-arranging of the entire method.
        if (Time.hasPassed (request.getRequestEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Request End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }
        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }

        Time.waitFor (request.getRequestStartTime());

        if (servantManager != null)
        {
            if (servantManager instanceof org.omg.PortableServer.ServantActivator)
            {
                invokeIncarnate();
            }
            else
            {
                invokePreInvoke();
            }
        }

        if (servant != null)
        {
            if (info != null)
            {
                info.setServant(servant);

                if (servant instanceof org.omg.CORBA.portable.InvokeHandler)
                {
                    if(! invokeInterceptors(info,
                                            ServerInterceptorIterator.RECEIVE_REQUEST ))
                    {
                        //an interceptor bailed out, so don't continue
                        //request processing and return here. The
                        //service contexts for the result have to be
                        //set, of course.

                        if( cookieHolder != null )
                        {
                            invokePostInvoke();
                        }

                        ReplyOutputStream out =
                            request.getReplyOutputStream();
                        Enumeration ctx =
                            info.getReplyServiceContexts();

                        while( ctx.hasMoreElements() )
                        {
                            out.addServiceContext( (ServiceContext) ctx.nextElement() );
                        }

                        return;
                    }
                }
                else if (servant instanceof org.omg.PortableServer.DynamicImplementation)
                {
                    request.setServerRequestInfo(info);
                }
            }

            invokeOperation();
        }

        // preinvoke and postinvoke are always called in pairs
        // but what happens if the servant is null

        if (cookieHolder != null)
        {
            invokePostInvoke();
        }

        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded after invocation",
                                            0, CompletionStatus.COMPLETED_YES));
        }

        if (info != null)
        {
            InterceptorManager manager =
                controller.getORB().getInterceptorManager();
            info.setCurrent (manager.getCurrent());

            short op = 0;
            switch(request.status().value())
            {
                case ReplyStatusType_1_2._NO_EXCEPTION :
                    op = ServerInterceptorIterator.SEND_REPLY;
                    info.setReplyStatus (SUCCESSFUL.value);
                    break;

                case ReplyStatusType_1_2._USER_EXCEPTION :
                    info.setReplyStatus (USER_EXCEPTION.value);
                    SystemExceptionHelper.insert(info.sending_exception,
                                                 new org.omg.CORBA.UNKNOWN("Stream-based UserExceptions are not available!"));
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                case ReplyStatusType_1_2._SYSTEM_EXCEPTION :
                    info.setReplyStatus (SYSTEM_EXCEPTION.value);
                    SystemExceptionHelper.insert(info.sending_exception,
                                                 request.getSystemException());
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                case ReplyStatusType_1_2._LOCATION_FORWARD :
                    info.setReplyStatus (LOCATION_FORWARD.value);
                    op = ServerInterceptorIterator.SEND_OTHER;
                    break;
            }

            invokeInterceptors(info, op);

            ReplyOutputStream out =
                request.get_out();
            Enumeration ctx =
                info.getReplyServiceContexts();

            while( ctx.hasMoreElements() )
            {
                out.addServiceContext( (ServiceContext) ctx.nextElement() );
            }
View Full Code Here

    {
        try
        {
            if (orb.hasRequestInterceptors())
            {
                ServerRequestInfoImpl sinfo = ( (ServantObjectImpl) servant).getServerRequestInfo();

                DefaultClientInterceptorHandler interceptors =
                    ( (ServantObjectImpl) servant).getClientInterceptorHandler();

                if (sinfo != null && interceptors != null)
                {
                    Collection<ServiceContext> ctx = sinfo.getReplyServiceContexts();
                    interceptors.getInfo ().setReplyServiceContexts (ctx.toArray (new ServiceContext[ctx.size ()]));
                    orb.getInterceptorManager().removeLocalPICurrent();

                    try
                    {
                        if (sinfo.reply_status() == SUCCESSFUL.value)
                        {
                            interceptors.handle_receive_reply (null);
                        }
                        else if (sinfo.reply_status() == SYSTEM_EXCEPTION.value)
                        {
                            interceptors.handle_receive_exception (
                                SystemExceptionHelper.read (sinfo.sending_exception().create_input_stream()));
                        }
                        else if (sinfo.reply_status() == LOCATION_FORWARD.value)
                        {
                            /**
                             * If the ForwardRequest was thrown at the send_exception interception
                             * point we will not be able to get the forward_reference from the
                             * server info and a BAD_INV_ORDER will be thrown.  In that case handle
                             * as a simple receive_other.
                             */
                            try
                            {
                                interceptors.handle_location_forward (null, sinfo.forward_reference());
                            }
                            catch (BAD_INV_ORDER bio)
                            {
                                interceptors.handle_receive_other(sinfo.reply_status());
                            }
                        }
                        else if (sinfo.reply_status() == USER_EXCEPTION.value)
                        {
                            interceptors.handle_receive_other (sinfo.reply_status());
                        }
                    }
                    catch (ForwardRequest fwd)
                    {
                        throw new RuntimeException (fwd);
View Full Code Here

                                            String operation,
                                            @SuppressWarnings("rawtypes") Class expectedType )
    {
        InterceptorManager manager = null;
        ServerInterceptorIterator interceptorIterator = null;
        ServerRequestInfoImpl sinfo = null;
        Collection<ServiceContext> contexts = null;
        DefaultClientInterceptorHandler interceptors = null;
        boolean addedContext = false;

        if (poa == null)
        {
            resolvePOA(self);
        }

        if (poa == null)
        {
            if (logger.isWarnEnabled())
            {
                logger.warn("No POA! servant_preinvoke returns null");
            }

            return null;
        }

        Map<INVOCATION_KEY, UtcT> currentContext = new HashMap<INVOCATION_KEY, UtcT>();
        currentContext.put (INVOCATION_KEY.SERVANT_PREINVOKE, null);

        invocationContext.get().push (currentContext);

        // remember that a local request is outstanding. On
        // any exit through an exception, this must be cleared again,
        // otherwise the POA will hangon destruction (bug #400).
        poa.addLocalRequest();

        final ServantObject servantObject = new ServantObjectImpl();

        ( (ServantObjectImpl) servantObject).setORB (orb);

        try
        {
            if (orb.hasClientRequestInterceptors())
            {
                interceptors = new DefaultClientInterceptorHandler(orb,
                                                                   operation,
                                                                   true,
                                                                   SYNC_WITH_TARGET.value,
                                                                   self,
                                                                   this,
                                                                   piorOriginal);
            }

            if (orb.hasRequestInterceptors() && interceptors != null)
            {
                try
                {
                    interceptors.handle_send_request();
                }
                catch (ForwardRequest fwd)
                {
                    ( (ObjectImpl) self)._set_delegate ( ( (ObjectImpl) fwd.forward)._get_delegate());
                    return null;
                }
                catch (RemarshalException re)
                {
                    // Should not happen for a local server invocation.
                }
            }

            if (interceptors != null)
            {
                contexts = interceptors.getInfo().getRequestServiceContexts();
            }

            if (orb.hasServerRequestInterceptors())
            {
                sinfo = new ServerRequestInfoImpl
                (
                    orb,
                    contexts,
                    (org.omg.PortableServer.Servant) servantObject.servant,
                    getObjectId(),
                    operation,
                    true,
                    SYNC_WITH_TARGET.value
                );

                manager = orb.getInterceptorManager();
                sinfo.setCurrent (manager.getEmptyCurrent());
                interceptorIterator = manager.getServerIterator();

                ( (org.jacorb.orb.ServantObjectImpl ) servantObject).setServerRequestInfo (sinfo);

                // Note: this code is very similar to the below hasServerRequestInterceptors try/catch
                try
                {
                   manager.setLocalPICurrent (sinfo.current ());

                   interceptorIterator.iterate
                   (
                       sinfo,
                       ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS
                   );
                }
                catch (ForwardRequest fwd)
                {
                    if (interceptors != null)
                    {
                        interceptors.handle_location_forward (null, fwd.forward);
                    }

                    ( (ObjectImpl) self)._set_delegate ( ( (ObjectImpl) fwd.forward)._get_delegate());
                    return null;
                }
                catch (Exception ex)
                {
                    if (interceptors != null && orb.hasRequestInterceptors())
                    {
                        manager.removeLocalPICurrent ();

                        try
                        {
                            if (ex instanceof SystemException)
                            {
                                interceptors.handle_receive_exception ( (SystemException) ex);
                            }
                            else if (ex instanceof ApplicationException)
                            {
                                interceptors.handle_receive_exception ( (ApplicationException) ex, null);
                            }
                        }
                        catch (ForwardRequest fwd)
                        {
                            ( (ObjectImpl) self)._set_delegate ( ( (ObjectImpl) fwd.forward)._get_delegate());
                            return null;
                        }
                    }

                    throw ex;
                }
            }

            try
            {
                if ( ( poa.isRetain() && !poa.isUseServantManager() ) ||
                     poa.useDefaultServant() )
                {
                    // no ServantManagers, but AOM use
                    try
                    {
                       servantObject.servant = poa.reference_to_servant( self );
                    }
                    catch( WrongAdapter e )
                    {
                        throw new OBJ_ADAPTER( "WrongAdapter caught when converting servant to reference. " + e );
                    }
                    catch( WrongPolicy e )
                    {
                        throw new OBJ_ADAPTER("WrongPolicy caught" + e );
                    }
                    catch( ObjectNotActive e )
                    {
                        throw new org.omg.CORBA.OBJECT_NOT_EXIST();
                    }
                }
                else if ( poa.isUseServantManager() )
                {
                    byte [] oid =
                    POAUtil.extractOID( getParsedIOR().get_object_key() );
                    org.omg.PortableServer.ServantManager sm = poa.get_servant_manager();

                    if ( poa.isRetain() )
                    {
                        // ServantManager is a ServantActivator. Use the AOM to
                        // incarnate this or return the servant. It will correctly
                        // synchrnoize the requests.
                        servantObject.servant = poa._incarnateServant(oid, (ServantActivator)sm);
                    }
                    else
                    {
                        // ServantManager is a ServantLocator: locate a servant
                        org.omg.PortableServer.ServantLocator sl =
                            ( org.omg.PortableServer.ServantLocator ) sm;

                        // store this for postinvoke

                        cookie = new org.omg.PortableServer.ServantLocatorPackage.CookieHolder();

                        invokedOperation = operation;

                        servantObject.servant = sl.preinvoke( oid, poa, operation, cookie );
                    }
                    ((org.omg.CORBA_2_3.ORB)orb).set_delegate(servantObject.servant);
                }
                else
                {
                    throw new INTERNAL("Internal error: we should not have got to this piece of code!");
                }
            }
            catch( WrongPolicy e )
            {
                throw new OBJ_ADAPTER( "WrongPolicy caught" + e );
            }
            catch( org.omg.PortableServer.ForwardRequest e )
            {
                if( logger.isDebugEnabled() )
                {
                    logger.debug("Caught forwardrequest to " + e.forward_reference + " from " + self );
                }
                ( (ObjectImpl) self)._set_delegate ( ( (ObjectImpl) e.forward_reference)._get_delegate());

                return null;
            }

            if ( !expectedType.isInstance( servantObject.servant ) )
            {
                if( logger.isWarnEnabled() )
                {
                    logger.warn("Expected " + expectedType +
                                " got " + servantObject.servant.getClass() );
                }

                ignoreNextCallToIsLocal.set(Boolean.TRUE);

                poa.removeLocalRequest();
                return null;
            }


            orb.getPOACurrent()._addContext
            (
                Thread.currentThread(),
                new org.jacorb.poa.LocalInvocationContext
                (
                    orb,
                    poa,
                    getObjectId(),
                    ( org.omg.PortableServer.Servant ) servantObject.servant
                )
            );
            addedContext = true;

            ( (org.jacorb.orb.ServantObjectImpl )servantObject).setClientInterceptorHandler (interceptors);

            if (orb.hasServerRequestInterceptors())
            {
                sinfo =  ( (org.jacorb.orb.ServantObjectImpl ) servantObject).getServerRequestInfo();
                sinfo.setServant((org.omg.PortableServer.Servant) servantObject.servant);

                interceptorIterator = manager.getServerIterator();

                ( (org.jacorb.orb.ServantObjectImpl ) servantObject).setServerRequestInfo (sinfo);

                // Note: this code is very similar to the above hasServerRequestInterceptors try/catch
                try
                {
                   manager.setLocalPICurrent (sinfo.current ());

                   interceptorIterator.iterate
                   (
                       sinfo,
                       ServerInterceptorIterator.RECEIVE_REQUEST
                   );
                }
                catch (ForwardRequest fwd)
                {
                    if (interceptors != null)
                    {
                        interceptors.handle_location_forward (null, fwd.forward);
                    }

                    ( (ObjectImpl) self)._set_delegate ( ( (ObjectImpl) fwd.forward)._get_delegate());
                    return null;
                }
                catch (Exception ex)
                {
                    Collection<ServiceContext> ctx = sinfo.getReplyServiceContexts();
                    interceptors.getInfo ().setReplyServiceContexts (ctx.toArray (new ServiceContext[ctx.size ()]));
                    manager.removeLocalPICurrent ();

                    if (interceptors != null && orb.hasRequestInterceptors())
                    {
View Full Code Here

    }

    public void receive_request( ServerRequestInfo sri )
        throws ForwardRequest
    {
        ServerRequestInfoImpl ri = ((ServerRequestInfoImpl)sri);

        if (logger.isDebugEnabled())
            logger.debug("receive_request for "+ri.operation());

        if (sasContext == null || ri.isLocalInterceptor())
        {
            return;
        }

        GIOPConnection connection = ri.getConnection();

        // check policy
        SASPolicyValues sasValues = null;
        try
        {
            ObjectImpl oi =
                (ObjectImpl)ri.target();
            org.jacorb.orb.Delegate d =
                (org.jacorb.orb.Delegate)oi._get_delegate();
            SASPolicy policy =
                (SASPolicy)d.getPOA().getPolicy(SAS_POLICY_TYPE.value);
            if (policy != null)
                sasValues = policy.value();
        }
        catch (BAD_PARAM e)
        {
            if (logger.isDebugEnabled())
                logger.debug("No SAS Policy for "+ri.operation());
        }
        catch (Exception e)
        {
            if (logger.isWarnEnabled())
                logger.warn("Error fetching SAS policy for "+
                            ri.operation()+": "+e);
            throw new org.omg.CORBA.NO_PERMISSION("Error fetching SAS policy: "+e,
                                                  MinorCodes.SAS_TSS_FAILURE,
                                                  CompletionStatus.COMPLETED_NO);
        }
        if (sasValues == null)
            return;
        if (sasValues.targetRequires == 0 && sasValues.targetSupports == 0)
            return;

        ATLASPolicyValues atlasValues = null;
        try
        {
            ObjectImpl oi = (ObjectImpl)ri.target();
            org.jacorb.orb.Delegate d = (org.jacorb.orb.Delegate)oi._get_delegate();
            ATLASPolicy policy = (ATLASPolicy)d.getPOA().getPolicy(ATLAS_POLICY_TYPE.value);
            if (policy != null)
                atlasValues = policy.value();
        }
        catch (BAD_PARAM e)
        {
            if (logger.isDebugEnabled())
                logger.debug("No ATLAS Policy for "+ri.operation());
        }
        catch (Exception e)
        {
            if (logger.isWarnEnabled())
                logger.warn("Error fetching ATLAS policy for "+
                            ri.operation()+": "+e);
            throw new org.omg.CORBA.NO_PERMISSION("Error fetching ATLAS policy: "+e,
                                                  MinorCodes.SAS_TSS_FAILURE,
                                                  CompletionStatus.COMPLETED_NO);
        }

        // parse service context
        SASContextBody contextBody = null;
        long client_context_id = 0;
        byte[] contextToken = null;
        try
        {
            ServiceContext ctx =
                ri.get_request_service_context(SASInitializer.SecurityAttributeService);
            Any ctx_any =
                codec.decode_value( ctx.context_data, SASContextBodyHelper.type() );
            contextBody =
                SASContextBodyHelper.extract(ctx_any);
        }
        catch (BAD_PARAM e)
        {
            if (logger.isDebugEnabled())
                logger.debug("Could not parse service context for operation " +
                         ri.operation());
        }
        catch (Exception e)
        {
            if (logger.isWarnEnabled())
                logger.warn("Could not parse service context for operation " +
                        ri.operation() + ": " + e);
        }

        if (contextBody == null &&
           (sasValues.targetRequires & org.omg.CSIIOP.EstablishTrustInClient.value) != 0 &&
           !ri.operation().equals("_non_existent") &&
           !ri.operation().equals("_is_a"))
        {
            if (logger.isErrorEnabled())
                logger.error("Did not parse service context for operation " +
                         ri.operation());
            throw new org.omg.CORBA.NO_PERMISSION("No SAS service context found",
                                                  MinorCodes.SAS_TSS_FAILURE,
                                                  CompletionStatus.COMPLETED_NO);
        }
        if (contextBody == null)
        {
            if (logger.isDebugEnabled())
                logger.debug("No context found, but not required");
            return;
        }

        // process MessageInContext
        if (contextBody.discriminator() == MTMessageInContext.value)
        {
            MessageInContext msg = null;
            try
            {
                msg = contextBody.in_context_msg();
                client_context_id = msg.client_context_id;
                contextToken = getSASContext(connection, msg.client_context_id);
            }
            catch (Exception e)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not parse service MessageInContext " +
                                 ri.operation() + ": " + e);
                makeContextError(ri, client_context_id, 1, 1, contextToken);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Error parsing MessageInContext: " + e,
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
            if (contextToken == null)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not find context in MessageInContext " +
                                 ri.operation() + ": " + msg.client_context_id);
                makeContextError(ri, client_context_id, 2, 1, contextToken);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Error invalid context in MessageInContext",
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
        }

        // process EstablishContext
        if (contextBody.discriminator() == MTEstablishContext.value)
        {
            EstablishContext msg = null;
            String principalName = null;
            try
            {
                msg = contextBody.establish_msg();
                client_context_id = msg.client_context_id;
                contextToken = msg.client_authentication_token;

                principalName = sasContext.getValidatedPrincipal();
            }
            catch (org.omg.CORBA.NO_PERMISSION e)
            {
                if (logger.isErrorEnabled())
                    logger.error("Err " + ri.operation() + ": " + e);
                makeContextError(ri, client_context_id, 1, 1, contextToken);
                throw e;
            }
            catch (Exception e)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not parse service EstablishContext " +
                                 ri.operation() + ": " + e);
                makeContextError(ri, client_context_id, 2, 1, contextToken);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Error parsing EstablishContext: " + e,
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
            if (contextToken == null)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not parse service EstablishContext " +
                                 ri.operation() + ": " + msg.client_context_id);
                makeContextError(ri, client_context_id, 2, 1, contextToken);

                throw new org.omg.CORBA.NO_PERMISSION("SAS Error parsing EstablishContext",
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }

            // cache context
            if (sasValues.stateful)
                cacheSASContext(connection, msg.client_context_id,
                                contextToken, principalName);
        }

        // set slots
        try
        {
            makeCompleteEstablishContext(ri, client_context_id, sasValues);
        }
        catch (Exception e)
        {
            if (logger.isErrorEnabled())
                logger.error("Error inserting service context into slots for " +
                             ri.operation() + ": " + e);
            makeContextError(ri, client_context_id, 1, 1, contextToken);
            throw new org.omg.CORBA.NO_PERMISSION("SAS Error insert service context into slots: " + e, MinorCodes.SAS_TSS_FAILURE, CompletionStatus.COMPLETED_NO);
        }
    }
View Full Code Here

    }

    public void receive_request_service_contexts( ServerRequestInfo sri )
        throws ForwardRequest
    {
        ServerRequestInfoImpl ri = ((ServerRequestInfoImpl)sri);

        if (logger.isDebugEnabled())
            logger.debug("receive_request_service_contexts for " + ri.operation());

          // First check whether the target is interested in SAS at all
          Policy targetSasPolicy = null;
          try {
            targetSasPolicy = ri.get_server_policy(SAS_POLICY_TYPE.value);
          }
          catch(Exception ex) {
          }

          if( targetSasPolicy == null ) {
            // No such policy exist on the target object so there is no point in attempting to call the validateContext
            // since the target didn't ask for it
            return;
          }

        if (sasContext == null || ri.isLocalInterceptor())
        {
            return;
        }

        GIOPConnection connection = ri.getConnection();

        // verify SSL requirements
        if (useSsl && !connection.isSSL())
        {
            if (logger.isErrorEnabled())
                logger.error("SSL required for operation " + ri.operation());
            throw new org.omg.CORBA.NO_PERMISSION("SSL Required!",
                                                  MinorCodes.SAS_TSS_FAILURE,
                                                  CompletionStatus.COMPLETED_NO);
        }

        // parse service context
        SASContextBody contextBody = null;
        long client_context_id = 0;
        byte[] contextToken = null;
        try
        {
            ServiceContext ctx =
                ri.get_request_service_context(SASInitializer.SecurityAttributeService);
            Any ctx_any =
                codec.decode_value( ctx.context_data, SASContextBodyHelper.type() );
            contextBody = SASContextBodyHelper.extract(ctx_any);
        }
        catch (BAD_PARAM e)
        {
        }
        catch (Exception e)
        {
            if (logger.isWarnEnabled())
                logger.warn("Could not parse service context: ", e);
            makeContextError(ri, client_context_id, 1, 1, new byte[0]);
            throw new org.omg.CORBA.NO_PERMISSION("Could not parse service context: " +
                                                  e,
                                                  MinorCodes.SAS_TSS_FAILURE,
                                                  CompletionStatus.COMPLETED_NO);
        }
        if (contextBody == null)
            return;

        // process MessageInContext
        if (contextBody.discriminator() == MTMessageInContext.value)
        {
            MessageInContext msg = null;
            try
            {
                msg = contextBody.in_context_msg();
                client_context_id = msg.client_context_id;
                contextToken = getSASContext(connection, msg.client_context_id);
            }
            catch (Exception e)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not parse service MessageInContext " +
                             ri.operation() + ": " + e);
                makeContextError(ri, client_context_id, 1, 1, new byte[0]);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Error parsing MessageInContext: " +
                                                      e,
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
            if (contextToken == null)
            {
                if (logger.isErrorEnabled())
                    logger.error("Invalid context in MessageInContext " +
                                 ri.operation() + ": " + msg.client_context_id);

                makeContextError(ri, client_context_id, 2, 1, new byte[0]);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Invalid context in MessageInContext",
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
        }

        // process EstablishContext
        String principalName = null;
        if (contextBody.discriminator() == MTEstablishContext.value)
        {
            EstablishContext msg = null;
            try
            {
                msg = contextBody.establish_msg();
                client_context_id = msg.client_context_id;
                contextToken = msg.client_authentication_token;

                if (!sasContext.validateContext(orb, codec, contextToken)) {
                    logger.info("Could not validate context EstablishContext " + ri.operation());
                    makeContextError(ri, client_context_id, 1, 1, contextToken);
                    throw new org.omg.CORBA.NO_PERMISSION("SAS Error validating context",
                                                          MinorCodes.SAS_TSS_FAILURE,
                                                          CompletionStatus.COMPLETED_NO);
                }
                principalName = sasContext.getValidatedPrincipal();
            }
            catch (org.omg.CORBA.NO_PERMISSION e)
            {
                if (logger.isErrorEnabled())
                    logger.error("Err " + ri.operation() + ": " + e);
                makeContextError(ri, client_context_id, 1, 1, contextToken);
                throw e;
            }
            catch (Exception e)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not parse service EstablishContext " +
                                 ri.operation() + ": " + e);
                makeContextError(ri, client_context_id, 1, 1, contextToken);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Error parsing EstablishContext: " +
                                                      e, MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
            if (contextToken == null)
            {
                if (logger.isErrorEnabled())
                    logger.error("Could not parse service EstablishContext " +
                                 ri.operation() + ": " + msg.client_context_id);
                makeContextError(ri, client_context_id, 1, 1, contextToken);
                throw new org.omg.CORBA.NO_PERMISSION("SAS Error parsing EstablishContext",
                                                      MinorCodes.SAS_TSS_FAILURE,
                                                      CompletionStatus.COMPLETED_NO);
            }
        }

        // set slots
        try
        {
            Any nameAny = orb.create_any();
            if (principalName == null)
                principalName =
                    getSASContextPrincipalName(connection, client_context_id);

            nameAny.insert_string(principalName);
            ri.set_slot( SASInitializer.sasPrincipalNamePIC, nameAny);
        }
        catch (Exception e)
        {
            if (logger.isErrorEnabled())
                logger.error("Error inserting service context into slots for " +
                             ri.operation() + ": " + e);
            makeContextError(ri, client_context_id, 1, 1, contextToken);
            throw new org.omg.CORBA.NO_PERMISSION("SAS Error insert service context into slots: " + e,
                                                  MinorCodes.SAS_TSS_FAILURE,
                                                  CompletionStatus.COMPLETED_NO);
        }
View Full Code Here

     */

    private void process()
    {
        final ORB orb = controller.getORB();
        ServerRequestInfoImpl info = null;

        // Notify parties interested in using information about a Transport
        orb.notifyTransportListeners(request.getConnection());

        if (orb.hasServerRequestInterceptors())
        {
            //RequestInfo attributes
            info = new ServerRequestInfoImpl(orb,
                                             request,
                                             servant);

            InterceptorManager manager = orb.getInterceptorManager();
            info.setCurrent (manager.getEmptyCurrent());

            if(! invokeInterceptors( info,
                                     ServerInterceptorIterator.
                                     RECEIVE_REQUEST_SERVICE_CONTEXTS))
            {
                //an interceptor bailed out, so don't continue request
                //processing and return here. The service contexts for
                //the result have to be set, of course.
                ReplyOutputStream out = request.getReplyOutputStream();
                Collection<ServiceContext> ctx = info.getReplyServiceContexts ();

                for (ServiceContext s: ctx)
                {
                    out.addServiceContext(s);
                }

                return;
            }

            manager.setTSCurrent(info.current());
        }

        // TODO: The exception replies below should also trigger interceptors.
        // Requires some re-arranging of the entire method.
        if (Time.hasPassed (request.getRequestEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Request End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }
        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded",
                                            0, CompletionStatus.COMPLETED_NO));
            return;
        }

        Time.waitFor (request.getRequestStartTime());

        if (servantManager != null)
        {
            if (servantManager instanceof org.omg.PortableServer.ServantActivator)
            {
                invokeIncarnate();
            }
            else
            {
                invokePreInvoke();
            }
            ((org.omg.CORBA_2_3.ORB)orb).set_delegate(servant);
        }

        if (servant != null)
        {
            if (info != null)
            {
                info.setServant(servant);

                if (servant instanceof org.omg.CORBA.portable.InvokeHandler)
                {
                    if(! invokeInterceptors(info,
                                            ServerInterceptorIterator.RECEIVE_REQUEST ))
                    {
                        //an interceptor bailed out, so don't continue
                        //request processing and return here. The
                        //service contexts for the result have to be
                        //set, of course.

                        if( cookieHolder != null )
                        {
                            invokePostInvoke();
                        }

                        ReplyOutputStream out = request.getReplyOutputStream();
                        Collection<ServiceContext> ctx = info.getReplyServiceContexts ();

                        for (ServiceContext s: ctx)
                        {
                            out.addServiceContext(s);
                        }

                        return;
                    }
                }
                else if (servant instanceof org.omg.PortableServer.DynamicImplementation)
                {
                    request.setServerRequestInfo(info);
                }
            }

            invokeOperation();
        }

        // preinvoke and postinvoke are always called in pairs
        // but what happens if the servant is null

        if (cookieHolder != null)
        {
            invokePostInvoke();
        }

        if (checkReplyEndTime && Time.hasPassed (request.getReplyEndTime()))
        {
            request.setSystemException
                (new org.omg.CORBA.TIMEOUT ("Reply End Time exceeded after invocation",
                                            0, CompletionStatus.COMPLETED_YES));
        }

        if (info != null)
        {
            InterceptorManager manager =
                orb.getInterceptorManager();
            info.setCurrent (manager.getCurrent());

            short op = 0;
            switch(request.status().value())
            {
                case ReplyStatusType_1_2._NO_EXCEPTION:
                {
                    op = ServerInterceptorIterator.SEND_REPLY;
                    info.setReplyStatus (SUCCESSFUL.value);
                    break;
                }
                case ReplyStatusType_1_2._USER_EXCEPTION:
                {
                    info.setReplyStatus (USER_EXCEPTION.value);
                    Any sendingException = orb.create_any();
                    SystemExceptionHelper.insert(sendingException, new org.omg.CORBA.UNKNOWN("Stream-based UserExceptions are not available!"));
                    info.sending_exception(sendingException);
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;
                }
                case ReplyStatusType_1_2._SYSTEM_EXCEPTION:
                {
                    info.setReplyStatus (SYSTEM_EXCEPTION.value);
                    Any sendingException = orb.create_any();
                    SystemExceptionHelper.insert(sendingException, request.getSystemException());
                    info.sending_exception(sendingException);
                    op = ServerInterceptorIterator.SEND_EXCEPTION;
                    break;

                }
                case ReplyStatusType_1_2._LOCATION_FORWARD:
                {
                    info.setReplyStatus (LOCATION_FORWARD.value);
                    op = ServerInterceptorIterator.SEND_OTHER;
                    break;
                }
            }

            invokeInterceptors(info, op);

            ReplyOutputStream out = request.get_out();
            Collection<ServiceContext> ctx = info.getReplyServiceContexts ();

            for (ServiceContext s: ctx)
            {
                out.addServiceContext(s);
            }
View Full Code Here

TOP

Related Classes of org.jacorb.orb.portableInterceptor.ServerRequestInfoImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.