cxf-java2ws-plugin および cxf-codegen-plugin を使用して Maven 経由で CXF 2.7.11 を使用すると、Web サービス クラスから WSDL が生成され、そこから WSDL プロキシ クラスが生成され、さまざまなクライアントで使用されて実際のライブサーバー。
これらの生成されたサービス プロキシには、null 配列が渡されると NullPointerException が発生するという問題があります。
Web サービスは次のようなものです。
public class MyService {
public SomeResult someMethod(String param, String[] otherParams) {
if (otherParams == null){
... etc etc...
}
}
}
生成された WSDL フラグメント:
<xs:complexType name="someMethod">
<xs:sequence>
<xs:element minOccurs="0" name="param1" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="otherParams" type="xs:string"/>
</xs:sequence>
</xs:complexType>
最後に生成されたサービス プロキシ フラグメント:
public class SomeMethod
{
protected String param1;
protected String[] otherParams;
...
public String[] getOtherParams()
{
// Good, defensive code used here
if (this.otherParams == null)
{
return new String[0];
}
String[] retVal = new String[this.otherParams.length];
System.arraycopy(this.otherParams, 0, retVal, 0, this.otherParams.length);
return (retVal);
}
...
public void setOtherParams(String[] values)
{
// Complete lack of defensive code here!
int len = values.length;
this.otherParams = ((String[]) new String[len]);
for (int i = 0; (i < len); i++)
{
this.otherParams[i] = values[i];
}
}
public String setOtherParams(int idx,
String value)
{
// And here
return this.otherParams[idx] = value;
}
}
WSDL 生成用の pom.xml フラグメント:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>2.7.11</version>
<executions>
<execution>
<id>generate-wsdl-MyService</id>
<phase>process-classes</phase>
<goals>
<goal>java2ws</goal>
</goals>
<configuration>
<className>com.somewhere.services.MyService</className>
<serviceName>MyService</serviceName>
<genWsdl>true</genWsdl>
</configuration>
</execution>
</executions>
<plugin>
上記の WSDL からプロキシを生成するための pom.xml フラグメント:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.11</version>
<executions>
<execution>
<id>generate-service-proxies</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<defaultOptions>
<bindingFiles>
<bindingFile>some/location/jaxws-binding.xjb</bindingFile>
<bindingFile>some/location/jaxb-binding.xjb</bindingFile>
</bindingFiles>
<extraargs>
<extraarg>-fe</extraarg>
<extraarg>jaxws21</extraarg>
<extraarg>-xjc-npa</extraarg>
</extraargs>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>some/location/generated/wsdl/MyService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
</plugin>
null 配列を渡したいクライアントに対処するサービス プロキシを CXF に生成させるにはどうすればよいですか? (空の配列または null を含む配列ではなく、実際の null 配列)。WSDL で「nillable=true」として宣言された「otherParams」が必要ですか? もしそうなら、どのように?
多くの注釈と JAXB/JAXWS オプションを試しましたが、望ましい動作が得られないようです。