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

时间:2015-06-02 07:44:04

标签: java web-services rest cxf

我使用RESTful在Web应用程序中开发了一个简单的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;
    }
}

2 个答案:

答案 0 :(得分:1)

最后,继续尝试后,我能够让它发挥作用。我认为这是由于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>

cxf-servlet.xml

中添加了WEB-INF
<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"/>

答案 1 :(得分:-1)

你试过了吗?

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

顺便提一下这里有许多好东西:

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