views:

13

answers:

1

Hello there.

I'm using Enunciate to generate a SOAP endpoint for a Wicket web application I am working on and I have a couple of questions that I haven't figured out the solution to yet.

1 How do I change the name of the xsd files? I've looked through the FAQ and it tells me to do something similar to this:

<xml>
    <schema namespace="http://api.example.com/data" file="data.xsd"/>
</xml>

However, I haven't quite figured out how to set the targetNamespace for my data objects. I've done this for my service via @WebService ( targetNamespace="blah" ), but how do I annotate my data objects to let Enunciate know which namespace they should belong to?

2 Enunciate generates my XSDs just fine, but I don't particularily like the element names it uses. I have a ServiceRequest and ServiceResponse object. The ServiceRequest object has a List of User objects. The ServiceResponse has a list of Group objects. Enunciate suggests that every "User" object within the ServiceRequest should be using the tag "<users>". I feel that it would make more sense to use the singular form, "<user>" since the tag does in fact only contain a single user. Is it possible to change this behaviour, and if so, how?

Thanks in advance.

+1  A: 

So just to be clear, with the exception of the question about naming your schema files, your questions are really more about JAXB than they are about Enunciate. JAXB is the spec that defines how your Java objects are (de)serialized to/from XML and Enunciate conforms to that spec.

Anyway, the easiest way to apply a namespace to your Java objects is with a package-info.java file in the package of your Java classes. Annotate your package with @XmlSchema and set the namespace to be the value you want.

Customizing how your accessors are serialized to/from XML can be done with the @XmlElement annotation, e.g.:

public class MyClass {
  ...
  @XmlElement (name="user")
  List<User> users;
  ...
}

Here are the JAXB javadocs

https://jaxb.dev.java.net/nonav/2.1.9/docs/api/

Or google for a good JAXB tutorial.

Ryan Heaton
Thanks Ryan. I managed to accomplish a proper structure by using annotations such as @XmlElementWrapper and @XmlElement :-)
John