📄 jaxmsoapclient.java
字号:
import java.io.*;
import javax.xml.soap.*;
import javax.xml.messaging.*;
import java.net.URL;
import javax.mail.internet.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import org.dom4j.*;
public class JAXMSOAPClient {
public static void main(String[] args) {
try {
//Author a SOAP request.
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage request = messageFactory.createMessage();
SOAPPart soapPartOfRequest = request.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPartOfRequest.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
Name methodName = soapEnvelope.createName("invoke", "jaxm",
"urn:P2PCarRental");
soapBody.addChildElement(methodName);
//Add code for SOAP Header authoring here.
//Establish the SOAP connection.
URLEndpoint soapServerAddress = new URLEndpoint(
"http://localhost:8080/soap/servlet/rpcrouter");
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connectionFactory.createConnection();
//Display the request.
System.out.println();
System.out.println("Sending SOAP request:");
request.writeTo(System.out);
System.out.println();
//Send the request and wait for the response.
SOAPMessage soapResponse = connection.call(request,
soapServerAddress);
//We have received the response.Display it.
System.out.println();
System.out.println("Received reply from:" + soapServerAddress);
soapResponse.writeTo(System.out);
//Job done.Close the connection.
connection.close();
} catch (Throwable e) {
e.printStackTrace();
} //catch
} //main
} //class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -