我需要在 json 中生成 REST 服务的 wadl 的 json 表示:
@Description("Service for reading books")
@Path("/bookService")
public interface BookService
{
@GET
@Path("/getBook")
@Produces(
{"application/xml",
"application/json"})
@Description("Get Book for a given id")
public Book getBook(@QueryParam("bookId") Integer id) throws Exception;
}
在 localhost:8080/services/?_wadl 给我
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<grammars />
<resources base="http://localhost:8080/services/">
<resource path="/bookService" id="books.rs.BookServiceImpl">
<doc>Service for reading books.</doc>
<resource path="/getBook">
<method name="GET" id="getBook">
<doc>Get Book for a given id</doc>
<request>
<param name="bookId" style="query" type="xs:int" />
</request>
<response>
<representation mediaType="application/xml" />
<representation mediaType="application/json" />
</response>
</method>
</resource>
</resource>
</resources>
</application>
下面是服务的服务配置,这里应该是什么 json 模式来获取 wadl 的 json 表示
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<ref bean="bookService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean id="jacksonJsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
<bean class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<property name="linkJsonToXmlSchema" value="true" />
<property name="schemaLocations">
<list>
<value>classpath:/json.schema</value>
</list>
</property>
<property name="useJaxbContextForQnames" value="true" />
<property name="ignoreMessageWriters" value="true" />
<property name="addResourceAndMethodIds" value="true" />
</bean>
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="serializeAsArray" value="true" />
</bean>
</jaxrs:providers>
</jaxrs:server>