@Override public void messageReceived(IoSession session, Object msg) throws Exception { String xml = msg.toString(); System.out.println( "1. Message Recieved from : " + session.getRemoteAddress().toString() + "\nMessage " + xml); XPathHandler handler = new XPathHandler(); parser.parse(new ByteArrayInputStream(xml.getBytes()), handler); String xmlResponse = createResponse(handler.getXmlData()); System.out.println( "2. Message Response to : " + session.getRemoteAddress().toString() + "\nMessage " + xmlResponse); session.write(xmlResponse); }