* @param tobj The transfer object to send.
* @return The transfer object containing the response.
*/
public TransferObject respond(TransferObject tobj) throws IntegrationException
{
TransferObject response;
TCPConnection con = null;
try
{
InetSocketAddress remoteAddr = getRemoteAddress(tobj);
con = open(remoteAddr, getLocalAddress(tobj, remoteAddr), getTrust(tobj),
getCertificate(tobj), getPassword(tobj), getConnectionTimeout(tobj));
con.setTOS(getTOS(tobj));
send(tobj, con, null);
// Get the input channel
MessageInputStream mis = m_channel.getMessageStreamFactory(null).createMessageInputStream(con.getInputStream());
con.setReadTimeout(m_channel.getReadTimeout());
remoteAddr = con.getRemoteAddress();
InetSocketAddress localAddr = con.getLocalAddress();
// Create the TransferObject
response = new TransferObject("TCP", 6);
response.setValue(TCPSender.REMOTE_HOST, remoteAddr.getAddress().getHostAddress());
response.setValue(TCPSender.REMOTE_PORT, Primitive.createInteger(remoteAddr.getPort()));
response.setValue(TCPSender.LOCAL_HOST, localAddr.getAddress().getHostAddress());
response.setValue(TCPSender.LOCAL_PORT, Primitive.createInteger(localAddr.getPort()));
response.setValue(TCPSender.CHANNEL, m_channel.getName());
if (mis.next(response))
{
// get body
BufferedInputStream bufStream = new BufferedInputStream(new NoCloseInputStream(mis));
Object body;
if (m_channel.getEncoding() != null)
{
String sEncoding = m_channel.getEncoding().toLowerCase(Locale.ENGLISH);
Reader ireader = new BufferedReader(new InputStreamReader(
UTF8BOMIgnoreInputStream.wrap(bufStream, sEncoding), sEncoding));
body = new ReaderInput(ireader);
}
else
{
body = new StreamInput(bufStream);
}
response.setValue(TCPSender.BODY, body);
}
}
catch (RPCException e)
{
// don't wrap RPC exception