Proper tool for simple XML interfaces [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this questionI need to expose some services of the web application to remote clients via XML interfaces over http. A number of provided services is lim开发者_运维百科ited (3-7), both request and response should be kept simple and do not require any special data types or cross-entity relations.
My goal is to keep the code clean and clear and have robust and performant application. I would really appreciate your advices regarding the proper XML binding\processing tool to be used for that task.
UPD: My bad, haven't mentioned that restlet is required for implementation, however, as far as I am concerned, it does not impose any restrictions on the xml tool to be used.
Thanks in advance.
The JAX-RS specification (JSR-311) provides a standard means of creating RESTful services over HTTP. There are several JAX-RS implementations: Jersey, RESTEasy, Wink. JAXB (JSR-222) is the standard binding layer (objects to/from XML) for JAX-RS, and there are several implementations: MOXy, Metro, JaxMe, etc.
These implementations are also come pre-bundled with Java EE application servers (i.e. GlassFish and WebLogic contain Jersey).
Here is an example I put together using Jersey & MOXy in GlassFish:
- Part 1 - The Database
- Part 2 - Mapping the Database to JPA Entities
- Part 3 - Mapping JPA entities to XML (using JAXB)
- Part 4 - The RESTful Service
- Part 5 - The Client
We've done some work recently using Apache CXF, and found its JAX-RS support to be simple and allow us to write very DRY friendly code.
There is a reasonable amount of flexibility, e.g. several different data binding layers to choose from.
How about XStream? http://x-stream.github.io/
XStream is a simple library to serialize objects to XML and back again.
I like http://www.restlet.org/
My advice would be to not use a binding tool at all. Just deal with the fact that what you are sending over the wire is in fact XML. The Spring Web Services reference manual describes the rationale behind this, which is called 'contract first', right here
I understand that what you are looking to write is not a SOAP service, but a REST service. That doesn't matter for the point I am making against using a binding tool, the principle of 'contract first' still applies.
Good luck!
精彩评论