0

I am using cisco axl webservice to pull data from their database. The web service works fine when I execute it with curl. When I execute in Java, SOAP connection is returning null. I set up the TCP/IP monitor to view the data and it is printing garbage values(both request and response).

 public SOAPMessage createSqlMessage(String cmdName, String sql) throws 
 Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage soapMessage = mf.createMessage();
    MimeHeaders mh = soapMessage.getMimeHeaders();
    mh.addHeader("SOAPAction", "CUCM:DB ver=11.5");
    SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
    SOAPBody bdy = envelope.getBody();
    envelope.addNamespaceDeclaration("ns", "http://www.cisco.com/AXL/API/11.5");
    SOAPBodyElement bodyElement = bdy.addBodyElement(envelope.createName(cmdName));
    bodyElement.setPrefix("ns");
    bodyElement.addAttribute(envelope.createName("sequence"), 
    String.valueOf(System.currentTimeMillis()));
    bodyElement.addChildElement("sql").addTextNode(sql);
    System.out.println("In createSqlMEssage");
    return soapMessage;
}

public String getUrlEndpoint() {
    return new String("https://" + "appUser1" + ":" + password + "@" + "localhost" + ":" + "9443" + "/axl/");
}

 public SOAPMessage sendMessage(SOAPMessage requestMessage) throws Exception {

    SOAPMessage reply = null;
    try {
        System.out.println("URL" + getUrlEndpoint());
        reply = con.call(requestMessage, getUrlEndpoint());
        System.out.println("After getting URL");
        if (reply != null) {
            System.out.println("Inside if");
            SOAPPart replySP = reply.getSOAPPart();
            SOAPEnvelope replySE = replySP.getEnvelope();
            SOAPBody replySB = replySE.getBody();

            if (replySB.hasFault()) System.out.println("ERROR: " + replySB.getFault().getFaultString());
            String a = convertSOAPtoString(reply);
            a=a.replaceAll("<row>","").replaceAll("</output>","").replaceAll("<output>","").replaceAll("</return>.*","").replaceAll(".*<return>","");
            String[] split=a.split("</row>");
            for(String e : split){
                System.out.println(e);
                if(e.toLowerCase().contains("broderick")) continue;
                String[] input = e.split(",",-1);
                System.out.println(input.length);
                LogSQL.insertLog(input[0],input[1],input[2],input[3]);
            }

        }
    }
    catch (Exception e) {
        System.out.println("return started here" + reply);
        System.out.println(e);
        e.printStackTrace();
        throw e;
    }
    return reply;
}

Can anyone help me?

Shik9
  • 15
  • 4

2 Answers2

0

By looking into your Code, You are about to monitor HTTPS traffic.

Try with HTTP Traffic which will not have Junk Values i.e will not be Encrypted.

For HTTPS Traffic, I would prefer Wireshark to monitor request or response.

Refer Capturing HTTPS traffic in the clear?

Sundar Rajan
  • 556
  • 4
  • 25
  • The web service won't allow the HTTP traffic. I tried, it throws "Message send failed" error. I looked at the Wireshark, there is some communication going between the two hosts(ack is done and data is sent), but I do not know how to read wire shark output data. – Shik9 Feb 09 '18 at 18:38
  • Filter by XML to read soap response and request alone. There are several filter options. – Sundar Rajan Feb 09 '18 at 18:39
  • the SOAP response has some data which includes hyphen(-), Does SOAP handle hyphen as special character? Just wondering – Shik9 Feb 09 '18 at 18:40
  • Filtered with XML, it says not valid XML file – Shik9 Feb 09 '18 at 18:41
  • You must try filter text as 'xml' in wireshark filter search bar once you are watching the right adapter. – Sundar Rajan Feb 10 '18 at 18:31
0

So Finally found the error in my code. Sharing it as it might be helpful for someone who are new to java like me. I have used different tools like wireshark, TCP/IP monitor to check what is going on or find the error. I didn't knew about Java debug option in Eclipse. I turned on the Debug with below argument. -Djavax.net.debug=all This showed me what the error was. The error was, I added the header to look for CUCM database 11.5. The 11.5 version didn't exist. I corrected this and it worked.

Shik9
  • 15
  • 4