soap - Renaming an XML/SOAP tag using Apache CXF
问题描述
I've got a SOAP web-service server using Apache CXF as implementation. Due to some external technical constraint I'd like to be able to rename some XML tags naming an operation parameter (which are deprecated) in the inbound SOAP request. I was reading about using Interceptors
for this, but the documentation on how to setup/configure them is not very clear.
My code to publish an endpoint is the following:
Endpoint endpoint = Endpoint.create(
"http://schemas.xmlsoap.org/soap/", new MyServer());
endpoint.publish("ws/endpoint");
Ideally I'd like to add a filter only to a given endpoint (I have several of them).
解决方案
Apache's documentations about interceptors are quite clear (IMO), anyway, there is a helloworld project (based on spring boot, cxf and maven) in my github profile which you can take a look for setting up interceptors (in fact it's a baisc autentication interceptor).
For setting up an interceptor (e.g InInterceptor), your class should extend AbstractPhaseInterceptor<Message>
and override handleMessage(Message message)
method, then in the constructor you should declare the phase
in which the interceptor is going to be applied. Finally you have to instantiate it and apply in on an Endpoint.
As you said:
rename some XML tags naming an operation parameter (which are deprecated) in the inbound SOAP request
I think the name of the operation parameter (in WSDL file) is something different from the argument of your web method. Suppose that there is method in your endpoint named addPerson
:
@WebMethod
String addPerson(Person person) {
/*method logic*/
}
and Person class:
class Person {
private String firstName;
private String lastName;
private Date birthDate;
//getters and setters
}
in order to map lastName
property to a different name, you have to annotate it with
@XmlElement(name = "sureName")
private String lastName;
after applying this anotation, sureName
(in wsdl file) is going to be mapped to lastName
.
In addition, there is @WebParam
annotation which can be used for changing the name of web method arguments:
@WebMethod
String sayHello( @WebParam(name = "sureName") String lastName);
Hope it helps.
推荐阅读
- javascript - 未捕获(承诺中) FirebaseError:缺少权限或权限不足。在新 Rr
- google-apps-script - 将数据输入 Google 表格后以表格形式显示
- javascript - 为什么减去天数不允许我超过 27
- f# - Thoth.Json 得到结果
- javascript - AG Grid表数据复制到剪贴板在反应中不起作用
- javascript - Emitted Event 无法导致调用绑定方法
- java - Java toEquals() 覆盖以包含父类属性
- elixir - 比较 Phoenix 控制器内 Ecto 查询中的字符串 DateTime 参数
- python - 如何在 Pandas 数据框中创建一个新列,其值由同一行中的其他列确定
- html - 如何在编辑器中显示图像保持率