I'm creating a Web Service with the Struts2 REST Plugin, which works great. I just have a problem with the entity names of the XML output.
I have a model class named "ModelClass" in the package "com.mycompany.implementation" with a few properties and a nested class "NestedModelClass", and the XML output looks like:
<com.mycompany.implementation.ModelClass>
...
<com.mycompany.implementation.ModelClass_-NestedModelClass>
...
</com.mycompany.implementation.ModelClass_-NestedModelClass>
</com.mycompany.implementation.ModelClass>
How can I change the XML Entity name to be displayed without package name - or even a different name?
Thanks!
The struts rest plugin uses XStream to serialize your model class to XML. Current versions of XStream support annotating classes and fields to customize the serialization. Unfortunately, the struts rest plugin uses a rather old version of XStream, ignoring those annotations.
The easiest way to get what you want is to write your own ContentTypeHandler and use that instead of the default one provided by the rest plugin. This blog describes how to do that.
Related
We are developing REST services and want to use JSR 303 for input data validation, but problem here is all model objects are generated from groovy DSL and will be imported as jars. So there is no flexibility of writing JSR-303 annotations on top of object fields.
So is there any other alternative to use JSR-303 without annotations,is it possible by XML configuaration? or any suggestion for validation in this scenario please.
Thanks
JSR-303 allows you to override your annotations by using XML validation descriptors. (use a validation.xml)
Either use the XML configuration as defined by the Bean Validation spec or - if you're working with Hibernate Validator - the API for programmatic constraint declaration.
It possible in Resteasy to extract the URI mapping to an external, dedicated file?
Annotating classes and methods is quick and easy but I would like to have a file that maps the URIs to functions. Something like:
/teams/{team}/player/{player-id} TeamResource.fetchPlayer
As far as I know this is not currently supported as part of the JAX-RS specification, but I could see you being able to do this with byte code insertion at runtime using something like javassist.
Basically you would add the #Path annotations to the your resource classes at runtime with the values loaded from your uri mapping file. Once the annotations were added to the resource you would then inject them into Resteasy.
I'm wonderring whether Google is ready to publish (or there is at least any chance to "produce") the full formal xml schema for GWT UIBinder.
I've searched the latest entire GWT-SDK-2.4 distribution but found nothing. Does GWT simply look up java sources or reflect the classes of the widgets to validate the UIBinder xml counterparts, assuming that the xml schema was actually by no means predefined thus adopted to govern the validation?
#EDIT
According to the answer from #Ganesh Kumar, I've looked into ui.xsd (r6836) and found something e.g. in lines 496-499:
<!--
A complex type that contains both text and elements. There is no schema
for the elements, they can be any elements.
-->
There're also other similar occurrences indicating no schema for the elements alike. It seems that Google has not yet fully defined even agreed on the xml schema for UIBinder xml instances, doesn't it?
AFAIK, the XSD is only there to help the Google Plugin for Eclipse doe autocomplete.
There's no schema per se, UiBinder generator directly matches the elements with classes and the attributes with setters (with a few exceptions, such as addStyleNames, this is documented in the UIObject javadoc). There are a bunch of element parsers specific to some widgets (each widget that uses one has some specific documentation in its javadoc), and there are attribute parsers to unmarshal attribute values into Java objects to pass to setters.
Yes, Google is publishing the XSD for UiBinder as part of GWT source. You can get the latest GWT source which is available at http://google-web-toolkit.googlecode.com/svn/trunk/. You can view the XSD at here
I want to use JSR 303 Bean validation on my classes. My problem is that these classes are generated from schema. I am using the jaxb annotate plugin on my bindings file and was able to define simple validation annotations like #NotNull. My problem comes when I have to define multiple annotations of same type for different groups. javax.validation offers a solution for this using annotations like #Size.List{#Size...). How can I use jaxb-annotate and annox plugin to define annotations like those.
You can define nested annotations with Annox, it's no problem. In your case it will be something like:
In *.xjb file:
<annox:annotate>
<annox:annotate annox:class="javax.validation.constraints.Size$List">
<annox:annotate annox:field="value">
<annox:annotate annox:class="javax.validation.constraints.Size" .../>
</annox:annotate>
</annox:annotate>
</annox:annotate>
In schema:
<annox:annotate>
<c:Size$List xmlns:c="http://annox.dev.java.net/javax.validation.constraints">
<c:value>
<c:Size ... />
</c:value>
</c:Size$List>
</annox:annotate>
I haven't tested it, so the syntax may be a bit different.
See the Annox user guide an the Annotate plugin docs.
I am trying to create Web Services from the Top-Down approach. I downloaded Eclipse and am using the WSDL gui editor in it to build my WSDL files.
I am splitting up my Services based on "modules". The Types I am adding to the WSDLs all need to reference common stuff, such as PersonEntity, AddressEntity, States enumeration (simple type), Countries enumeration (simple type), and AbstractEntity. Since those items are all common I created a seperate WSDL file (named Commons.wsdl) that contains the type information for those types.
I want to "import" that WSDL into my other WSDL files to use:
For example, I have an entity named RegistrationEntity which inherits from AbstractEntity and contains a PersonEntity as well as an AddressEntity. I'm not sure how to do this... I saw that the WSDL spec has "import" and "include" and am not sure which one to use. Also, how do I actually import (or include) the Commons.wsdl file so that I can use the Types defined within it?
Thanks!
Oh, and I'm not sure if I'm supposed to stick this stuff in a seperate WSDL but another type of file such as an xsd or something. I really wanna follow best practices so if that's the proper way to do it then I'd rather do that.
I found out that the problem I had was I was creating a WSDL file for my commons and using an inline scheme for that, rather than creating an XSD file to be imported by my other WSDLs.
So instead I just created an Commons.XSD as my "Common Schema".