2016-10-04 14 views
5

Tôi đang cố gắng tạo WADL bằng plugin maven. Dự án xây dựng và dịch vụ hoạt động. Đây là một phần của POM có plugin:Plugin Maven WADL không sản xuất WADL có thể sử dụng

   <plugin> 
       <groupId>com.sun.jersey.contribs</groupId> 
       <artifactId>maven-wadl-plugin</artifactId> 
       <version>1.19.2</version> 
       <executions> 
        <execution> 
         <id>generate</id> 
         <goals> 
          <goal>generate</goal> 
         </goals> 
         <phase>package</phase> 
        </execution> 
       </executions> 

       <configuration> 
        <wadlFile>${basedir}/src/main/docs/ThingREST.wadl</wadlFile> 
        <formatWadlFile>true</formatWadlFile> 
        <baseUri>http://localhost:8080/ThingREST</baseUri> 
        <packagesResourceConfig> 
         <param>samp.rest.ws.controller</param> 
        </packagesResourceConfig> 
        <wadlGenerators> 
         <wadlGeneratorDescription> 
          <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc 
          </className> 
          <properties> 
           <property> 
            <name>applicationDocsFile</name> 
            <value>${basedir}/src/main/docs/xml/app-wadl-doc.xml</value> 
           </property> 
          </properties> 
         </wadlGeneratorDescription> 
         <wadlGeneratorDescription> 
          <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport 
          </className> 
          <properties> 
           <property> 
            <name>grammarsFile</name> 
            <value>${basedir}/src/main/docs/xml/app-wadl-grammar.xml</value> 
           </property> 
          </properties> 
         </wadlGeneratorDescription>       
        </wadlGenerators> 
       </configuration> 
      </plugin> 

Ứng dụngDocFile và grammarFile tồn tại nhưng không chứa bất kỳ thông tin quan trọng nào. Tôi không chắc chắn nên bao gồm những gì.

Dưới đây là bộ điều khiển:

package samp.rest.ws.controller; 

import java.util.List; 
import samp.rest.ws.ThingDB; 
import samp.rest.ws.vo.Thing; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestBody; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RestController; 

/** 
* 
* @author Grayson 
*/ 
@RestController 
public class ThingController { 

    @RequestMapping(value = "/things", method = RequestMethod.GET, headers = "Accept=application/json") //produces = "application/json") 
    public List<Thing> getThings() { 
     return ThingDB.getThings(); 
    } 

    @RequestMapping(value = "/thing/{id}", method = RequestMethod.GET, headers = "Accept=application/json") 
    public Thing getThingById(@PathVariable int id) { 
     return ThingDB.getThing(id); 
    } 

    @RequestMapping(value = "/thingy/{id}", method = RequestMethod.GET) 
    public String getThingy(@PathVariable int id) { 
     return ThingDB.getThing(id).toString(); 
    } 

    @RequestMapping(value = "/addthing", method = RequestMethod.PUT) //, headers = "Accept=application/json")  
    public void addThing(@RequestBody Thing thing) { 
     ThingDB.addThing(thing); 

     List<Thing> lt = ThingDB.getThings(); 
     for (Thing t : lt) { 
      System.out.println(" Post add: " + t.toString()); 
     } 
    } 
} 

Cuối cùng, đây là WADL sản xuất:

<?xml version="1.0" encoding="UTF-8"?> 
<application xmlns="http://wadl.dev.java.net/2009/02"> 
    <doc 
     jersey:generatedBy="Jersey: 1.19.2 08/25/2016 12:00 AM" 
     xmlns:jersey="http://jersey.java.net/"/> 
    <doc 
     title="Maven Spring REST Sample WADL" 
     xml:lang="en"><![CDATA[ 
     This is the Web Application Description Language (WADL) for 
     a Maven Spring REST Service. This service is intended to serve as 
     a workign model/sample. 
    ]]></doc> 
    <grammars/> 
    <resources base="http://localhost:8080/ThingREST"/> 
</application> 

Tôi hy vọng các WADL để bao gồm các cuộc gọi dịch vụ có sẵn và cũng xác định các loại đầu vào. Rõ ràng, tôi không nhận được điều này.

Tôi đã tìm kiếm các ví dụ và tài liệu cao và thấp để sử dụng plugin này. Bất kỳ và tất cả sự giúp đỡ sẽ được đánh giá cao. Đáng buồn thay, những tài liệu/ví dụ nào tồn tại dường như đã lỗi thời.

Xin cảm ơn trước.

+0

Nó không giống như mùa xuân REST của hỗ trợ mô-đun WADL thế hệ, xem [SPR-8705] (https://jira.spring.io/browse/SPR-8705). – Tunaki

+0

@Tunaki - Cảm ơn. – Grayson

Trả lời

3

Thật không may plugin này không hỗ trợ bộ điều khiển Spring REST. Nó sẽ chỉ xử lý các lớp được chú thích bằng @Path và các chú thích JAX-RS khác. Không có plugin nào khác làm những gì bạn cần. Bạn có hai tùy chọn:

1) Viết lại bộ điều khiển của bạn để sử dụng JAX-RS. Ví dụ tôi đã thay đổi điều khiển của bạn như sau:

package samp.rest.ws.controller; 

import java.util.List; 
import samp.rest.ws.ThingDB; 
import samp.rest.ws.vo.Thing; 

import javax.ws.rs.*; 

@Path("/thing") 
public class ThingController { 

    @GET 
    @Path(value = "/things") 
    @Produces("application/json") 
    public List<Thing> getThings() { 
     return ThingDB.getThings(); 
    } 

    @GET 
    @Path(value = "/thing/{id}") 
    @Produces("application/json") 
    public Thing getThingById(@PathParam("id") int id) { 
     return ThingDB.getThing(id); 
    } 

    @GET 
    @Path(value = "/thingy/{id}") 
    public String getThingy(@PathParam("id") int id) { 
     return ThingDB.getThing(id).toString(); 
    } 

    @PUT 
    @Path(value = "/addthing") 
    @Produces("application/json") 
    public void addThing(Thing thing) { 
     ThingDB.addThing(thing); 

     List<Thing> lt = ThingDB.getThings(); 
     for (Thing t : lt) { 
      System.out.println(" Post add: " + t.toString()); 
     } 
    } 
} 

Sau đó, các plugin tạo file WADL này:

<?xml version="1.0" encoding="UTF-8"?> 
<application xmlns="http://wadl.dev.java.net/2009/02"> 
    <doc jersey:generatedBy="Jersey: 1.19.2 08/25/2016 12:00 AM" xmlns:jersey="http://jersey.java.net/"/> 
    <doc title="A message in the WADL" xml:lang="en"><![CDATA[This is the Web Application Description Language (WADL) for 
     a Maven Spring REST Service. This service is intended to serve as 
     a workign model/sample.]]></doc> 
    <grammars> 
     <include href="xsd0.xsd"> 
      <doc/> 
     </include> 
    </grammars> 
    <resources base="http://localhost:8080/ThingREST"> 
     <resource path="/thing"> 
      <resource path="/things"> 
       <method id="getThings" name="GET"> 
        <response> 
         <representation mediaType="application/json"/> 
        </response> 
       </method> 
      </resource> 
      <resource path="/addthing"> 
       <method id="addThing" name="PUT"> 
        <request> 
         <representation mediaType="*/*"/> 
        </request> 
       </method> 
      </resource> 
      <resource path="/thing/{id}"> 
       <param name="id" style="template" type="xs:int" xmlns:xs="http://www.w3.org/2001/XMLSchema"/> 
       <method id="getThingById" name="GET"> 
        <response> 
         <representation mediaType="application/json"/> 
        </response> 
       </method> 
      </resource> 
      <resource path="/thingy/{id}"> 
       <param name="id" style="template" type="xs:int" xmlns:xs="http://www.w3.org/2001/XMLSchema"/> 
       <method id="getThingy" name="GET"> 
        <response> 
         <representation mediaType="*/*"/> 
        </response> 
       </method> 
      </resource> 
     </resource> 
    </resources> 
</application> 

2) Viết riêng plugin Maven WADL của bạn có hỗ trợ điều khiển Xuân REST. Để tham khảo, bạn có thể nhìn vào máy phát điện này theo hình thức dịch vụ web:

https://javattitude.com/2014/05/26/wadl-generator-for-spring-rest/

Và mã nguồn của Maven WADL plugin:

https://github.com/jersey/jersey-1.x/tree/master/contribs/maven-wadl-plugin

+0

Cảm ơn bạn đã nhập. Tôi có thể thử điều này vào một ngày sau đó. Vì không ai khác nỗ lực vào nó và bạn đã làm một chút, bạn sẽ nhận được tiền thưởng. Chúc mừng. – Grayson

Các vấn đề liên quan