SOAP请求和响应打印垃圾字符

时间:2018-02-09 18:03:34

标签: java web-services soap

我正在使用cisco axl webservice从他们的数据库中提取数据。当我用curl执行它时,Web服务正常工作。当我在Java中执行时,SOAP连接返回null。我设置了TCP / IP监视器来查看数据,它正在打印垃圾值(请求和响应)。

 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;
}

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

通过查看您的代码,您即将监控HTTPS流量。

尝试使用不具有垃圾值的HTTP流量,即不会加密。

对于HTTPS流量,我更希望Wireshark监控请求或响应。​​

参考Capturing HTTPS traffic in the clear?

答案 1 :(得分:0)

所以终于在我的代码中找到了错误。分享它可能对像我这样刚接触java的人有帮助。 我使用了不同的工具,如wireshark,TCP / IP监视器来检查发生了什么或发现错误。我在Eclipse中并不了解Java调试选项。 我用下面的参数打开了Debug。       -Djavax.net.debug =所有 这告诉我错误是什么。错误是,我添加了标题以查找CUCM数据库11.5。 11.5版本并不存在。我纠正了这个并且有效。