Ask Your Question

rosjava: calling rosservice fails

asked 2012-02-13 22:08:05 -0500

Markus Eich gravatar image

updated 2012-02-20 07:51:30 -0500

kwc gravatar image

Dear all,

I made my first homebrewed rosservice with Java. I have generated my custom service GetCylinders.srv

 string name
 float32 likelihood

which should return a name and a likelihood with an empty request. I have generated the service and included it in my server like this:

 import org.ros.service.reasoner_msgs.*;

   ServiceServer<org.ros.service.reasoner_msgs.GetCylinders.Request, org.ros.service.reasoner_msgs.GetCylinders.Response> server = node.newServiceServer(
        "callme", "reasoner_msgs/GetCylinders",

        new ServiceResponseBuilder<org.ros.service.reasoner_msgs.GetCylinders.Request, org.ros.service.reasoner_msgs.GetCylinders.Response>() {
          public org.ros.service.reasoner_msgs.GetCylinders.Response build(org.ros.service.reasoner_msgs.GetCylinders.Request request) throws ServiceException {
            org.ros.service.reasoner_msgs.GetCylinders.Response response = new org.ros.service.reasoner_msgs.GetCylinders.Response();
            // ...
            response.likelihood=(float) 0.7;

            return response;

When I start the node the service /callme shows up. Well that is fine. But if I use rosservice call /callme i get an error. Have I done something wrong in the setup of the service? The error message I get is

 Traceback (most recent call last):
 File "/opt/ros/electric/ros/bin/rosservice", line 46, in <module>
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 731, in rosservicemain
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 586, in _rosservice_cmd_call
service_class = get_service_class_by_name(service_name)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 357, in get_service_class_by_name
service_type = get_service_type(service_name)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 141, in get_service_type
return get_service_headers(service_name, service_uri).get('type', None)
 File "/opt/ros/electric/stacks/ros_comm/tools/rosservice/src/", line 113, in get_service_headers
return, cStringIO.StringIO(), 2048)
 File "/opt/ros/electric/ros/core/roslib/src/roslib/", line 367, in read_ros_handshake_header
raise ROSHandshakeException("connection from sender terminated before handshake header received. %s bytes were received. Please check sender for additional details."%b.tell()) connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.

Can anyone help me in solving this problem?

edit retag flag offensive close merge delete


I found out that using rosservice info /callme and rosservice args /callme give the same error. rosservice list shows /callme and rosservice uri /callme gives rosrpc:// Strange. Is there maybe a bug in the rosjavas service call?

Markus Eich gravatar image Markus Eich  ( 2012-02-14 02:38:03 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2012-03-05 07:14:38 -0500

damonkohler gravatar image
edit flag offensive delete link more

answered 2012-02-15 03:26:09 -0500

Markus Eich gravatar image

updated 2012-02-15 03:36:47 -0500

I wrote a little client for the caller in Java. THIS WORKS!! I did also a C++ client caller and this works as well. It seems that ROSJAVA is not compatible with the rostools, i.e. rosservice. Is this a know bug? For others who read this posting: I have included the client call methods. It would be much nicer to test small services with the rostools. Writing always clients for testing a service or a topic takes much longer.

 package service_caller;

 import org.apache.commons.logging.Log;
 import org.ros.exception.RemoteException;
 import org.ros.namespace.GraphName;
 import org.ros.node.Node;
 import org.ros.node.NodeMain;
 import org.ros.node.service.ServiceClient;
 import org.ros.node.service.ServiceResponseListener;
 import org.ros.service.reasoner_msgs.*;

 public class Caller implements NodeMain {

 public GraphName getDefaultNodeName() {
  return new GraphName("service_caller/Caller");


  public void onStart(Node node) {
  final Log log = node.getLog();

    ServiceClient<GetCylinders.Request, GetCylinders.Response> client = node.newServiceClient("callme","reasoner_msgs/GetCylinders");
    GetCylinders.Request request=new GetCylinders.Request();     , new ServiceResponseListener<GetCylinders.Response>() {                                          

        public void onSuccess(GetCylinders.Response respone) {
            // TODO Auto-generated method stub


        public void onFailure(RemoteException arg0) {



catch(Exception ex){


   public void onShutdown(Node node) {

   public void onShutdownComplete(Node node) {
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-02-13 22:08:05 -0500

Seen: 714 times

Last updated: Mar 05 '12