Skip to content

Commit b92b81d

Browse files
committed
Fixed runtime error fail in service resonse.
1 parent 79dd640 commit b92b81d

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/main/java/org/ros/internal/node/response/Response.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static <T> Response<T> newNotfound(String message, T value) {
5353
*/
5454
public static <T> Response<T> fromListCheckedFailure(List<Object> response,
5555
ResultFactory<T> resultFactory) throws RemoteException {
56-
StatusCode statusCode;
56+
StatusCode statusCode = StatusCode.SUCCESS;
5757
String message;
5858
try {
5959
statusCode = StatusCode.fromInt((Integer) response.get(0));
@@ -63,13 +63,15 @@ public static <T> Response<T> fromListCheckedFailure(List<Object> response,
6363
}
6464

6565
} catch (ClassCastException e) {
66-
throw new RosRuntimeException(
67-
"Remote side did not return correct type (status code/message).", e);
66+
throw new RemoteException(StatusCode.FAILURE,
67+
"Remote side did not return correct type headers in response. Expected StatusCode.class, got "+response.get(0).getClass()+
68+
" and message of type String but got "+response.get(1).getClass()+" for values "+response.get(0)+" and "+response.get(1));
6869
}
6970
try {
7071
return new Response<T>(statusCode, message, resultFactory.newFromValue(response.get(2)));
7172
} catch (ClassCastException e) {
72-
throw new RosRuntimeException("Remote side did not return correct value type.", e);
73+
throw new RemoteException(StatusCode.FAILURE,"Remote side did not return correct value type in response. Got "+ response.get(2).getClass()+
74+
" from value "+ response.get(2)+" expected "+((T)resultFactory).getClass());
7375
}
7476
}
7577

@@ -98,16 +100,18 @@ public static <T> Response<T> fromListChecked(List<Object> response,
98100
statusCode = StatusCode.fromInt((Integer) response.get(0));
99101
message = (String) response.get(1);
100102
if (statusCode != StatusCode.SUCCESS) {
101-
102103
throw new RemoteException(statusCode, message);
103104
}
104105
} catch (ClassCastException e) {
105-
throw new RosRuntimeException("Remote side did not return correct type (status code/message).", e);
106+
throw new RemoteException(StatusCode.FAILURE,
107+
"Remote side did not return correct type headers in response. Expected StatusCode.class, got "+response.get(0).getClass()+
108+
" and message of type String but got "+response.get(1).getClass()+" for values "+response.get(0)+" and "+response.get(1));
106109
}
107110
try {
108111
return new Response<T>(statusCode, message, resultFactory.newFromValue(response.get(2)));
109112
} catch (ClassCastException e) {
110-
throw new RosRuntimeException("Remote side did not return correct value type.", e);
113+
throw new RemoteException(StatusCode.FAILURE,"Remote side did not return correct value type in response. Got "+ response.get(2).getClass()+
114+
" from value "+ response.get(2)+" expected "+((T)resultFactory).getClass());
111115
}
112116
}
113117

@@ -142,12 +146,15 @@ public static <T> Response<T> fromListCheckedNotFound(List<Object> response,
142146
throw new RemoteException(statusCode, message);
143147
}
144148
} catch (ClassCastException e) {
145-
throw new RosRuntimeException("Remote side did not return correct type (status code/message).", e);
149+
throw new RemoteException(StatusCode.FAILURE,
150+
"Remote side did not return correct type headers in response. Expected StatusCode.class, got "+response.get(0).getClass()+
151+
" and message of type String but got "+response.get(1).getClass()+" for values "+response.get(0)+" and "+response.get(1));
146152
}
147153
try {
148154
return new Response<T>(statusCode, message, resultFactory.newFromValue(response.get(2)));
149155
} catch (ClassCastException e) {
150-
throw new RosRuntimeException("Remote side did not return correct value type.", e);
156+
throw new RemoteException(StatusCode.FAILURE,"Remote side did not return correct value type in response. Got "+ response.get(2).getClass()+
157+
" from value "+ response.get(2)+" expected "+((T)resultFactory).getClass());
151158
}
152159
}
153160

src/main/java/org/ros/internal/node/rpc/MasterRpcEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ List<Object> registerPublisher(String callerId, String topicName, String topicTy
190190
* ROS caller ID
191191
* @param service
192192
* Fully-qualified name of service
193-
* @return service URL is provides address and port of the service. Fails if
193+
* @return service socket address that provides address and port of the service. Fails if
194194
* there is no provider.
195195
*/
196196
List<Object> lookupService(String callerId, String service);

src/main/java/org/ros/internal/node/service/DefaultServiceServer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class DefaultServiceServer<T, S> implements ServiceServer<T, S> {
3636

37-
private static final boolean DEBUG = false;
37+
private static final boolean DEBUG = true;
3838
private static final Log log = LogFactory.getLog(DefaultPublisher.class);
3939

4040
private final ServiceDeclaration serviceDeclaration;
@@ -54,6 +54,9 @@ public DefaultServiceServer(ServiceDeclaration serviceDeclaration,
5454
this.messageFactory = messageFactory;
5555
this.scheduledExecutorService = scheduledExecutorService;
5656
listenerGroup = new ListenerGroup<ServiceServerListener<T, S>>(scheduledExecutorService);
57+
if(DEBUG)
58+
log.info("DefaultServiceServer contructed with service declaration:"+serviceDeclaration+" serviceResponseBuilder:"+serviceResponseBuilder+
59+
"Advertise address:"+advertiseAddress+" Message factory:"+messageFactory+" Executor:"+scheduledExecutorService+" Listener Group:"+listenerGroup);
5760
listenerGroup.add(new DefaultServiceServerListener<T, S>() {
5861
@Override
5962
public void onMasterRegistrationSuccess(ServiceServer<T, S> registrant) {

src/main/java/org/ros/internal/transport/tcp/TcpServerPipelineFactory.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.apache.commons.logging.Log;
66
import org.apache.commons.logging.LogFactory;
7+
import org.ros.internal.node.service.DefaultServiceServer;
78
import org.ros.internal.node.service.ServiceManager;
89
import org.ros.internal.node.topic.DefaultPublisher;
910
import org.ros.internal.node.topic.TopicParticipantManager;
@@ -52,6 +53,14 @@ protected void initChannel(ChannelHandlerContext ch) throws Exception {
5253
for(DefaultPublisher<?> p : pubs) {
5354
log.info("PUBLISHER:"+p);
5455
}
56+
log.info("TcpServerPipelineFactory ServiceManager:"+serviceManager);
57+
Collection<DefaultServiceServer<?,?>> srvrs = serviceManager.getServers();
58+
if( srvrs.isEmpty()) {
59+
log.info("NO SERVICES IN TopicParticipantManager "+topicParticipantManager);
60+
}
61+
for(DefaultServiceServer<?,?> s : srvrs) {
62+
log.info("SERVICE:"+s);
63+
}
5564
}
5665
}
5766
}

0 commit comments

Comments
 (0)