Hello Sergey, > Op 25-mrt.-2015, om 13:48 heeft Sergey Beryozkin <[email protected]> het > volgende geschreven: > > Hi > On 24/03/15 20:29, Peter De Winter wrote: >> Hello, >> >> I have a question regarding marshaling with a provider using jaxb >> annotations with JAX-RS.. >> I must admit it might not be a CXF question “pur sang”, but maybe you >> could give me a directions on my questions to investigate a possible >> solution. >> >> Allow me to add a small example for simplicity based on HATEOAS links. >> >> We have a request payload object defined as below which is used to >> create/update a person resource object (POST, PUT) >> >> packagesomepackage; >> >> importjavax.validation.constraints.NotNull; >> importjavax.xml.bind.annotation.XmlAccessType; >> importjavax.xml.bind.annotation.XmlAccessorType; >> importjavax.xml.bind.annotation.XmlRootElement; >> importjavax.xml.bind.annotation.XmlType; >> >> >> @XmlRootElement(name =“person") >> @XmlAccessorType(XmlAccessType.FIELD) >> @XmlType(propOrder = {"firstName","lastName"}) >> public classPerson { >> >> @NotNull >> privateString firstName; >> >> @NotNull >> privateString lastName; >> } >> >> Now to retrieve a person using for example /person/id we created a >> subclass of person to add HATEOAS links to the payload. >> >> packageanotherpackage; >> >> importsomepackage.AtomLink; >> importsomepackage.Person; >> importjavax.validation.constraints.NotNull; >> importjavax.xml.bind.annotation.*; >> importjava.util.Collections; >> >> >> @XmlRootElement(name ="person") >> @XmlAccessorType(XmlAccessType.FIELD) >> @XmlType(propOrder = {“links"}) >> public classPersonOutextendsPerson { >> >> @XmlElement(name ="links") >> Collections<AtomLink> links; >> } >> >> We hoped this way there would be able to express in the wadl that these >> HATEOAS links are only available during retrieval of data. Notice we >> named both xlmrootelements “person”. >> >> The result of wadl though now seem to be as following: >> <xs:element name="person" nillable="true" type="xs:anyType"/> >> >> Yes, anytype. >> > This is what JAXB generates... > >> We were under the assumption it is a good RESTful practice to align >> resource payload definition as much as possible over standard operations >> and if not possible use POST overloading or PATCH with it’s own >> definition. But this “links” object doesn’t really fit in a request >> payload, don’t you think. >> And I would like to avoid using a header to define HATEOAS links. >> >> So down to the questions: >> >> * Is there a way to be explicit in the wadl on which grammar to be >> used for Request or Response payload? > There are few options to customize it, see > > http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-CustomizingWADLGeneration > > <http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-CustomizingWADLGeneration> > > It will need to be expanded with more examples. > So you can configure the generator to use some prepared schemas, or you > can create WADL in advance and link to it: > > http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-ExternalWADLdocumentsandJAXRSendpoints > > <http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-ExternalWADLdocumentsandJAXRSendpoints>. > >> * Is there a better way to define my person structure so that the wadl >> generates a more concrete grammar? >> * Is there some nifty jaxb trick that might help me out? > I guess both are very much JAXB-related questions. > By the way, JAX-RS API provides the following helpers: > > https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Link.JaxbAdapter.html > > <https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Link.JaxbAdapter.html> > https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Link.JaxbLink.html > > <https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Link.JaxbLink.html> > > I haven't tried them but I wonder if they can help you somehow. > > >> * Is my problem absurd :) as it is considered “OK" to have grammar >> parts such as “links” showing for request payload definition due too >> using the same class for request and response and should I simply >> ignore it if a client passes links in a request? >> > Do you mean the client ends up sending those links too due to its reusing the > same classes on the client side ? If yes - then I'd personally consider > updating the client to use the super class unless it does male sense, > example, the client is running in scope of a server or can point to some > server with the links
The client doesn’t have to be a CXF client persé. Anyway the WADL mentions anytype due too the fact that we extend a class to add a links property. We could have two different classes, but this would mean refactoring and maybe another trick exists that would prevent us from having to do this. Now for people only reading the wadl, let’s say a .Net or IOS developer would get the wadl from us, the anytype is a little ambigue and questions will surely be asked. Just trying to get the wadl as clear as possible, so no anytype. I will investigate your proposals. Thanks for your time! > > Cheers, Sergey >> >> Any tip is welcome. >> >> Thanks in advance. >> >> ------------------------------------------------------------------------ >> >> Met vriendelijke groeten - Cordialement - Best Regards - Mit >> freundlichen Grüßen >> >> *Peter* *De Winter* | technical lead >> +32 2 421 46 93 | +32 2 420 33 15 | >> >> [email protected] <mailto:[email protected]> >> <mailto:[email protected] <mailto:[email protected]>> >> >> >> M-team asbl/vzw | Route de Lennik/Lenniksebaan 788 b1, 1070 Brussels, >> Belgium >> www.m-team.be <http://www.m-team.be/> <http://www.m-team.be >> <http://www.m-team.be/>> >> >> >> >> >> >> >> Met vriendelijke groet/Regards/Cordialement , >> *Peter De Winter >> Owner mijathi bvba >> Ond. Nr. 0833.250.487 >> >> Contact info >> *Lindenlaan 85 >> B-8400 Oostende >> * >> * >> Mobile: +32 (0)473 45 10 02 >> Phone: +32 (0)2808 08 65 Ext 988 >> email: [email protected] <mailto:[email protected]> >> <mailto:[email protected] <mailto:[email protected]>> >> *Site: *mijathi.be <http://mijathi.be/> <http://www.mijathi.be/ >> <http://www.mijathi.be/>> >> **Twitter: **@mijathi <http://www.twitter.com/mijathi >> <http://www.twitter.com/mijathi>> >> >> *Instead of printing this e-mail, you could carve it into stone.* >> > > > -- > Sergey Beryozkin > > Talend Community Coders > http://coders.talend.com/ <http://coders.talend.com/> > > Blog: http://sberyozkin.blogspot.com <http://sberyozkin.blogspot.com/>
