import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnectionFactory;
...
public void send() throws SOAPException{
// SOAPConnectionのインスタンスを生成します
SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
SOAPConnection conn = connFactory.createConnection();
// SOAPBodyを生成します
MessageFactory mesgFactory = MessageFactory.newInstance();
SOAPMessage message = mesgFactory.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope env = part.getEnvelope();
SOAPBody body = env.getBody();
// SOAPBodyに送信データを設定します
Name bodyRoot = env.createName("dispatch",null,"urn:fujitsu-apcoordinator-soap");
SOAPBodyElement elt = body.addBodyElement(bodyRoot);
Name verb = env.createName("verb");
Name xml = env.createName("root");
Name data = env.createName("data");
elt.addChildElement(verb).addTextNode("command");
elt.addChildElement(xml).addChildElement(data).addTextNode("text");
message.saveChanges();
// メッセージを送信し、レスポンスを受信します。
SOAPMessage resMessage = conn.call(message,"http://SoapHost/soap/servlet/WSContainer");
conn.close();
}
|