You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2012/10/01 18:12:58 UTC

Re: Need some help with WADL2Java Tool

Hi

The WADL fragment compiles as expected, the following is produced:

/**
  * Created by Apache CXF WadlToJava code generator
**/
package com.bp.bs;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@Path("/books")
public interface BookResource {

     @POST
     @Consumes("application/octet-stream")
     @Produces("application/octet-stream")
     Response add();

     @DELETE
     @Produces("application/octet-stream")
     @Path("/{isbn}")
     Response deleteIsbn(@PathParam("isbn") String isbn);

     @GET
     @Produces("application/xml")
     @Path("/{isbn}")
     Book getIsbn(@PathParam("isbn") String isbn);

     @PUT
     @Consumes("application/xml")
     @Produces("application/octet-stream")
     @Path("/{isbn}")
     Response update(@PathParam("isbn") String isbn, Book book);

}

Note update() has a 'Book' added in the signature.

Try CXF 2.7.0-SNAPSHOT or CXF 2.6.3-SNAPSHOT (to be released shortly),

Cheers, Sergey


On 28/09/12 11:47, Behzad Pirvali wrote:
> Hi Sergey,
>
> Thank You so much for your response.
>
> I was going to reply in the forum so that everyone with my problem could
> use your answer.
> I have checked both Stack Overflow and cxf-forum, but did not see any
> replies there.
> That is why I am replying to your email.
>
> 1)
> With Injecting Request into a class field, you mean using Spring?
> But how do I make Spring to know about the incoming Request object?
>
> 2)
> Do you have any idea on how to get WADL so that generated update(PUT)
> interface has both parameter?
> Currently, the generated update(...) is:
>      - update(@PathParam("isbn") String isbn)
> instead of:
>      - update(@PathParam("isbn") String isbn, BookState st)
>
> Thank u SO MUCH,
> Behzad
>
>
> Here is the whole WADL:
>
> <application xmlns="http://wadl.dev.java.net/2009/02"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>   xmlns:prefix1="http://bp.com/bs">
> <grammars>
> <schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://bp.com/bs"
> xmlns:tns="http://bp.com/bs" elementFormDefault="qualified">
> <element name="book">
> <complexType>
> <sequence>
> <element name="isbn" type="string"></element>
> <element name="title" type="string"></element>
> </sequence>
> </complexType>
> </element>
> </schema>
> <!-- <include href="BookService.xsd"/>  -->
> </grammars>
> <resources base="http://localhost:8080/bs">
> <resource path="/books" id="com.bp.bs.BookResource">
> <method name="POST" id="add" >
> <request>
> <representation mediaType="application/octet-stream" />
> </request>
> <response>
> <representation mediaType="application/octet-stream" />
> </response>
> </method>
> <resource path="/{isbn}">
> <param name="isbn" style="template" type="xs:string" />
> <method name="DELETE" id="delete" >
> <request />
> <response>
> <representation mediaType="application/octet-stream" />
> </response>
> </method>
> <method name="GET" id="get" >
> <request />
> <response>
> <representation mediaType="application/xml" element="prefix1:book" />
> </response>
> </method>
> <method name="PUT" id="update" >
> <request>
> <representation mediaType="application/xml" element="prefix1:book" />
> <!-- <representation mediaType="application/octet-stream" /> -->
> </request>
> <response>
> <representation mediaType="application/octet-stream" />
> </response>
> </method>
> </resource>
> </resource>
> </resources>
> </application>
>
>
>
> On Fri, Sep 28, 2012 at 1:41 AM, Sergey Beryozkin <sberyozkin@gmail.com
> <ma...@gmail.com>> wrote:
>
>     Hi,
>
>     Redirecting to the users,
>     On 27/09/12 19:17, bpirvali wrote:
>
>         Hi Guys,
>
>         I went through the documentation, which helped me figure out
>         several issues
>         I had, but not the following two problems:
>
>         1) I have got a get(GET) method: get(@Context Request request,
>         @PathParam("isbn")String isbn)
>         How do I formulate the WADL for it so that I get the @Context in the
>         produced Java code?
>
>
>     It is not possible to express that in WADL because @Context is meant
>     to capture a request information for the benefit of a service.
>
>     Instead, get the tool to generate an interface only, and have
>     'Request' injected into the implementation class field
>
>         2) I have got a update (PUT) method: update(@PathParam("isbn")
>         String isbn,
>         BookState st)
>         How do I formuate the WADL to get the BookState in the produced
>         Java code?
>
>         Here is my current WADL, which does not do it:
>         <resource path="/{isbn}">
>
>                   ....
>         <method name="GET" id="get">
>         <request />
>         <response>
>         <representation mediaType="application/xml"
>         element="prefix1:book" />
>         </response>
>         </method>
>         <method name="PUT" id="update">
>         <request>
>         <representation mediaType="application/xml"
>         element="prefix1:book" />
>
>         </request>
>         <response>
>         <representation mediaType="application/octet-__stream" />
>         </response>
>         </method>
>         </resource>
>
>     what about a response type for 'get'? May be you can paste the
>     schema fragment ?
>
>     Sergey
>
>
>
>         Thank u so much,
>         Behzad
>
>
>
>
>         --
>         View this message in context:
>         http://cxf.547215.n5.nabble.__com/Need-some-help-with-__WADL2Java-Tool-tp5714978.html
>         <http://cxf.547215.n5.nabble.com/Need-some-help-with-WADL2Java-Tool-tp5714978.html>
>         Sent from the cxf-issues mailing list archive at Nabble.com.
>
>
>
>
>
>
> --
> Thanks,
> Behzad
>