我设法使用org.jboss.resteasy.wadl.ResteasyWadlServlet
(https://stackoverflow.com/a/41471710/2528609)获得了WADL,但WADL不包含语法。表示节点也不包含定义响应类型的element
属性。
给出以下休息端点类
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("user")
public class UserEndpoint {
@GET
@Path("")
@Produces(MediaType.APPLICATION_JSON)
public UserResponse getUser() {
UserResponse response = new UserResponse();
response.name = "Michiel";
response.age = 43;
return response;
}
}
和
public class UserResponse {
public String name;
public int age;
}
导航到端点时,我确实获得了正确的JSON,但在导航到application.xml URL时,我得到了
<application xmlns="http://wadl.dev.java.net/2009/02">
<resources base="http://localhost:8080/box/rest">
<resource path="user">
<resource path="">
<method id="getUser" name="GET">
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
</resources>
</application>
WADL没有描述UserResponse类,也没有将它指示为getUser方法的元素类型。
我本来期望的是:
<application xmlns="http://wadl.dev.java.net/2009/02">
<grammars>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="...">
<xs:complexType name="UerResponse">
<xs:sequence>
...
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars>
<resources base="http://localhost:8080/box/rest">
<resource path="user">
<resource path="">
<method id="getUser" name="GET">
<response>
<representation mediaType="application/json"element="prefix1:UserResponse"/>
</response>
</method>
</resource>
</resources>
</application>
如何让生成的WADL包含语法部分?
这是我的web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>RESTEasy WADL</servlet-name>
<servlet-class>org.jboss.resteasy.wadl.ResteasyWadlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy WADL</servlet-name>
<url-pattern>/application.xml</url-pattern>
</servlet-mapping>
</web-app>
这些是我的pom.xml中的依赖项:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-wadl -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-wadl</artifactId>
<version>3.0.19.Final</version>
<exclusions>
<exclusion>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
我使用JBoss Wildfly 10.1.0。