1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| package ws.complexTypeExample;
import java.io.IOException;
import java.util.LinkedHashMap;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.ws.soap.SOAPFaultException;
import org.w3c.dom.NodeList;
public class CreatComplexTypeRequestTest {
public static SOAPBodyElement payload;
private static Name BankName;
private static SOAPBody body ;
public SOAPMessage creatSoapRequestMessage (String targetNSpace, String operationName, LinkedHashMap<String,String> paramNamesToTypes) throws SOAPFaultException, SOAPException, IOException {
SOAPMessage request = MessageFactory.newInstance().createMessage();
SOAPPart part = request.getSOAPPart();
SOAPEnvelope env = part.getEnvelope();
env.addNamespaceDeclaration("exam", targetNSpace);
env.addNamespaceDeclaration("xsd", "http://example.ws/xsd");
body = env.getBody();
SOAPFactory soapfactory = SOAPFactory.newInstance();
BankName = soapfactory.createName(operationName, "exam", targetNSpace);
payload = body.addBodyElement( BankName);
SOAPElement client = payload.addChildElement("client","xsd");
SOAPElement add = client.addChildElement("address", "xsd");
add.addTextNode("addes");
SOAPElement am = client.addChildElement("amount", "xsd");
am.addTextNode("2999");
SOAPElement ln = client.addChildElement("clientN", "xsd");
ln.addTextNode("NN");
SOAPElement ph = client.addChildElement("phone", "xsd");
ph.addTextNode("1267");
request.saveChanges();
request.writeTo(System.out);
return request;
} |
Partager