在哪里可以找到我的 WADL? (CXF)

Where I can find my WADL? (CXF)

我开发了一个简单的 RESTful 服务,使用 Apache CXF 耦合在网络应用程序中,并且运行良好。

我可以在“http://localhost:8080/SpringRestProjectJava/api/books/1234”上访问它,而且我也得到了正确的 JSON 响应。

我的理解是 from this link WADL 将自动生成。

是否正确?如果是,我如何才能看到此服务的 WADL

这是我的web.xml

  <servlet>
      <servlet-name>springmvc</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/CustomSpringConfig.xml</param-value>
      </init-param>      
      <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
      <servlet-name>springmvc</servlet-name>
      <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>simplerest</servlet-name>
    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
    <init-param>
        <param-name>jaxrs.serviceClasses</param-name>
        <param-value>org.gsdev.ws.bookservice.BookResource</param-value>
    </init-param>
    <init-param>
        <param-name>jaxrs.providers</param-name>
        <param-value>org.gsdev.ws.bookservice.provider.XstreamJsonProvider</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>simplerest</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>

这是我的BookResource.java

@Path( "books/{isbn}" )
public class BookResource {

    @GET
    @Produces ( "application/json" )
    public Book getDetails( @PathParam("isbn") String isbn){

        if( isbn.equals( "1234" )){
            Book book = new Book();
            book.setIsbn(isbn);
            book.setTitle("Learning web services by Garry");
            return book;
        }
        return null;
    }
}

你试过了吗:

http://localhost:8080/SpringRestProjectJava/api/books?_WADL

顺便说一句,这里有很多好东西:

http://cxf.apache.org/docs/jax-rs.html

终于,经过不断的尝试,我能够让它工作了。我认为这是由于 CXFNonSpringJaxrsServlet。我进行了以下更改,并且能够访问自动生成的 WADL.

更改为 web.xml

<servlet>
    <servlet-name>simplerest</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>simplerest</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

WEB-INF

中添加了 cxf-servlet.xml
<jaxrs:server id="bookService" address="/bookservice">
        <jaxrs:serviceBeans>
           <ref bean="bs"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean='jsonProvider' />
        </jaxrs:providers>
     </jaxrs:server>

     <bean id="bs" class="org.gsdev.ws.bookservice.BookResource"/> 
     <bean id="jsonProvider" class="org.gsdev.ws.bookservice.provider.XstreamJsonProvider"/>