SOAP SERVICE USING JAXM and SAAJ
Hi,
I am trying to create a SOAP service and i am using JAVA SUN APPLICATION SERVER (Ver 9)
Even with the example posted on the jaxm I am not able to run.
http://developers.sun.com/sw/building/codesamples/jaxm/index.html
Though the example is written for Sun Application Server 7.
I belive it should run even with App Server 8 or 9.
I tried with another simple example listed below.
Would appreciate if anyone replies.
The error which i am getting is
SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message
com.sun.xml.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPE
ceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnectio n.java:127)
at SendSOAPMessage.sendMessage(SendSOAPMessage.java:86)
at SendSOAPMessage.main(SendSOAPMessage.java:124)
Caused by: java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:
ext/html. Is this an error message instead of a SOAP response?
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnectio n.java:121)
... 2 more
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message inste
d of a SOAP response?
at com.sun.xml.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.jav a:581)
at com.sun.xml.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactory Impl.java:70)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnectio n.java:374)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(Ht tpSOAPConnection.java:150)
... 4 more
CAUSE:
java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html.
s this an error message instead of a SOAP response?
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnectio n.java:121)
at SendSOAPMessage.sendMessage(SendSOAPMessage.java:86)
at SendSOAPMessage.main(SendSOAPMessage.java:124)
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message inste
d of a SOAP response?
at com.sun.xml.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.jav a:581)
at com.sun.xml.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactory Impl.java:70)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnectio n.java:374)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(Ht tpSOAPConnection.java:150)
... 4 more
Server Side
import javax.xml.messaging.JAXMServlet;
import javax.xml.messaging.ReqRespListener;
import javax.xml.soap.SOAPMessage;
import java.io.*;
/**
* This example echos the SOAP message received back to the sender.
*/
public class SOAPEchoServlet extends JAXMServlet implements ReqRespListener {
/**
* SOAP Message received is echoed back to the sender.
*/
public SOAPMessage onMessage (SOAPMessage soapMessage) {
return soapMessage;
}
}
Client Side
import javax.xml.messaging.URLEndpoint;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPConnection;
/**
* This example demonstrates a hello world example for using JAXM API.
*/
public class SendSOAPMessage {
/**
* send a simple soap message with JAXM API.
*/
public void sendMessage (String url) {
try {
//System.setProperty("javax.xml.soap.MessageFactory", "com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl");
//System.setProperty("javax.xml.soap.MessageFactory", "com.sun.xml.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl");
/**
* Construct a default SOAP connection factory.
*/
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
/**
* Get SOAP connection.
*/
SOAPConnection soapConnection = connectionFactory.createConnection();
/**
* Construct a default SOAP message factory.
*/
MessageFactory mf = MessageFactory.newInstance();
/**
* Create a SOAP message object.
*/
SOAPMessage soapMessage = mf.createMessage();
/**
* Get SOAP part.
*/
SOAPPart soapPart = soapMessage.getSOAPPart();
/**
* Get SOAP envelope.
*/
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
/**
* Get SOAP body.
*/
SOAPBody soapBody = soapEnvelope.getBody();
/**
* Add child element with the specified name.
*/
//SOAPElement element = soapBody.addChildElement("HelloWorld");
/**
* Add text message
*/
//element.addTextNode("Welcome to SunOne Web Services!");
soapMessage.saveChanges();
/**
* Construct endpoint object.
*/
URLEndpoint endpoint = new URLEndpoint (url);
/**
* Send SOAP message.
*/
System.out.println("JUST BEFORE CALL METHOD");
SOAPMessage resp = soapConnection.call(soapMessage, endpoint);
/**
* Print response to the std output.
*/
resp.writeTo( System.out );
/**
* close the connection
*/
soapConnection.close();
}catch (java.io.IOException ioe) {
ioe.printStackTrace();
System.out.println("In the IO Exception");
} catch (SOAPException soape) {
soape.printStackTrace();
System.out.println("In the SOAP Exception");
} catch(Exception ex){
System.out.println("In the main Excpetion");
}
}
public static void main (String args[]) {
String url = "http://localhost:8080/imqSOAPexamples/SOAPEchoServlet";
if (args.length > 0) {
url = args[0];
} else {
System.out.println("Usage: " +
"\tjava SendSOAPMessage <SOAP servlet url>\n" +
"e.g.\n\tjava SendSOAPMessage http://localhost:8080/imqSOAPexamples/SOAPEchoServlet"
);
System.exit(1);
}
SendSOAPMessage ssm = new SendSOAPMessage();
ssm.sendMessage(url);
}
}

