监听端口,获取webService请求报文

时间:2021-10-12 23:44:58

第一步下载我们的wsdl文件到本地

第二步建立一个测试webservice工程,把wsdl放在项目里面

第三步把测试webservice中的wsdlLocation改成localhost.....你的wsdl本地项目的地址.

第四步wsdl中的地址改成127.0.0.1 如果是域名则在host文件中配置

第五步创建java项目监听80端口

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
ServerSocket ss;
Socket serverSocket;
InputStream inStream;
OutputStream outStream;

public Server() {
try {
System.out.println("====================Server==================");
ss = new ServerSocket(80);
serverSocket = ss.accept();
System.out
.println("--------------some guest connected----------------");
inStream = serverSocket.getInputStream();
outStream = serverSocket.getOutputStream();

} catch (Exception e) {
e.printStackTrace();
}
}

public void conn() {
new Thread() {
public void run() {
try {
InputStreamReader iReader = new InputStreamReader(inStream);
BufferedReader iBufferStream = new BufferedReader(iReader);
String line = null;
while ((line = iBufferStream.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}

public static void main(String args[]) {
Server server = new Server();
server.conn();
}
}

第六步运行监听程序

第七步访问测试webservice接口,监听程序就会打印出你发送的soap协议报文.webservice底层还是根据http协议传输的.
---------------------
原文:https://blog.csdn.net/u012938226/article/details/50522916