[
https://issues.apache.org/jira/browse/CXF-2862?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12883211#action_12883211
]
Matthew Smith commented on CXF-2862:
------------------------------------
Hi Sergey,
Thanks for the response. Setting the useJaxbContextForQnames property of the
WadlGenerator to false resulted in an empty grammars element in the wadl, so I
removed it again (having also tried it in combination with an @XmlName
annotation).
Adding a namespace to the @XmlRootElement annotation did result in an element
attribute being added to the representation. This is good when the method
returns a jaxb annotated object (thanks), but won't work if the method being
described returns a Response object instead of a jaxb annotated object, and
doesn't appear to work for objects in the request body. I (will) have modified
the patch so that it takes account of the namespace in @XmlRootElement:
Jaxb annotated bean:
@XmlRootElement(name = "myBeanName", namespace = "myPrefix")
public class MyXmlBean {
//...
}
Annotated service method:
@POST
@WadlElement(request = MyXmlBean.class, response = MyXmlBean.class)
public Response createMyXmlBean(@Context MessageContext context, MyXmlBean
bean) {
return Response.ok(bean, MediaType.APPLICATION_XML_TYPE).build();
}
generated WADL:
<application xmlns="http://research.sun.com/wadl/2006/10"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prefix1="myPrefix">
<grammars>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="unqualified">
<!-- ... -->
<xs:complexType name="myXmlBean">
<!-- ... -->
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="ouk"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="myPrefix">
<xs:import namespace="" />
<xs:element name="myBeanName" type="myXmlBean" />
</xs:schema>
</grammars>
<resources base="http://127.0.0.1:8080/rest/">
<resource path="/">
<request>
<representation mediaType="application/xml" element="prefix1:order" />
</request>
<response>
<representation mediaType="application/xml" element="prefix1:order" />
</response>
</method>
</resource>
</resources>
</application>
> Provide an annotation to allow customisation of the elements declared in the
> request & response representation in the auto-generated wadl
> -----------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CXF-2862
> URL: https://issues.apache.org/jira/browse/CXF-2862
> Project: CXF
> Issue Type: Improvement
> Components: JAX-RS
> Affects Versions: 2.2.9
> Reporter: Matthew Smith
> Priority: Minor
> Attachments: WadlElement.patch
>
>
> In using the auto-generated wadl for jax-rs rest services in cxf (2.2.9) I
> have found that all my jaxb annotated xml beans are defined in the grammars
> section of the wadl, but they are not referenced as elements in the
> representation element of methods in the resources section. Indeed it would
> be difficult to automatically determine the correct element for methods that
> return a Response object containing a jaxb annotated object instead of
> returning the object itself.
> To overcome this I suggest creating a WadlElement annotation that allows the
> method to be annotated with the class accepted in the request and returned by
> the response even where it is not the declared return type of the method.
> For example, the following method declaration in a Rest service currently
> produces an auto-generated wadl as shown below:
> // method from jax-rs service:
> @POST
> @Path("/")
> @Produces("application/xml")
> @Consumes("application/xml")
> public Response doStuff(@Context MessageContext context, MyXmlBean
> bean) {
> return Response.ok(bean,
> MediaType.APPLICATION_XML_TYPE).build();
> }
> <!-- snippet of auto-generated wadl: -->
> <resource path="/">
> <method name="POST">
> <request>
> <representation mediaType="application/xml" />
> </request>
> <response>
> <representation mediaType="application/xml" />
> </response>
> </method>
> Using the annotation, this would become:
> // method from jax-rs service using annotation:
> @POST
> @Path("/")
> @Produces("application/xml")
> @Consumes("application/xml")
> @WadlElement(request = MyXmlBean.class, response = MyXmlBean.class)
> public Response doStuff(@Context MessageContext context, MyXmlBean
> bean) {
> return Response.ok(bean,
> MediaType.APPLICATION_XML_TYPE).build();
> }
> <!-- snippet of auto-generated wadl usign annotation. Note that the element
> "myXmlBean" is defined in the grammars section of the wadl: -->
> <resource path="/">
> <method name="POST">
> <request>
> <representation mediaType="application/xml" element="myXmlBean" />
> </request>
> <response>
> <representation mediaType="application/xml" element="myXmlBean" />
> </response>
> </method>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.