gpt4 book ai didi

java - 在 Eclipse 中将 Java Enums 和 ArrayList 与 JAX-WS 结合使用

转载 作者:行者123 更新时间:2023-12-01 04:50:02 25 4
gpt4 key购买 nike

我目前正在 eclipse(Juno、JavaEE)中使用 JAX-WS 构建 Web 服务。我仅限于使用 JAX-WS 和 Java 1.6(这是我无法控制更新的)

当我尝试从代码生成 Web 服务时遇到的错误是:

The service class "webservice.WebService" does not comply to one ormore requirements of the JAX-RPC 1.1 specification, and may not deployor function correctly.

The field or property "declaringClass" on thevalue type "java.lang.Enum" used via the service class"webservice.WebService" has a data type, "java.lang.Class", that isnot supported by the JAX-RPC 1.1 specification. Instances of the typemay not serialize or deserialize correctly. Loss of data or completefailure of the Web service may result.

The field or property"referenceDataSet" on the value type "webservice.ReferenceDataSetList"used via the service class "webservice.WebService" has a data type,"java.util.ArrayList", that is not supported by the JAX-RPC 1.1specification. Instances of the type may not serialize or deserializecorrectly. Loss of data or complete failure of the Web service mayresult.

生成此警告的@WebMethod是:

@WebMethod
public RequestStatus setReferenceData(ReferenceDataSetList refData)
{
// TODO
RequestStatus status = new RequestStatus(Result.FAILURE);

return status;
}
  • RequestStatus 是一个对象,包含枚举 Result 和可选字符串消息。
  • ReferenceDataSetList 包含一个ArrayList和ReferenceDataSet有相同的地方结构为 RequestStatus(不同的枚举类型)

我环顾四周,找不到任何解决此警告的方法。

我不太确定下一步该去哪里......

编辑我应该补充一点,我可以运行该服务,但我得到的错误是当我尝试生成 WSDL 以便我可以构建客户端时

最佳答案

我不确定可能是什么问题。我使用的是 JDK 6 中的 JAX-WS RI 2.1.6(该运行时是 JDK 的一部分)并且运行顺利。

枚举:

public enum Result {
FAILURE;
}

响应包装:

public class RequestStatus {

private Result result;

public RequestStatus() {
}

public RequestStatus(Result result) {
this.result = result;
}

public Result getResult() {
return result;
}

public void setResult(Result result) {
this.result = result;
}

}

请求包装器:

public lass ReferenceDataSetList {

private List<String> list;

public List<String> getList() {
return list;
}

public void setList(List<String> list) {
this.list = list;
}

}

以及 SEI 类:

package test;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class TestService {

@WebMethod
public RequestStatus setReferenceData(ReferenceDataSetList refData) {
return new RequestStatus(Result.FAILURE);
}

public static void main(String[] args) {
Endpoint.publish("http://localhost:8084/service", new TestService());
}

}

控制台输出是:

28/02/2013 10:34:43 AM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class test.jaxws.SetReferenceData
28/02/2013 10:34:43 AM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class test.jaxws.SetReferenceDataResponse

我可以在 http://localhost:8084/service?wsdl 中看到 WSDL。列表和枚举(片段)的架构是:

<xs:complexType name="setReferenceData">
<xs:sequence>
<xs:element name="arg0" type="tns:referenceDataSetList"
minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="referenceDataSetList">
<xs:sequence>
<xs:element name="list" type="xs:string" nillable="true" minOccurs="0"
maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="requestStatus">
<xs:sequence>
<xs:element name="result" type="tns:result" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="result">
<xs:restriction base="xs:string">
<xs:enumeration value="FAILURE"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>

关于java - 在 Eclipse 中将 Java Enums 和 ArrayList 与 JAX-WS 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15139062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com