I use IS 10.1 to control a telnet session, using functionality from the Apache Commons TelnetClient library. The approach I use is to write Java wrapper services for key telnet actions (connect, read, write, disconnect etc). I then call the Java telnet services from Flow code. The initial call to the connect service returns a org.apache.commons.net.telnet.TelnetClient object. I pass this object to other Java services (read, write, disconnect) via Flow code. On the whole, this approach works pretty well.
But this approach fails in the catch block. There, I call pub.flow:getLastError and try to obtain the telnet session object from lastError/pipeline. This is so I can attempt a telnet disconnection when an exception occurs. But in the catch block, the telnet session retrieved is no longer an object - it’s a string! This causes the disconnect Java service to throw a ClassCastException at ‘>>>’ in Java code below.
Flow Service
Java ‘disconnect’ Service
import org.apache.commons.net.telnet.TelnetClient;
...
public static final void disconnect(IData pipeline) throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
>>> TelnetClient telnetSession = (TelnetClient) IDataUtil.get(pipelineCursor, "telnetSession"); <<<
try {
// Disconnect telnet session
telnetSession.disconnect();
} catch (Exception e)
Java Exception
java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.commons.net.telnet.TelnetClient
at CECommon.utils.telnet.disconnect(telnet.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
...
The problem seems to lie with pub.flow:getLastError mapping a string - not an object - into telnetSession in the mapping below.

In the ‘Try’ block, the Java disconnect service works fine with the telnetSession object.
Any thoughts how I can obtain the telnet session object in the ‘Catch’ block as an object, not a string?
Update: just saw this old post where Rupinder Singh and others seem to have stumbled across the same problem. But that was 2002! Is the behavior still the same two decades on?
#Flow-and-Java-services#webMethods#Integration-Server-and-ESB