Locale instance in web service - frameworks

How can I use instances of java.util.Locale as parameter or result in a webservice?
My webservice uses Apache CXF.

The only way to do so is to use an XmlTypeAdapter to map the Locale object into something that JAXB can understand. Check the JAXB docs for instructions about the type adapters. CXF also has an example in the java_first_jaxws sample folder for mapping some interface things into stuff that JAXB can understand. Very similar concept here.

Related

jackson and jax-rs annotations

I am using Jackson to implement a simple REST API.
Because it is the first time, I would like to be sure that I am following the correct practice.
Looking various examples, I found annotations implemented in the Jackson library such as #JsonProperty.
I found also other annotations that are defined in jax-rs.
It is not clear to me when Jackson ends and jax-rs starts and viceversa.
Is it ok to implement the API using both the annotations ?
Is there an overlapping or are always used to define different characteristics of the API?
JAX-RS is a specification for creating REST web services in Java. JAX-RS requires an implementation such as Jersey, RESTEasy or Apache CXF.
Jackson is a popular JSON parser for Java and can be integrated with JAX-RS using the jackson-jaxrs-providers multi-module project.
While JAX-RS annotations allows you to map classes and methods to handle HTTP requests, Jackson annotations allows you to map Java classes to JSON objects and vice versa.

Is it possible to have a class support both a JAX-RS service and JAX-WS service?

I've created a RESTful web service using jersey and JAX-RS annotations. It's also documented using enunciate and looks great. However, SOAP support has been requested as an option. I noticed in this outdated enunciate example JAX-WS and JAX-RS annotations in the same class. Is this possible? I've tried it myself and enunciate generates documentation correctly, but the services don't actually work.
I'd prefer to have the exact same class support both interfaces rather than two separate classes (one soap one rest) pointing to the business logic class. This would prevent possibly having code in two places.
Here's the example on outdated software versions:
http://docs.codehaus.org/display/ENUNCIATE/A+Rich+Web+service+API+for+Spring
I'm using
Jersey 1.8
Spring 3.0.5
Weblogic 11g
Thanks!
/Chip
I'm not sure what might not be working, but a lot of the Enunciate example modules use both the SOAP and REST annotations on the same class.
Here's one for Jersey/JAX-WS.
Here's one for JBoss WS/RestEasy.
Here's one for CXF.
We ended up making a separate service for SOAP than the REST service. We also found it best to have interfaces for each that enunciate could generate from. This way we could control what documentation it generated. It also started functioning smoother. Still having a problem with the namespaces though as they're all default and ns0 is generated but enunciate links are to ns2/3/4/5/etc. So many links are broken.

Support for annotation inheritance in Jersey

I am working on creating a SOA project. I want to use Jersey to expose the services on rest. In my project the standard is to create a API project which has API interfaces and DTOs. The implementation project depends on the API project and all implementation is written in the implementation.
The idea behind this architecture is that, we could create two API projects one for REST and other for SOAP, annotate the interfaces with required annotations. As a result the implementation would be unaware about the method used to expose the service (I mean REST and SOAP).
But the problem in Jersey is unable to discover the annotations on the interface and keeps throwing following exception
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
A similar question has already been asked - JAX-RS Jersey/Grizzly Define an interface resource - The answer says that it is possible using Spring-Jersey.
But I tried various configuration options for spring-jersey - including - http://jersey.java.net/nonav/apidocs/1.8/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/package-summary.html
But did not have any success.
Questions
The idea of trying to manage the different ways of exposing service thru interface, is it a feasible and good idea? How are experts in the industry doing?
How can I manage to use Jersey to understand the annotations done on Interface?
Is some other framework like RestEasy going to help?

Role of JAXB in Java based Web Services

I must admit that I'm new to Web services. When I create a Web service using CXF or Axis, even with custom beans being used to communicate information between the client and the service, the objects are automatically marshalled and unmarshalled for me (I mean CXF or Axis create all the necessary files and classes). So, even though I know JAXB is used by the stack to marshal, and unmarshal objects, but I don't directly need to work with JAXB.
Now, my question is whether I need to work with JAXB directly, as far as Web services are concerned, or that marshaling and unmarshalling will always be handled for me?
When creating a JAX-WS (SOAP) or JAX-RS (RESTful) Web Service, JAXB is used as the binding layer to convert objects to/from XML (and sometimes JSON). This marshalling/unmarshalling is triggered automatically for you. Where you interact with JAXB is by adding annotations to your domain model to control how the XML looks. Below are a couple of examples that you may find useful:
http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html (JAX-WS example)
http://blog.bdoughan.com/2010/08/creating-restful-web-service-part-35.html (JAX-RS example)

What's a JAX-RS implementation?

I have been trying to figure out how to use JAX-RS for quite some time. I started from the very basic concepts and then to gradually understand the annotation styled programming, the meaning of #Path, #Get, #Post, etc.
To my understanding, as to what has been mentioned in a lot of places, JAX-RS is a framework that focuses on applying Java annotations to plain Java objects (Page 27, Bill Burke, RESTful Java).
I have then got confused beyond this point. If JAX-RS in itself is a framework that defines APIs dealing with annotations in order to implement RESTful web service, what's the meaning of "implementation of JAX-RS" such as "Jersey" and "JBoos Resteasy". Another layer on top of JAX-RS? Why do we need them?
Could someone provide me some insights about it? Many thanks!!!
JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.
Being implementations mean that the spec says "if you put #GET("/foo") on a method (bar()), you may access data X" - now in an app server, someone needs to go in and actually read your deployed code, parse the byte code with the #GET annotation and then if the user actually browses to e.g. http://localhost/foo get this web request to reach bar() and translate the return value of bar() into a http answer (e.g in XML or JSON representation).
So the spec with the name "JAX-RS" only provides the syntax and semantics of e.g. #GET, but the work of parsing requests, calling the right methods, marshalling the result values etc. need to be done by a package that implements the Spec.
Work on the version 2.0 of the standard has started as JRS-339.
See also http://en.wikipedia.org/wiki/Jax-rs
JAX-RS is a specification for RESTful Web Services with Java. There is a reference implementation that is included in Java EE but since it is a specification, other frameworks can be written to implement the spec, and that includes Jersey, Resteasy, and others.