Run StreamServerTest, exception found in background logging information

152 views
Skip to first unread message

黄维勇

unread,
May 18, 2013, 12:27:19 PM5/18/13
to json...@googlegroups.com
hi, Brian,

thanks for such a great work firstly. recently i am researching a solution for a project to use json-rpc. i found jsonrpc4j from wikipedia, and i also check out the source code. I wrote a test by myself to test stream rpc, based on the unit test of StreamServerTest. I got an exception when the jsonclient closes the socket. it reports:

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input...

i run the StreamServerTest, and it also produces such an exception. here is the log

-----------------------------------------------------------------------------------------------------------------------------------------

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer start

信息: StreamServer starting /127.0.0.1:6329

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

信息: Connection from /127.0.0.1:6330

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():0

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():1

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():2

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():3

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():4

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():5

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():6

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():7

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():8

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():9

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():10

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():11

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():12

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():13

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

........

信息: server: inc():99

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl hello

信息: server: hello(dude)

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

严重: Exception while handling request

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

 at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@6477eb97; line: 1, column: 1]

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:163)

at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2620)

at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2562)

at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1500)

at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224)

at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

at java.lang.Thread.run(Thread.java:680)

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

严重: Exception while handling request

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

 at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@7d0c3a08; line: 1, column: 1]

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:163)

at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2620)

at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2562)

at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1500)

at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224)

at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

at java.lang.Thread.run(Thread.java:680)

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

严重: Exception while handling request

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

 at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@2db6235b; line: 1, column: 1]

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:163)

at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2620)

at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2562)

at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1500)

at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224)

at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

at java.lang.Thread.run(Thread.java:680)

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

严重: Exception while handling request

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

 at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@10cb42cf; line: 1, column: 1]

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:163)

at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2620)

at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2562)

at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1500)

at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224)

at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

at java.lang.Thread.run(Thread.java:680)

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

严重: Closing client connection due to repeated errors

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

 at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@108f2ca6; line: 1, column: 1]

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:163)

at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2620)

at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2562)

at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1500)

at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224)

at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

at java.util.concurrent.FutureTask.run(FutureTask.java:138)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

at java.lang.Thread.run(Thread.java:680)

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer start

信息: StreamServer starting /127.0.0.1:6331

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

信息: Connection from /127.0.0.1:6332

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():0

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

信息: Connection from /127.0.0.1:6333

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

信息: Connection from /127.0.0.1:6334

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServer$Server run

信息: Connection from /127.0.0.1:6335

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():1

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():2

2013-5-19 0:10:46 com.googlecode.jsonrpc4j.StreamServerTest$ServiceImpl inc

信息: server: inc():3

.....


-----------------------------------------------------------------------------------------------------------------------------------------

my testing code is:

******server:

package com.googlecode.jsonrpc4j;


import java.io.IOException;

import java.net.InetAddress;

import java.net.ServerSocket;

import java.net.UnknownHostException;

import java.util.logging.Level;

import java.util.logging.Logger;


import javax.net.ServerSocketFactory;



public class MyTest {


private ServerSocket serverSocket;

private JsonRpcServer jsonRpcServer;


StreamServer streamServer;

public MyTest() throws UnknownHostException, IOException{

serverSocket = ServerSocketFactory.getDefault().createServerSocket(9527, 0, InetAddress.getByName("127.0.0.1"));

jsonRpcServer = new JsonRpcServer(new ServiceImpl(), Service.class);

//jsonRpcClient = new JsonRpcClient();

streamServer = new StreamServer(jsonRpcServer, 5, serverSocket);

}

/**

* @param args

* @throws Exception 

*/

public static void main(String[] args) throws Exception {

// TODO Auto-generated method stub

MyTest test=new MyTest();

test.start();

System.in.read();


}

public void start(){

streamServer.start();

}

private static interface Service {

String hello(String whatever);

int inc();

void reset();

}


private class ServiceImpl implements Service {

private final Logger LOGGER = Logger.getLogger(ServiceImpl.class.getName());

private int val;


public String hello(String whatever) {

LOGGER.log(Level.INFO, "server: hello("+whatever+")");

return "hello "+whatever;

}


public int inc() {

LOGGER.log(Level.INFO, "server: inc():"+val);

return val++;

}


public void reset() {

val = 0;

}

}



}


******Client

package com.googlecode.jsonrpc4j;


import static org.junit.Assert.assertEquals;


import java.io.IOException;

import java.net.Socket;




public class MyTestClient {

private JsonRpcClient jsonRpcClient= new JsonRpcClient();;

public void test() throws Exception{

Socket socket = new Socket("127.0.0.1",9527);


// create and connect with a client

Service service1 = ProxyUtil.createClientProxy(

this.getClass().getClassLoader(), Service.class,

jsonRpcClient, socket);


System.out.println("i=" + service1.inc());


System.out.println("hello=" + service1.hello("hello,world"));


// disconnect

socket.close();

}


/**

* @param args

* @throws Exception 

*/

public static void main(String[] args) throws Exception {

// create socket

MyTestClient mtc=new MyTestClient();

mtc.test();


}

private static interface Service {

String hello(String whatever);

int inc();

void reset();

}


}

---------------------------------

The exception is thrown from the jackson library. I have no idea how to solve it. Could you take a look at this problem and help me? Thanks in advance. 

黄维勇

unread,
May 18, 2013, 12:30:47 PM5/18/13
to json...@googlegroups.com

System.out.println("i=" + service1.inc());


System.out.println("hello=" + service1.hello("hello,world"));


// disconnect

socket.close();

service1.inc and service1.hello is called successfully. server side had no errors. when socket is closed, exception is thrown in the server side. 

asiamas...@gmail.com

unread,
Aug 21, 2013, 11:06:11 PM8/21/13
to json...@googlegroups.com
hello 黄维勇:
i have the same problem with you, i use the version of jsonrpc4j-0.28.
i downloaded the sourcecode and modify StreamServer.java to avoid the exception.

                        // keep handling requests
            int errors = 0;
            if (StreamServer.this.keepRunning.get()) {   //original code is while instead of if

                // handle it
                try {
                    jsonRpcServer.handle(input, output);
                } catch (Throwable t) {
                    errors++;
                    if (errors<maxClientErrors) {
                        LOGGER.log(Level.SEVERE, "Exception while handling request", t);
                    } else {
                        LOGGER.log(Level.SEVERE, "Closing client connection due to repeated errors", t);
//                        break;                    //comment this line
                    }
                }
            }


hope to help you.
Reply all
Reply to author
Forward
0 new messages