springboot整合webservice修改cxf自动生成wsdl的soap:address location

近期系统中的webservice接口要上线

通过http://localhost:8080/webServices/testService?wsdl走网关访问时,返回的<soap:address location>是真实业务服务的ip:port。因为我们只能暴露网关的ip和端口,需要将真实服务的ip和端口隐藏起来。

    @Bean
    public Endpoint messagePoint() throws IOException {
        EndpointImpl endpoint = new EndpointImpl(this.springBus(), this.testService);
        endpoint.setPublishedEndpointUrl("http://yourdomain.com/yourServicePath");
        endpoint.publish("/testService");
        return endpoint;
    }

这时候我们在创建Endpoint的时候,可以通过配置setPublishedEndpointUrl()展示wsdl文件中<soap:address location>发布地址。

效果如下:

<wsdl:service name="testService">
<wsdl:port binding="tns:testServiceSoapBinding" name="TestServiceImplPort">
<soap:address location="http://yourdomain.com/yourServicePath"/>
</wsdl:port>
</wsdl:service>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用`AbstractPhaseInterceptor`类可以拦截CXF的消息处理流程,并对消息进行修改。 首先,您需要继承`AbstractPhaseInterceptor`类,并实现`handleMessage`方法。在`handleMessage`方法中,您可以获取到请求或响应消息,并对其进行修改。 例如,以下代码演示了如何使用`AbstractPhaseInterceptor`类修改SOAP请求消息中的请求体: ```java import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.interceptor.AbstractPhaseInterceptor; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.phase.Phase; import javax.xml.namespace.QName; import java.util.List; public class MyInterceptor extends AbstractPhaseInterceptor<SoapMessage> { public MyInterceptor() { super(Phase.PRE_PROTOCOL); } @Override public void handleMessage(SoapMessage message) throws Fault { List<SoapHeader> headers = message.getHeaders(); // 获取SOAP请求消息中的请求体 String requestBody = message.getContent(String.class); // 对请求体进行修改 String modifiedRequestBody = modifyRequestBody(requestBody); // 将修改后的请求体设置回SOAP消息中 message.setContent(String.class, modifiedRequestBody); } private String modifyRequestBody(String requestBody) { // TODO: 对请求体进行修改 return requestBody; } } ``` 在上述代码中,我们创建了一个`MyInterceptor`类,继承自`AbstractPhaseInterceptor`。在`handleMessage`方法中,我们首先获取了SOAP请求消息中的SOAP头和SOAP体,然后对SOAP体进行了修改,最后将修改后的SOAP体设置回SOAP消息中。 您可以根据需要修改`modifyRequestBody`方法,来对SOAP请求消息进行任意修改。另外,如果您需要修改SOAP响应消息,可以在`handleFault`方法中进行相应的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值