ArrayOfXXX class out of soap input param of array type

五迷三道 提交于 2020-01-23 09:33:12

问题


I have a method with input param as Array. When I generate stub out of it creates List type.

But I want to know how to create a wrapper class around array type e.g. for class Apple it should create ArrayOfApple.

Is there any change needs to be done in class or any specific plugin need to be used?

Note: I am using JAXWS with Apache CXF implementation

Below is the sample code:

EmployeeService.java:

@WebService(endpointInterface="com.test.EmployeeService")
@SOAPBinding(style=Style.DOCUMENT)
public class EmployeeService {

    public String updateEmpRoles(@WebParam(name="EmpRoles")EmpRole[] empRoles) {
        return "SUCCESS";
    }
}

EmpRole.java :

@XmlType(name="EmpRole")
public class EmpRole {
    private String empRole;

    public String getEmpRole() {
        return empRole;
    }

    public void setEmpRole(String empRole) {
        this.empRole = empRole;
    }
}

After publishing, wsdl is getting generated as below -

But what I expect is WSDL should create ArrayOfEmpRole and it should wrap List<EmpRole>.

Kindly help

In short - I want something that Björn doesn't want in below link. (In his case, it's automatically creating ArrayOfXXX, this is what I need) - Arrays in SOAP method Parameters generated via JAX-WS?


回答1:


I would switch from Code first to a Contract first approach which means start with the WSDL and generate a stub using wsdl2java from it. This way you can ensure that the WSDL looks like the way you want.

If you want to stick to the current approach, the easiest way to achieve a wrapper is probably to introduce another class.



来源:https://stackoverflow.com/questions/53514875/arrayofxxx-class-out-of-soap-input-param-of-array-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!