Exemple #1
0
void
IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager, BasicStream* stream)
{
    _is = stream;

    BasicStream::Container::iterator start = _is->i;

    //
    // Read the current.
    //
    _is->read(_current.id);

    //
    // For compatibility with the old FacetPath.
    //
    string facet;
    {
        vector<string> facetPath;
        _is->read(facetPath);
        if(!facetPath.empty())
        {
            if(facetPath.size() > 1)
            {
                throw MarshalException(__FILE__, __LINE__);
            }
            facet.swap(facetPath[0]);
        }
    }
    _current.facet.swap(facet);

    _is->read(_current.operation, false);

    Byte b;
    _is->read(b);
    _current.mode = static_cast<OperationMode>(b);

    Int sz = _is->readSize();
    while(sz--)
    {
        pair<const string, string> pr;
        _is->read(const_cast<string&>(pr.first));
        _is->read(pr.second);
        _current.ctx.insert(_current.ctx.end(), pr);
    }

    const CommunicatorObserverPtr& obsv = _is->instance()->initializationData().observer;
    if(obsv)
    { 
        // Read the parameter encapsulation size.
        Ice::Int sz;
        _is->read(sz); 
        _is->i -= 4;

        _observer.attach(obsv->getDispatchObserver(_current, static_cast<Int>(_is->i - start + sz)));
    }

    //
    // Don't put the code above into the try block below. Exceptions
    // in the code above are considered fatal, and must propagate to
    // the caller of this operation.
    //

    if(servantManager)
    {
        _servant = servantManager->findServant(_current.id, _current.facet);
        if(!_servant)
        {
            _locator = servantManager->findServantLocator(_current.id.category);
            if(!_locator && !_current.id.category.empty())
            {
                _locator = servantManager->findServantLocator("");
            }

            if(_locator)
            {
                try
                {
                    _servant = _locator->locate(_current, _cookie);
                }
                catch(const UserException& ex)
                {
                    Ice::EncodingVersion encoding = _is->skipEncaps(); // Required for batch requests.

                    _observer.userException();

                    if(_response)
                    {
                        _os.write(replyUserException);
                        _os.startWriteEncaps(encoding, DefaultFormat);
                        _os.write(ex);
                        _os.endWriteEncaps();
                        _observer.reply(static_cast<Int>(_os.b.size() - headerSize - 4));
                        _responseHandler->sendResponse(_current.requestId, &_os, _compress, false);
                    }
                    else
                    {
                        _responseHandler->sendNoResponse();
                    }

                    _observer.detach();
                    _responseHandler = 0;
                    return;
                }
                catch(const std::exception& ex)
                {
                    _is->skipEncaps(); // Required for batch requests.
                    __handleException(ex, false);
                    return;
                }
                catch(...)
                {
                    _is->skipEncaps(); // Required for batch requests.
                    __handleException(false);
                    return;
                }
            }
        }
    }

    try
    {
        if(_servant)
        {
            //
            // DispatchAsync is a "pseudo dispatch status", used internally only
            // to indicate async dispatch.
            //
            if(_servant->__dispatch(*this, _current) == DispatchAsync)
            {            
                return;
            }

            if(_locator && !__servantLocatorFinished(false))
            {
                return;
            }
        }
        else
        {
            //
            // Skip the input parameters, this is required for reading
            // the next batch request if dispatching batch requests.
            //
            _is->skipEncaps(); 

            if(servantManager && servantManager->hasServant(_current.id))
            {
                throw FacetNotExistException(__FILE__, __LINE__, _current.id, _current.facet, _current.operation);
            }
            else
            {
                throw ObjectNotExistException(__FILE__, __LINE__, _current.id, _current.facet, _current.operation);
            }
        }
    }
    catch(const std::exception& ex)
    {
        if(_servant && _locator && !__servantLocatorFinished(false))
        {
            return;
        }
        __handleException(ex, false);
        return;
    }
    catch(...)
    {
        if(_servant && _locator && !__servantLocatorFinished(false))
        {
            return;
        }
        __handleException(false);
        return;
    }

    //
    // Don't put the code below into the try block above. Exceptions
    // in the code below are considered fatal, and must propagate to
    // the caller of this operation.
    //

    if(_response)
    {
        _observer.reply(static_cast<Int>(_os.b.size() - headerSize - 4));
        _responseHandler->sendResponse(_current.requestId, &_os, _compress, false);
    }
    else
    {
        _responseHandler->sendNoResponse();
    }

    _observer.detach();
    _responseHandler = 0;
}
Exemple #2
0
void
IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager)
{
    //
    // Read the current.
    //
    _current.id.__read(&_is);

    //
    // For compatibility with the old FacetPath.
    //
    string facet;
    {
        vector<string> facetPath;
        _is.read(facetPath);
        if(!facetPath.empty())
        {
            if(facetPath.size() > 1)
            {
                throw MarshalException(__FILE__, __LINE__);
            }
            facet.swap(facetPath[0]);
        }
    }
    _current.facet.swap(facet);

    _is.read(_current.operation, false);

    Byte b;
    _is.read(b);
    _current.mode = static_cast<OperationMode>(b);

    Int sz;
    _is.readSize(sz);
    while(sz--)
    {
        pair<const string, string> pr;
        _is.read(const_cast<string&>(pr.first));
        _is.read(pr.second);
        _current.ctx.insert(_current.ctx.end(), pr);
    }

    _is.startReadEncaps();

    if(_response)
    {
        assert(_os.b.size() == headerSize + 4); // Dispatch status position.
        _os.write(static_cast<Byte>(0));
        _os.startWriteEncaps();
    }

    // Initialize status to some value, to keep the compiler happy.
    DispatchStatus status = DispatchOK;

    //
    // Don't put the code above into the try block below. Exceptions
    // in the code above are considered fatal, and must propagate to
    // the caller of this operation.
    //

    try
    {
        try
        {
            if(servantManager)
            {
                _servant = servantManager->findServant(_current.id, _current.facet);
                if(!_servant)
                {
                    _locator = servantManager->findServantLocator(_current.id.category);
                    if(!_locator && !_current.id.category.empty())
                    {
                        _locator = servantManager->findServantLocator("");
                    }
                    if(_locator)
                    {
                        _servant = _locator->locate(_current, _cookie);
                    }
                }
            }
            if(!_servant)
            {
                if(servantManager && servantManager->hasServant(_current.id))
                {
                    status = DispatchFacetNotExist;
                }
                else
                {
                    status = DispatchObjectNotExist;
                }
            }
            else
            {
                status = _servant->__dispatch(*this, _current);
            }
        }
        catch(...)
        {
            if(_locator && _servant && status != DispatchAsync)
            {
                _locator->finished(_current, _servant, _cookie);
            }

            throw;
        }
        
        if(_locator && _servant && status != DispatchAsync)
        {
            _locator->finished(_current, _servant, _cookie);
        }
    }
    catch(const Exception& ex)
    {
        _is.endReadEncaps();
        __handleException(ex);
        return;
    }
    catch(const std::exception& ex)
    {
        _is.endReadEncaps();
        __handleException(ex);
        return;
    }
    catch(...)
    {
        _is.endReadEncaps();
        __handleException();
        return;
    }

    //
    // Don't put the code below into the try block above. Exceptions
    // in the code below are considered fatal, and must propagate to
    // the caller of this operation.
    //
    
    _is.endReadEncaps();

    //
    // DispatchAsync is "pseudo dispatch status", used internally only
    // to indicate async dispatch.
    //
    if(status == DispatchAsync)
    {
        //
        // If this was an asynchronous dispatch, we're done here.
        //
        return;
    }

    if(_response)
    {
        _os.endWriteEncaps();
        
        if(status != DispatchOK && status != DispatchUserException)
        {
            assert(status == DispatchObjectNotExist ||
                   status == DispatchFacetNotExist ||
                   status == DispatchOperationNotExist);
            
            _os.b.resize(headerSize + 4); // Dispatch status position.
            _os.write(static_cast<Byte>(status));
            
            _current.id.__write(&_os);

            //
            // For compatibility with the old FacetPath.
            //
            if(_current.facet.empty())
            {
                _os.write(static_cast<string*>(0), static_cast<string*>(0));
            }
            else
            {
                _os.write(&_current.facet, &_current.facet + 1);
            }

            _os.write(_current.operation, false);
        }
        else
        {
            *(_os.b.begin() + headerSize + 4) = static_cast<Byte>(status); // Dispatch status position.
        }

        _connection->sendResponse(&_os, _compress);
    }
    else
    {
        _connection->sendNoResponse();
    }
}
Exemple #3
0
IceInternal::Direct::Direct(const Current& current) :
    _current(current)
{
    ObjectAdapterI* adapter = dynamic_cast<ObjectAdapterI*>(_current.adapter.get());
    assert(adapter);

    //
    // Must call incDirectCount() first, because it checks for adapter
    // deactivation, and prevents deactivation completion until
    // decDirectCount() is called. This is important, because
    // getServantManager() may not be called afer deactivation
    // completion.
    //
    adapter->incDirectCount();

    ServantManagerPtr servantManager = adapter->getServantManager();
    assert(servantManager);

    _servant = servantManager->findServant(_current.id, _current.facet);
    if(!_servant)
    {
        _locator = servantManager->findServantLocator(_current.id.category);
        if(!_locator && !_current.id.category.empty())
        {
            _locator = servantManager->findServantLocator("");
        }
        if(_locator)
        {
            try
            {
                _servant = _locator->locate(_current, _cookie);
            }
            catch(...)
            {
                adapter->decDirectCount();
                throw;
            }
        }
    }

    if(!_servant)
    {
        adapter->decDirectCount();
        if(servantManager && servantManager->hasServant(_current.id))
        {
            FacetNotExistException ex(__FILE__, __LINE__);
            ex.id = _current.id;
            ex.facet = _current.facet;
            ex.operation = _current.operation;
            throw ex;
        }
        else
        {
            ObjectNotExistException ex(__FILE__, __LINE__);
            ex.id = _current.id;
            ex.facet = _current.facet;
            ex.operation = _current.operation;
            throw ex;
        }
    }
}
Exemple #4
0
void
IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager, InputStream* stream)
{
    _is = stream;

    InputStream::Container::iterator start = _is->i;

    //
    // Read the current.
    //
    _is->read(_current.id);

    //
    // For compatibility with the old FacetPath.
    //
    string facet;
    {
        vector<string> facetPath;
        _is->read(facetPath);
        if(!facetPath.empty())
        {
            if(facetPath.size() > 1)
            {
                throw MarshalException(__FILE__, __LINE__);
            }
            facet.swap(facetPath[0]);
        }
    }
    _current.facet.swap(facet);

    _is->read(_current.operation, false);

    Byte b;
    _is->read(b);
    _current.mode = static_cast<OperationMode>(b);

    Int sz = _is->readSize();
    while(sz--)
    {
        pair<const string, string> pr;
        _is->read(const_cast<string&>(pr.first));
        _is->read(pr.second);
        _current.ctx.insert(_current.ctx.end(), pr);
    }

    const CommunicatorObserverPtr& obsv = _is->instance()->initializationData().observer;
    if(obsv)
    {
        // Read the parameter encapsulation size.
        Ice::Int sz;
        _is->read(sz);
        _is->i -= 4;

        _observer.attach(obsv->getDispatchObserver(_current, static_cast<Int>(_is->i - start + sz)));
    }

    //
    // Don't put the code above into the try block below. Exceptions
    // in the code above are considered fatal, and must propagate to
    // the caller of this operation.
    //

    if(servantManager)
    {
        _servant = servantManager->findServant(_current.id, _current.facet);
        if(!_servant)
        {
            _locator = servantManager->findServantLocator(_current.id.category);
            if(!_locator && !_current.id.category.empty())
            {
                _locator = servantManager->findServantLocator("");
            }

            if(_locator)
            {
                try
                {
                    _servant = _locator->locate(_current, _cookie);
                }
                catch(const std::exception& ex)
                {
                    skipReadParams(); // Required for batch requests.
                    handleException(ex, false);
                    return;
                }
                catch(...)
                {
                    skipReadParams(); // Required for batch requests.
                    handleException("unknown c++ exception", false);
                    return;
                }
            }
        }
    }

    if(!_servant)
    {
        try
        {
            if(servantManager && servantManager->hasServant(_current.id))
            {
                throw FacetNotExistException(__FILE__, __LINE__, _current.id, _current.facet, _current.operation);
            }
            else
            {
                throw ObjectNotExistException(__FILE__, __LINE__, _current.id, _current.facet, _current.operation);
            }
        }
        catch(const Ice::LocalException& ex)
        {
            skipReadParams(); // Required for batch requests
            handleException(ex, false);
            return;
        }
    }

    try
    {
        //
        // Dispatch in the incoming call
        //
        _servant->_iceDispatch(*this, _current);

        //
        // If the request was not dispatched asynchronously, send the response.
        //
        if(!_inAsync)
        {
            response(false);
        }
    }
    catch(const std::exception& ex)
    {
        if(_inAsync)
        {
            try
            {
                _inAsync->kill(*this);
            }
            catch(const Ice::ResponseSentException&)
            {
                const Ice::PropertiesPtr properties = _os.instance()->initializationData().properties;
                if(properties->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0)
                {
                    if(const IceUtil::Exception* exc = dynamic_cast<const IceUtil::Exception*>(&ex))
                    {
                        warning(*exc);
                    }
                    else
                    {
                        warning(string("std::exception: ") + ex.what());
                    }
                }
                return;
            }
        }
        exception(ex, false);
    }
    catch(...)
    {
        if(_inAsync)
        {
            try
            {
                _inAsync->kill(*this);
            }
            catch(const Ice::ResponseSentException&)
            {
                const Ice::PropertiesPtr properties = _os.instance()->initializationData().properties;
                if(properties->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0)
                {
                    warning("unknown c++ exception");
                }
                return;
            }
        }
        exception("unknown c++ exception", false);
    }
}