Forum Stats

  • 3,733,357 Users
  • 2,246,747 Discussions
  • 7,856,667 Comments

Discussions

"SAAJ0537: Invalid Content-Type" Exception

2682989
2682989 Member Posts: 1

Hi,

When I try to execute the sample code, I'm getting exception. In my classpath I have added the jars (activation, saaj-api, jaxm-api)

I tried to get some response from the OTN community but it was archived.

Code Example:

public class SaajSample {

  public static void main(String[] args)  {

     try {

       SOAPConnectionFactory scFactory =

           SOAPConnectionFactory.newInstance();

       SOAPConnection con = scFactory.createConnection();

  

       MessageFactory factory =        MessageFactory.newInstance();

       SOAPMessage message = factory.createMessage();

  

       SOAPPart soapPart = message.getSOAPPart();

       SOAPEnvelope envelope = soapPart.getEnvelope();

       SOAPHeader header = envelope.getHeader();

       SOAPBody body = envelope.getBody();

       header.detachNode();

  

       Name bodyName = envelope.createName(

               "GetLastTradePrice", "m",

               "http://wombats.ztrade.com");

       SOAPBodyElement gltp =

               body.addBodyElement(bodyName);

  

       Name name = envelope.createName("symbol");

       SOAPElement symbol = gltp.addChildElement(name);

       symbol.addTextNode("SUNW");

  

      // URL endpoint = new URL("http://wombat.ztrade.com/quotes");

       URLEndpoint endpoint = new URLEndpoint("http://wombat.ztrade.com/quotes");

      

       SOAPMessage response = con.call(message, endpoint);

  

       con.close();

  

       SOAPPart sp = response.getSOAPPart();

       SOAPEnvelope se = sp.getEnvelope();

       SOAPBody sb = se.getBody();

  

       Iterator it = sb.getChildElements(bodyName);

       SOAPBodyElement bodyElement =

               (SOAPBodyElement)it.next();

       String lastPrice = bodyElement.getValue();

  

       System.out.print("The last price for SUNW is ");

       System.out.println(lastPrice);

  

     } catch (Exception ex) {

       ex.printStackTrace();

     }

   }

}

Exception:

May 29, 2014 3:23:57 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl identifyContentType

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?

  at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:148)

  at com.soaptest.SaajSample.main(SaajSample.java:49)

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

  at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:655)

  at com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:85)

  at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:327)

  at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144)

  ... 1 more

Please suggest some solution for me (or) share some sample program for me to test.

Thanks in advance.

Regards,

RPC

This discussion has been closed.