简体   繁体   English

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

[英]Apache CXF JAX-RS representation element not defined

Utilizing Jackson (1.9.13) with Apache CXF (2.7.11), the generation of my WADL does not contain the "element" node on the parameter or response representation (therefore defining what the input/return type is), although it is defined in the "grammars" correctly. 利用Apache CXF(2.7.11)的Jackson(1.9.13),我的WADL的生成在参数或响应表示中不包含“元素”节点(因此定义了输入/返回类型是什么),尽管它是正确地在“语法”中定义。 I do have a namespace and @XMLRootElement on my return object (hence why it shows up in the grammar), but the element is still not defined on the types. 我的返回对象上确实有一个名称空间和@XMLRootElement(因此为什么它会出现在语法中),但是该元素仍未在类型上定义。 Any ideas are appreciated. 任何想法表示赞赏。

Here is my Object: 这是我的对象:

@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;
}

}

And my JAX-RS service class (both as return and request types): 还有我的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";
}

}

And my generated WADL: 我生成的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上使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM