简体   繁体   中英

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. 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. 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):

@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:

<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上使用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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