简体   繁体   English

无法在SOAP调用中查看回复

[英]Unable to view reply in SOAP call

I'm currently working on a custom SOAP call to a specific domain beyond my control. 我正在开发一个对我无法控制的特定域的自定义SOAP调用。 I know the SOAP call fails but I cannot seem to grab the returned (wrong)value. 我知道SOAP调用失败但我似乎无法获取返回的(错误的)值。

Right now I'm using the code below: 现在我正在使用下面的代码:

                    Document document = convertStringToDocument(this.MeldingString);
                // System.out.println(document);
                SOAPConnectionFactory myFct = SOAPConnectionFactory.newInstance();
                MessageFactory myMsgFct = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
                SOAPMessage message = myMsgFct.createMessage();
                SOAPConnection myCon = myFct.createConnection();

                // Adding parts
                SOAPPart mySPart = message.getSOAPPart();
                SOAPEnvelope myEnvp = mySPart.getEnvelope();

                // Escape the password for usage in header
                String escpwd = StringEscapeUtils.escapeJava(this.Password);

                // Header
                MimeHeaders headers = message.getMimeHeaders();
                headers.setHeader("Content-Type", "application/soap+xml;charset=UTF-8");
                headers.setHeader("Authorization", this.Username + ":" + escpwd);

                // Body
                SOAPBody body = myEnvp.getBody();
                body.addDocument(document);

                // Sending
                Core.getLogger("GetResultSOAPmsg").trace("Started");
                URL endPt = new URL(
                        "URL-TO-MY-SERVICE");
                System.setProperty("java.net.useSystemProxies", "true");
                try {
                    SOAPMessage reply = myCon.call(message, endPt); "UTF-8");

            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

This yields the following error which is very common al throughout SO: 这会产生以下错误,这在整个SO中非常常见:

SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

Now I have read most of these topics already and they explain how this problem is usually solved (namespaces, escaping URL, etc.) but I cannot seem to figure out what is wrong in my case. 现在我已经阅读了大部分这些主题,他们解释了这个问题通常是如何解决的(命名空间,转义URL等),但我似乎无法弄清楚我的情况有什么问题。 This is a private service and the other side is unfortunately unable to assist me in this case. 这是一项私人服务,遗憾的是另一方在这种情况下无法协助我。 The error could be anything from wrong certificates to misspelling the URL. 错误可能是从错误的证书到拼写错误的URL。

Therefore I would like to actually SEE onscreen what the actual reply is that was received when making the call. 因此,我想实际上在屏幕上看到拨打电话时收到的实际回复。 This is going to help me (assuming it's something like a 503, 404 or other page). 这对我有帮助(假设它像503,404或其他页面)。 Regardless of what I do and where I set my breakpoints, there is no information on Reply. 无论我做什么以及在哪里设置断点,都没有关于回复的信息。 It makes somewhat sense since it was unable to create said object but the entire message seems to be discarded. 它有点意义,因为它无法创建所述对象,但整个消息似乎被丢弃。

In what way will I be able to see what the actual reply was to my call before it is discarded? 在丢弃之前,我能以什么方式查看我的电话的实际回复?

I think there's a problem with your header 我认为你的标题有问题

headers.setHeader("Content-Type", "application/soap+xml;charset=UTF-8");

try something like 尝试类似的东西

headers.setHeader("Content-Type", "application/xml;charset=UTF-8");

or 要么

headers.setHeader("Content-Type", "application/json;charset=UTF-8");

depending on the content type that the content type accepted by the service 取决于服务接受的内容类型的内容类型

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

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