Package org.jacorb.orb.giop

Examples of org.jacorb.orb.giop.RequestOutputStream


        {
            bind();

            ParsedIOR ior = getParsedIOR();

            RequestOutputStream out =
                new RequestOutputStream( orb,
                                         connection,
                                         connection.getId(),
                                         operation,
                                         responseExpected,
                                         getSyncScope(),
                                         getRequestStartTime(),
                                         requestEndTime,
                                         replyEndTime,
                                         ior.get_object_key(), ior.getEffectiveProfile().version().minor );

            // CodeSets are only negotiated once per connection,
            // not for each individual request
            // (CORBA 3.0, 13.10.2.6, second paragraph).
            if (!connection.isTCSNegotiated())
            {
                connection.setCodeSet(ior);
            }

            //Setting the codesets not until here results in the
            //header being writtend using the default codesets. On the
            //other hand, the server side must have already read the
            //header to discover the codeset service context.
            out.setCodeSets( connection.getTCS(), connection.getTCSW() );

            out.updateMutatorConnection (connection.getGIOPConnection());

            return out;
        }
    }
View Full Code Here


    }

    public void send_request( ClientRequestInfo ri )
        throws ForwardRequest
    {
        final RequestOutputStream output = ((ClientRequestInfoImpl) ri).getRequestStream ();

        if (output != null && output.getBodyBegin() > 0)
        {
            int debut = output.getBodyBegin();
            final int fin = output.size();
            int resteALire = fin - debut;

            if (resteALire > 0)
            {
                final byte[] buf = output.getBufferCopy();
                final int pos = output.get_pos();

                // skip header
                output.skip(debut - pos);
                // rewrite remaining
                output.write_octet_array(buf, debut, resteALire);
            }
        }

        // This will fail to compile if public accessor API has been accidentally
        // removed (!)
View Full Code Here

    @Test
    public void testGIOP_1_2_CorrectFragmentedRequest()
    {
        List<byte[]> messages = new Vector<byte[]>();

        RequestOutputStream r_out =
            new RequestOutputStream( getORB(), //ClientConnection
                                     (ClientConnection) null,           //request id
                                     0,       //operation
                                     "foo",        // response expected
                                     true,   // SYNC_SCOPE (irrelevant)
                                     (short)-1,        //request start time
                                     null,        //request end time
                                     null,        //reply start time
                                     null, //object key
                                     new byte[1], 2            // giop minor
                                     );

        //manually write the first half of the string "barbaz"
        r_out.write_ulong( 7 ); //string length
        r_out.write_octet( (byte) 'b' );
        r_out.write_octet( (byte) 'a' );
        r_out.write_octet( (byte) 'r' );
        r_out.insertMsgSize();

        byte[] b = r_out.getBufferCopy();

        b[6] |= 0x02; //set "more fragments follow"

        messages.add( b );

        MessageOutputStream m_out =
            new MessageOutputStream(orb);
        m_out.writeGIOPMsgHeader( MsgType_1_1._Fragment,
                                     2 // giop minor
                                     );
        m_out.write_ulong( 0 ); // Fragment Header (request id)
        m_out.write_octet( (byte) 'b' );
        m_out.write_octet( (byte) 'a' );
        m_out.write_octet( (byte) 'z' );
        m_out.write_octet( (byte) 0);
        m_out.insertMsgSize();

        messages.add( m_out.getBufferCopy() );

        DummyTransport transport =
            new DummyTransport( messages );

        DummyRequestListener request_listener =
            new DummyRequestListener();

        DummyReplyListener reply_listener =
            new DummyReplyListener();

        GIOPConnectionManager giopconn_mg =
            new GIOPConnectionManager();
        try
        {
            giopconn_mg.configure (config);
        }
        catch (Exception e)
        {
        }

        ServerGIOPConnection conn =
            giopconn_mg.createServerGIOPConnection( null,
                                                    transport,
                                                    request_listener,
                                                    reply_listener );

        try
        {
            //will not return until an IOException is thrown (by the
            //DummyTransport)
            conn.receiveMessages();
        }
        catch( IOException e )
        {
            //o.k., thrown by DummyTransport
        }

        //did the GIOPConnection hand the complete request over to the
        //listener?
        assertTrue( request_listener.getRequest() != null );

        RequestInputStream r_in = new RequestInputStream
            ( getORB(), null, request_listener.getRequest() );

        //is the body correct?
        assertEquals( "barbaz", r_in.read_string() );

        r_out.close();
        r_in.close();
        m_out.close();
    }
View Full Code Here

    @Test
    public void testGIOP_1_0_CorrectRefusing()
    {
        List<byte[]> messages = new Vector<byte[]>();

        RequestOutputStream r_out =
            new RequestOutputStream( getORB(), //ClientConnection
                                     null,           //request id
                                     0,       //operation
                                     "foo",        //response expected
                                     true,   //SYNC_SCOPE (irrelevant)
                                     (short)-1,        //request start time
                                     null,        //request end time
                                     null,        //reply end time
                                     null, //object key
                                     new byte[1], 0            // giop minor
                                     );

        r_out.write_string( "bar" );
        r_out.insertMsgSize();

        byte[] b = r_out.getBufferCopy();

        b[6] |= 0x02; //set "more fragments follow"

        messages.add( b );

        DummyTransport transport =
            new DummyTransport( messages );

        DummyRequestListener request_listener =
            new DummyRequestListener();

        DummyReplyListener reply_listener =
            new DummyReplyListener();

        GIOPConnectionManager giopconn_mg =
            new GIOPConnectionManager();
        try
        {
            giopconn_mg.configure (config);
        }
        catch (Exception e)
        {
        }

        GIOPConnection conn =
            giopconn_mg.createServerGIOPConnection( null,
                                                    transport,
                                                    request_listener,
                                                    reply_listener );

        try
        {
            //will not return until an IOException is thrown (by the
            //DummyTransport)
            conn.receiveMessages();
        }
        catch( IOException e )
        {
            //o.k., thrown by DummyTransport
        }

        //no request or reply must have been handed over
        assertTrue( request_listener.getRequest() == null );
        assertTrue( reply_listener.getReply() == null );

        //instead, an error message have must been sent via the
        //transport
        assertTrue( transport.getWrittenMessage() != null );

        byte[] result = transport.getWrittenMessage();

        assertTrue( Messages.getMsgType( result ) == MsgType_1_1._MessageError );
        MessageOutputStream m_out =
            new MessageOutputStream(orb);
        m_out.writeGIOPMsgHeader( MsgType_1_1._Fragment,
                                     0 // giop minor
                                     );
        m_out.write_ulong( 0 ); // Fragment Header (request id)
        m_out.write_octet( (byte) 'b' );
        m_out.write_octet( (byte) 'a' );
        m_out.write_octet( (byte) 'z' );
        m_out.insertMsgSize();

        messages.add( m_out.getBufferCopy() );

        try
        {
            //will not return until an IOException is thrown (by the
            //DummyTransport)
            conn.receiveMessages();
        }
        catch( IOException e )
        {
            //o.k., thrown by DummyTransport
        }

        //no request or reply must have been handed over
        assertTrue( request_listener.getRequest() == null );
        assertTrue( reply_listener.getReply() == null );

        //instead, an error message have must been sent via the
        //transport
        assertTrue( transport.getWrittenMessage() != null );

        //must be a new one
        assertTrue( transport.getWrittenMessage() != result );
        result = transport.getWrittenMessage();

        assertTrue( Messages.getMsgType( result ) == MsgType_1_1._MessageError );

        r_out.close();
        m_out.close();
    }
View Full Code Here

    @Test
    public void testGIOP_1_1_NoImplement()
    {
        List<byte[]> messages = new Vector<byte[]>();

        RequestOutputStream r_out =
            new RequestOutputStream( getORB(), //ClientConnection
                                     null,           //request id
                                     0,       //operation
                                     "foo",        //response expected
                                     true,   //SYNC_SCOPE (irrelevant)
                                     (short)-1,        //request start time
                                     null,        //request end time
                                     null,        //reply end time
                                     null, //object key
                                     new byte[1], 1            // giop minor
                                     );

        r_out.write_string( "bar" );
        r_out.insertMsgSize();

        byte[] b = r_out.getBufferCopy();

        b[6] |= 0x02; //set "more fragments follow"

        messages.add( b );

        DummyTransport transport =
            new DummyTransport( messages );

        DummyRequestListener request_listener =
            new DummyRequestListener();

        DummyReplyListener reply_listener =
            new DummyReplyListener();

        GIOPConnectionManager giopconn_mg =
            new GIOPConnectionManager();
        try
        {
            giopconn_mg.configure (config);
        }
        catch (Exception e)
        {
        }

        GIOPConnection conn =
            giopconn_mg.createServerGIOPConnection( null,
                                                    transport,
                                                    request_listener,
                                                    reply_listener );

        try
        {
            //will not return until an IOException is thrown (by the
            //DummyTransport)
            conn.receiveMessages();
        }
        catch( IOException e )
        {
            //o.k., thrown by DummyTransport
        }

        //no request or reply must have been handed over
        assertTrue( request_listener.getRequest() == null );
        assertTrue( reply_listener.getReply() == null );

        //instead, an error message have must been sent via the
        //transport
        assertTrue( transport.getWrittenMessage() != null );

        byte[] result = transport.getWrittenMessage();

        ReplyInputStream r_in = new ReplyInputStream( getORB(), result );

        Exception ex = r_in.getException();
        if ( ex != null && ex.getClass() == org.omg.CORBA.NO_IMPLEMENT.class )
        {
            // o.k.
        }
        else
        {
            fail();
        }

        MessageOutputStream m_out =
            new MessageOutputStream(orb);
        m_out.writeGIOPMsgHeader( MsgType_1_1._Fragment,
                                  1 // giop minor
                                  );
        m_out.write_ulong( 0 ); // Fragment Header (request id)
        m_out.write_octet( (byte) 'b' );
        m_out.write_octet( (byte) 'a' );
        m_out.write_octet( (byte) 'z' );
        m_out.insertMsgSize();

        messages.add( m_out.getBufferCopy() );

        try
        {
            //will not return until an IOException is thrown (by the
            //DummyTransport)
            conn.receiveMessages();
        }
        catch( IOException e )
        {
            //o.k., thrown by DummyTransport
        }

        //no request or reply must have been handed over
        assertTrue( request_listener.getRequest() == null );
        assertTrue( reply_listener.getReply() == null );

        //can't check more, message is discarded
        m_out.close();
        r_out.close();
        r_in.close();
    }
View Full Code Here

    @Test
    public void testGIOP_1_1_CorrectRequest()
    {
        List<byte[]> messages = new Vector<byte[]>();

        RequestOutputStream r_out =
            new RequestOutputStream( getORB(), //ClientConnection
                                     (ClientConnection) null,           //request id
                                     0,       //operation
                                     "foo",        // response expected
                                     true,   // SYNC_SCOPE (irrelevant)
                                     (short)-1,        //request start time
                                     null,        //request end time
                                     null,        //reply start time
                                     null, //object key
                                     new byte[1], 1            // giop minor
                                     );

        String message = "Request";
        r_out.write_string(message);
        r_out.insertMsgSize();

        messages.add( r_out.getBufferCopy() );

        DummyTransport transport =
            new DummyTransport( messages );

        DummyRequestListener request_listener =
            new DummyRequestListener();

        DummyReplyListener reply_listener =
            new DummyReplyListener();

        GIOPConnectionManager giopconn_mg =
            new GIOPConnectionManager();
        try
        {
            giopconn_mg.configure (config);
        }
        catch (Exception e)
        {
        }

        ServerGIOPConnection conn =
            giopconn_mg.createServerGIOPConnection( null,
                                                    transport,
                                                    request_listener,
                                                    reply_listener );

        try
        {
            //will not return until an IOException is thrown (by the
            //DummyTransport)
            conn.receiveMessages();
        }
        catch( IOException e )
        {
            //o.k., thrown by DummyTransport
        }

        //did the GIOPConnection hand the complete request over to the
        //listener?
        assertTrue( request_listener.getRequest() != null );

        RequestInputStream r_in =
        new RequestInputStream( getORB(), null, request_listener.getRequest() );

        //is the body correct?
        assertEquals( message, r_in.read_string() );

        r_out.close();
        r_in.close();
    }
View Full Code Here

                                 boolean async )
        throws ApplicationException, RemarshalException
    {
        checkORB();

        RequestOutputStream ros      = (RequestOutputStream)os;

        ArrayDeque<Map<INVOCATION_KEY, UtcT>> invocationStack = invocationContext.get ();

        /**
         * We must just peek as we do not want to remove the context from
         * the ArrayDeque
         */
        Map<INVOCATION_KEY, UtcT> currentCtxt = invocationStack.peek();
        UtcT reqET = null;
        UtcT repET = null;

        if (currentCtxt != null)
        {
            reqET = currentCtxt.get (INVOCATION_KEY.REQUEST_END_TIME);
            repET = currentCtxt.get (INVOCATION_KEY.REPLY_END_TIME);

            checkTimeout (reqET, repET);
        }

        ReplyReceiver       receiver = null;
        final ClientInterceptorHandler interceptors;

        if (orb.hasClientRequestInterceptors())
        {
            interceptors = new DefaultClientInterceptorHandler
            (
                    (DefaultClientInterceptorHandler)localInterceptors.get(),
                    orb,
                    ros,
                    self,
                    this,
                    piorOriginal,
                    connections[currentConnection.ordinal ()]
            );
        }
        else
        {
            interceptors = NullClientInterceptorHandler.getInstance();
        }

        if ( connections[currentConnection.ordinal ()] != null )
        {
           orb.notifyTransportListeners (connections[currentConnection.ordinal ()].getGIOPConnection());
        }

        if (orb.hasRequestInterceptors())
        {
            localInterceptors.set(interceptors);

            try
            {
                interceptors.handle_send_request();
            }
            catch (ForwardRequest fwd)
            {
                // Should not happen for remote requests
            }
            catch (RemarshalException re)
            {
                // RemarshalExceptions explicitely caught, because in
                // that case, localInterceptors must stay set
                throw re;
            }
            catch (RuntimeException e)
            {
                // If we are throwing a system exception then this will disrupt the call path.
                // Therefore nullify localInterceptors so it doesn't appear we are still in an
                // interceptor call.
                localInterceptors.set(null);

                throw e;
            }
        }

        ClientConnection connectionToUse = null;

        ReplyGroup group = null;
        try
        {
            synchronized (bind_sync)
            {
               if ( ! bound )
               {
                  // Somehow the connection got closed under us
                  throw new COMM_FAILURE("Connection closed");
               }
               else if (ros.getConnection() == connections[currentConnection.ordinal ()])
               {
                  // RequestOutputStream has been created for
                  // exactly this connection
                  connectionToUse = connections[currentConnection.ordinal ()];
               }
               else
               {
                    logger.debug("invoke: RemarshalException");

                    // RequestOutputStream has been created for
                    // another connection, so try again
                    throw new RemarshalException();
                }
            }

            group = getReplyGroup (connectionToUse);
            if ( !ros.response_expected() )  // oneway op
            {
                invoke_oneway (ros, connectionToUse, interceptors, group);
            }
            else
            {
                // response expected, synchronous or asynchronous
                receiver = new ReplyReceiver(this, group,
                                             ros.operation(),
                                             ros.getReplyEndTime(),
                                            interceptors, replyHandler, selectorManager);

                try
                {
                   receiver.configure(configuration);
                }
                catch (ConfigurationException ex)
                {
                   logger.error ("Configuration problem with ReplyReceiver", ex);
                   throw new INTERNAL ("Caught configuration exception setting up ReplyReceiver.");
                }

                group.addHolder (receiver);

                // Use the local copy of the client connection to avoid trouble
                // with something else affecting the real connections[currentConnection].
                connectionToUse.sendRequest(ros, receiver, ros.requestId(), true);
                getParsedIOR ().markLastUsedProfile ();
            }
        }
        catch ( org.omg.CORBA.SystemException cfe )
        {
View Full Code Here

        throws RemarshalException, ApplicationException
    {
        switch (ros.syncScope())
        {
            case SYNC_NONE.value:
                RequestOutputStream copy = new RequestOutputStream(ros);
                passToTransport (connectionToUse, copy);
                try
                {
                    interceptors.handle_receive_other (SUCCESSFUL.value);
                }
View Full Code Here

            else
            {
                currentConnection = TransportType.IIOP;
            }

            RequestOutputStream out =
                new RequestOutputStream( orb,
                                         connections[currentConnection.ordinal ()],
                                         connections[currentConnection.ordinal ()].getId(),
                                         operation,
                                         responseExpected,
                                         getSyncScope(),
                                         getRequestStartTime(),
                                         requestEndTime,
                                         replyEndTime,
                                         objectKey,
                                         giopMinor);

            // CodeSets are only negotiated once per connection,
            // not for each individual request
            // (CORBA 3.0, 13.10.2.6, second paragraph).
            if (!connections[currentConnection.ordinal ()].isTCSNegotiated())
            {
                connections[currentConnection.ordinal ()].setCodeSet(ior);
            }

            //Setting the codesets not until here results in the
            //header being written using the default codesets. On the
            //other hand, the server side must have already read the
            //header to discover the codeset service context.
            out.setCodeSets( connections[currentConnection.ordinal ()].getTCS(), connections[currentConnection.ordinal ()].getTCSW() );

            out.updateMutatorConnection (connections[currentConnection.ordinal ()].getGIOPConnection());

            return out;
        }
    }
View Full Code Here

        while (true)
        {
            org.jacorb.orb.Delegate delegate =
                (org.jacorb.orb.Delegate)((org.omg.CORBA.portable.ObjectImpl)target)._get_delegate();

            final RequestOutputStream out = (RequestOutputStream)delegate.request(target, operation, response_expected);

            try
            {
                out.setRequest(this);

                for( Iterator<NamedValue> it = ((org.jacorb.orb.NVList)arguments).iterator(); it.hasNext();)
                {
                    NamedValue namedValue = it.next();

                    if( namedValue.flags() != org.omg.CORBA.ARG_OUT.value )
                    {
                        namedValue.value().write_value(out);
                    }
                }

                try
                {
                    reply = delegate.invoke(target, out);

                    if( response_expected )
                    {
                        _read_result();

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

                            try
                            {
                                delegate.invokeInterceptors(info,
                                        ClientInterceptorIterator.RECEIVE_REPLY);
                            }
                            catch(RemarshalException e)
                            {
                                //not allowed to happen here anyway
                                throw new INTERNAL("should not happen");
                            }
                            info = null;
                        }
                    }
                }
                catch (RemarshalException e)
                {
                    // Try again
                    continue;
                }
                catch (ApplicationException e)
                {
                   if (logger.isDebugEnabled ())
                   {
                      logger.debug("DII Request caught ApplicationException", e);
                   }

                    org.omg.CORBA.Any any;
                    org.omg.CORBA.TypeCode typeCode;
                    String id = e.getId ();
                    int count = (exceptions == null ? 0 : exceptions.count ());

                    // since count > 0, this means that we were provided a
                    // list of exceptions that can be thrown by the invoked
                    // operation.  see if the ApplicationException we
                    // received matches any item in the exception list and
                    // set it if it does
                    for (int i = 0; i < count; i++)
                    {
                        try
                        {
                            typeCode = exceptions.item (i);

                            if (id.equals (typeCode.id ()))
                            {
                               if (logger.isDebugEnabled ())
                               {
                                  logger.debug ("Found matching typecode of " + id + " to throw.");
                               }
                                any = orb.create_any ();
                                any.read_value (e.getInputStream (), typeCode);
                                env.exception (new org.omg.CORBA.UnknownUserException (any));
                                break;
                            }
                        }
                        catch (org.omg.CORBA.TypeCodePackage.BadKind ex) // NOPMD
                        {
                            // Ignored
                        }
                        catch (org.omg.CORBA.Bounds ex)
                        {
                            break;
                        }
                    }
                    if (count == 0)
                    {
                        env.exception
                        (
                            new UNKNOWN
                            (
                                "Caught an unknown exception with typecode id of " +
                                e.getInputStream ().read_string (),
                                0,
                                CompletionStatus.COMPLETED_YES
                            )
                        );
                    }

                    break;
                }
                catch (Exception e)
                {
                   if (logger.isDebugEnabled ())
                   {
                      logger.debug("DII Request caught Exception", e);
                   }
                    env.exception (e);
                    break;
                }

                break;
            }
            finally
            {
                out.close();
                target._release();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jacorb.orb.giop.RequestOutputStream

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.