WADL in json in CXF

4.1k views Asked by At

I need to generate the json representation of wadl of a REST service in 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;
}

On localhost:8080/services/?_wadl gives me

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

Below is the service config for the service and what should be the json schema here to get the json representation of wadl

<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>
1

There are 1 answers

0
vivek On

Try ?_wadl&_type=json for json and ?_wadl&_type=xml for xml