incubator-agila-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davide Ling <lin...@libero.it>
Subject Re: get back the response message
Date Sun, 05 Feb 2006 20:07:15 GMT
On Sunday 05 February 2006 20:08, tnguyen@symcor.com wrote:
> Davidee,
>
> I try to send this soap message, but I got this exception:
> Feb 5, 2006 2:00:19 PM com.sun.xml.messaging.saaj.soap.MessageImpl
> saveChanges
> SEVERE: SAAJ0540: Error during saving a multipart message
> com.sun.xml.messaging.saaj.SOAPExceptionImpl: Error during saving a
> multipart me

Below is a simple client (non agila client) that send a messege like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
 <guy>
  <name>Davide</name>
  <surname>Ling</surname>
 </guy>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And receive a message like this (from a servlet):
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
  <response>Hello Davide Ling</response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

import java.net.URL; 
 
import javax.xml.soap.MessageFactory; 
import javax.xml.soap.Name; 
import javax.xml.soap.SOAPBody; 
import javax.xml.soap.SOAPConnection; 
import javax.xml.soap.SOAPConnectionFactory; 
import javax.xml.soap.SOAPElement; 
import javax.xml.soap.SOAPFactory; 
import javax.xml.soap.SOAPHeader; 
import javax.xml.soap.SOAPMessage; 
import javax.xml.transform.Transformer; 
import javax.xml.transform.TransformerFactory; 
import javax.xml.transform.dom.DOMSource; 
import javax.xml.transform.stream.StreamResult; 
 
public class Main { 
	public static void main(String[] args) throws Exception { 
		SOAPFactory soapFactory = SOAPFactory.newInstance(); 
 
		MessageFactory mf = MessageFactory.newInstance(); 
		SOAPMessage msg = mf.createMessage(); 
		SOAPBody body = msg.getSOAPBody(); 
		// You can detach the SOAP header in this example
		// msg.getSOAPHeader().detachNode(); 
		 
		Name guyName = soapFactory.createName("guy"); 
		SOAPElement guyElement = body.addBodyElement(guyName); 
		 
		SOAPElement child = soapFactory.createElement("name"); 
		child.addTextNode("Davide"); 
		guyElement.addChildElement(child); 
		 
		child = soapFactory.createElement("surname"); 
		child.addTextNode("Ling"); 
		guyElement.addChildElement(child); 
		 
		msg.saveChanges(); 
		 
		// Create the connection
		SOAPConnectionFactory scf =  
			SOAPConnectionFactory.newInstance(); 
			SOAPConnection con = scf.createConnection(); 
			 
		// Send the message
		System.out.println("Send the SOAP message\n"); 
		URL endpoint = new URL("http://localhost:8080/SOAPServlet/SOAP"); 
		SOAPMessage response = con.call(msg,endpoint); 
		 
		// Print sent message
		System.out.println("Sent:"); 
		Transformer trans = TransformerFactory.newInstance().newTransformer(); 
		trans.transform(new DOMSource(msg.getSOAPPart()),new 
StreamResult(System.out)); 
		 
		// Print response message
		System.out.println("\n\nReceived:"); 
		trans.transform(new DOMSource(response.getSOAPPart()),new 
StreamResult(System.out)); 
	} 
}

Bye
-- 
Davide Ling
Sito Personale - http://davideling.altervista.org
Key fingerprint = 284A 0FB9 F9F6 763C D429  E02B AA5D 483A 7E45 D2A6

Mime
View raw message