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

时间:2014-08-13 14:46:33

标签: java apache cxf jax-rs wadl

利用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>

1 个答案:

答案 0 :(得分:0)

尝试在TestObject上使用@QueryParam(“”)但不是@QueryParam(“skippy”)TestObject skippy