gpt4 book ai didi

java - Apache CXF JAX-RS 表示元素未定义

转载 作者:行者123 更新时间:2023-11-29 08:46:05 25 4
gpt4 key购买 nike

利用 Jackson (1.9.13) 和 Apache CXF (2.7.11),我生成的 WADL 不包含参数或响应表示上的“元素”节点(因此定义输入/返回类型是什么),尽管它在“语法”中被正确定义。我的返回对象上确实有一个命名空间和@XMLRootElement(因此它出现在语法中),但该元素仍未在类型上定义。任何想法表示赞赏。

这是我的对象:

@XmlRootElement(name = "testObject", namespace = "http://test.com/test")
public class TestObject {

private String sparky;
private String skippy;
private int goober;

public TestObject() {
// TODO Auto-generated constructor stub
}

public String getSparky() {
return sparky;
}

public void setSparky(String sparky) {
this.sparky = sparky;
}

public String getSkippy() {
return skippy;
}

public void setSkippy(String skippy) {
this.skippy = skippy;
}

public int getGoober() {
return goober;
}

public void setGoober(int goober) {
this.goober = goober;
}

}

还有我的 JAX-RS 服务类(作为返回和请求类型):

@Path("/testservice")
@WebService
@Produces(MediaType.APPLICATION_JSON)
public class TestService {
@Path("/getTestObject2")
@GET
@WebMethod
@ElementClass(response=TestObject.class)
public TestObject getTestObject2(@QueryParam("skippy") String skippy) {
TestObject myReturn = new TestObject();
myReturn.setGoober(1);
myReturn.setSkippy("Yep. It's skippy" + 1);
myReturn.setSparky("Here sparky. Here boy" + 1);

return myReturn;
}

@Path("/getTestObject3")
@POST
@WebMethod
@ElementClass(request=TestObject.class)
public String getTestObject3(@QueryParam("skippy") TestObject skippy) {
TestObject myReturn = new TestObject();
myReturn.setGoober(1);
myReturn.setSkippy("Yep. It's skippy" + 1);
myReturn.setSparky("Here sparky. Here boy" + 1);

return "goo";
}

}

以及我生成的 WADL:

<application xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02">
<grammars>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified" targetNamespace="http://test.com/test">
<xs:complexType name="testObject">
<xs:sequence>
<xs:element name="goober" type="xs:int"/>
<xs:element name="skippy" type="xs:string" minOccurs="0"/>
<xs:element name="sparky" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified" targetNamespace="http://test.com/test">
<xs:import/>
<xs:element name="testObject" type="testObject"/>
</xs:schema>
</grammars>
<resources base="http://localhost:8080/fedapp/test/frankwebservice/services/jaxrs">
<resource path="/testservice">
<resource path="/getTestObject2">
<method name="GET">
<request>
<param name="skippy" type="xs:string" style="query"/>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
<resource path="/getTestObject3">
<method name="POST">
<request>
<param name="skippy" style="query"/>
</request>
<response>
<representation mediaType="application/json">
<param name="result" type="xs:string" style="plain"/>
</representation>
</response>
</method>
</resource>
</resource>
</resources>
</application>

最佳答案

尝试在您的 TestObject skippy 上使用 @QueryParam("") 而不是 @QueryParam("skippy") TestObject skippy

关于java - Apache CXF JAX-RS 表示元素未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25289279/

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