简体   繁体   English

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

[英]SOAP Request and Response printing junk characters

I am using cisco axl webservice to pull data from their database. 我正在使用cisco axl webservice从其数据库中提取数据。 The web service works fine when I execute it with curl. 当我执行curl时,Web服务可以正常工作。 When I execute in Java, SOAP connection is returning null. 当我用Java执行时,SOAP连接返回null。 I set up the TCP/IP monitor to view the data and it is printing garbage values(both request and response). 我设置了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;
}

Can anyone help me? 谁能帮我?

By looking into your Code, You are about to monitor HTTPS traffic. 通过查看您的代码,您将监视HTTPS通信。

Try with HTTP Traffic which will not have Junk Values ie will not be Encrypted. 尝试使用HTTP流量,该流量将没有垃圾值,即不会被加密。

For HTTPS Traffic, I would prefer Wireshark to monitor request or response. 对于HTTPS流量,我希望Wireshark监视请求或响应。

Refer Capturing HTTPS traffic in the clear? 请参阅明确捕获HTTPS流量?

So Finally found the error in my code. 所以终于在我的代码中找到了错误。 Sharing it as it might be helpful for someone who are new to java like me. 共享它,对像我这样的Java新手来说可能会有所帮助。 I have used different tools like wireshark, TCP/IP monitor to check what is going on or find the error. 我使用了不同的工具,例如Wireshark,TCP / IP监视器来检查发生了什么或发现错误。 I didn't knew about Java debug option in Eclipse. 我不了解Eclipse中的Java调试选项。 I turned on the Debug with below argument. 我用下面的参数打开了调试。 -Djavax.net.debug=all This showed me what the error was. -Djavax.net.debug = all这向我显示了错误所在。 The error was, I added the header to look for CUCM database 11.5. 错误是,我添加了标题以查找CUCM数据库11.5。 The 11.5 version didn't exist. 11.5版本不存在。 I corrected this and it worked. 我纠正了这一点,它奏效了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM