springboot调用webservice接口,如何添加账号密码认证?
客户端
代码是通过idea调用服务的wsdl自动生成的
HelloWorldClient是自己写的,
客户端请求拦截器,已经写好就是不知道怎么添加到HelloWorldClient
package com.suiwei.wsClient;import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.headers.Header;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.namespace.QName;
import java.util.List;
/**
* @author suiwei
* @date 2023-04-24 16:42
*/
public class ClientLoginInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
private String username;
private String password;
public ClientLoginInterceptor(String username, String password) {
super(Phase.PREPARE_SEND);
this.username = username;
this.password = password;
}
@Override
public void handleMessage(SoapMessage soap) throws Fault {
List<Header> headers = soap.getHeaders();//获取全部头信息
Document doc = DOMUtils.createDocument();
Element auth = doc.createElement("authority");
Element username = doc.createElement("username");
Element password = doc.createElement("password");
username.setTextContent(this.username);
password.setTextContent(this.password);
auth.appendChild(username);
auth.appendChild(password);
headers.add(0,new Header(new QName("authority"),auth));
}
}
以上是 springboot调用webservice接口,如何添加账号密码认证? 的全部内容, 来源链接: utcz.com/p/945131.html