0

I'm currently working on a custom SOAP call to a specific domain beyond my control. I know the SOAP call fails but I cannot seem to grab the returned (wrong)value.

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:

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. 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.

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). 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?

JustLudo
  • 1,690
  • 12
  • 29
  • You might try to learn the raw content either from the soap message or the soap part as suggested in [this thread](https://stackoverflow.com/questions/522395/getting-raw-xml-from-soapmessage-in-java) – Roman Vottner Apr 26 '19 at 16:22
  • [This blog post](https://aykutakin.wordpress.com/2014/03/20/logging-soap-web-service-request-and-response/) suggest to use a custom handler for logging raw SOAP requests and responses – Roman Vottner Apr 26 '19 at 16:29
  • @RomanVottner: Thanks for the replies. I will look into these posts. – JustLudo Apr 29 '19 at 06:58

1 Answers1

0

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

Piaget Hadzizi
  • 702
  • 8
  • 15
  • Hi Piaget. Perhaps I'm completely mistaken but I don't see how that should be solving my issue. I know for a fact that the expected response is not the same as the actual response (I expect a SOAP message, but instead get plain HTML). I was wondering when I need to intervene in order to actually see the reply output (in this case the HTML). Even if the headers are wrong, there is likely something else wrong as well. I do appreciate the effort you took to write this answer. – JustLudo Apr 26 '19 at 13:28