Package com.alibaba.dubbo.remoting.exchange

Examples of com.alibaba.dubbo.remoting.exchange.Response


            if (!res.isEvent() && res.getStatus() != Response.BAD_RESPONSE) {
                try {
                    // FIXME 在Codec中打印出错日志?在IoHanndler的caught中统一处理?
                    logger.warn("Fail to encode response: " + res + ", send bad_response info instead, cause: " + t.getMessage(), t);

                    Response r = new Response(res.getId(), res.getVersion());
                    r.setStatus(Response.BAD_RESPONSE);
                    r.setErrorMessage("Failed to send response: " + res + ", cause: " + StringUtils.toString(t));
                    channel.send(r);

                    return;
                } catch (RemotingException e) {
                    logger.warn("Failed to send bad_response info back: " + res + ", cause: " + e.getMessage(), e);
View Full Code Here


        Assert.assertNotNull( obj );

        Assert.assertEquals( true, obj instanceof Response );

        Response response = ( Response ) obj;

        Assert.assertEquals( request.getId(), response.getId() );

        Assert.assertTrue( response.getResult() instanceof RpcResult );

        RpcResult result = ( RpcResult ) response.getResult();

        Assert.assertTrue( result.getResult() instanceof String );

        Assert.assertEquals( methodResult.success, result.getResult() );
View Full Code Here

        Assert.assertNotNull( obj );

        Assert.assertTrue( obj instanceof Response );

        Response response = ( Response ) obj;

        Assert.assertTrue( response.getResult() instanceof RpcResult );

        RpcResult result = ( RpcResult ) response.getResult();

        Assert.assertTrue( result.hasException() );

        Assert.assertTrue( result.getException() instanceof RpcException );
View Full Code Here

        Request request = createRequest();

        RpcResult rpcResult = new RpcResult();
        rpcResult.setResult( "Hello, World!" );

        Response response = new Response();
        response.setResult( rpcResult );
        response.setId( request.getId() );
        ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

        ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
                ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
        ThriftCodec.cachedRequest.putIfAbsent( request.getId(), rd );
View Full Code Here

        RpcResult rpcResult = new RpcResult();
        String exceptionMessage = "failed";
        rpcResult.setException( new RuntimeException( exceptionMessage ) );

        Response response = new Response();
        response.setResult( rpcResult );
        response.setId( request.getId() );
        ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

        ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
                ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
        ThriftCodec.cachedRequest.put( request.getId(), rd );
View Full Code Here

       
        final AtomicInteger count = new AtomicInteger(0);
        final Channel mchannel = new MockedChannel(){
            @Override
            public void send(Object message) throws RemotingException {
                Response res = (Response)message;
                Assert.assertEquals(request.getId(), res.getId());
                Assert.assertEquals(request.getVersion(), res.getVersion());
                Assert.assertEquals(Response.OK, res.getStatus());
                Assert.assertEquals(requestdata, res.getResult());
                Assert.assertEquals(null, res.getErrorMessage());
                count.incrementAndGet();
            }
        };
        ExchangeHandler exhandler = new MockedExchangeHandler(){
            @Override
View Full Code Here

       
        final AtomicInteger count = new AtomicInteger(0);
        final Channel mchannel = new MockedChannel(){
            @Override
            public void send(Object message) throws RemotingException {
                Response res = (Response)message;
                Assert.assertEquals(request.getId(), res.getId());
                Assert.assertEquals(request.getVersion(), res.getVersion());
                Assert.assertEquals(Response.SERVICE_ERROR, res.getStatus());
                Assert.assertNull(res.getResult());
                Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
                count.incrementAndGet();
            }
        };
        ExchangeHandler exhandler = new MockedExchangeHandler(){
            @Override
View Full Code Here

       
        final AtomicInteger count = new AtomicInteger(0);
        final Channel mchannel = new MockedChannel(){
            @Override
            public void send(Object message) throws RemotingException {
                Response res = (Response)message;
                Assert.assertEquals(request.getId(), res.getId());
                Assert.assertEquals(request.getVersion(), res.getVersion());
                Assert.assertEquals(Response.BAD_REQUEST, res.getStatus());
                Assert.assertNull(res.getResult());
                Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
                count.incrementAndGet();
            }
        };
        HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
        hexhandler.received(mchannel, request);
View Full Code Here

    public void received(Channel channel, Object message) throws RemotingException {
        setReadTimestamp(channel);
        if (isHeartbeatRequest(message)) {
            Request req = (Request) message;
            if (req.isTwoWay()) {
                Response res = new Response(req.getId(), req.getVersion());
                res.setEvent(Response.HEARTBEAT_EVENT);
                channel.send(res);
                if (logger.isInfoEnabled()) {
                    int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                    logger.info("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
View Full Code Here

        ObjectInput in = s.deserialize(channel.getUrl(), is);
        // get request id.
        long id = Bytes.bytes2long(header, 4);
        if ((flag & FLAG_REQUEST) == 0) {
            // decode response.
            Response res = new Response(id);
            if ((flag & FLAG_EVENT) != 0) {
                res.setEvent(Response.HEARTBEAT_EVENT);
            }
            // get status.
            byte status = header[3];
            res.setStatus(status);
            if (status == Response.OK) {
                try {
                    Object data;
                    if (res.isHeartbeat()) {
                        data = decodeHeartbeatData(channel, in);
                    } else if (res.isEvent()) {
                        data = decodeEventData(channel, in);
                    } else {
                        data = decodeResponseData(channel, in, getRequestData(id));
                    }
                    res.setResult(data);
                } catch (Throwable t) {
                    res.setStatus(Response.CLIENT_ERROR);
                    res.setErrorMessage(StringUtils.toString(t));
                }
            } else {
                res.setErrorMessage(in.readUTF());
            }
            return res;
        } else {
            // decode request.
            Request req = new Request(id);
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.remoting.exchange.Response

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.