Skip to main content

JAXRPC/JAXB 2.0 puzzle

11 replies [Last post]
hr_stoyanov
Offline
Joined: 2004-04-01

Hi all
I am new to JAXRPC/JAXB 2.0 and do not seem to find the answer for this issue: I want to define a simple web service like that:

--------------------------------------------------
@WebService
public class Filer {
public FilingResult acceptFiling(FilingBundle payload)
throws FilingException {
return new FilingResult();
}
}
--------------------------------------------------

I also pass these 2 simple "XML data objects":
--------------------------------------------------
@XmlRootElement
public class FilingBundle{
private FilingManifest manifest;
private Collection<?> parts;
}

@XmlRootElement
public class FilingResult {
private UUID filingReference = UUID.randomUUID();
public UUID getFilingReference() {
return filingReference;
}

}
--------------------------------------------------

Whan I use the APT tool from JAXRPC2.0 to generate WSDL+schema from the Java server class, I expected that the generated schema1.xsd file will contain proper schema definitions, derived from FilingResult and FilingBundle classes. But it only contains some empty stuff like:
-----------------
.....

...
-----------------

Am I supposed to write a boatload of customization files or what? Was not JAXRPC supposed to use JAXB's schema generation abilities?

I also looked at the bundled samples, but adding 2 numbers is not a very serious example and does not demonstrate serialization of data objects.

Thanks,
Hristo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

In the EA version, by default, JAXB only looks at the properties (meaning getter/setter pairs). Since your Java class don't define any getter/setter pair, JAXB won't find any property in it.

This is a controversial decision, but that's the way it is in the EA version.

To change this and make JAXB look at your fields, use @XmlAccessorType(FIELD). Then your code should work just fine.

See my blog about this at http://weblogs.java.net/blog/kohsuke/archive/2005/03/should_jaxb_wor.html

hr_stoyanov
Offline
Joined: 2004-04-01

Kohsuke-,
I see, but are you sure @XmlAccessorType(FIELD) works with the JAXB bundled with the EA JAXRPC2.0? The apt tool complains like that:
-------------------------------------------------------
compile.jaxrpc:
[apt] C:\efe\web_services\...\ws\FilingBundle.java
:16: cannot find symbol
[apt] symbol: variable FIELD
[apt] @XmlAccessorType(FIELD)
[apt] ^
[apt] C:\efe\web_services\src\...\ws\FilingBundle.java
:16: cannot find symbol
[apt] symbol: variable FIELD
[apt] @XmlAccessorType(FIELD)
[apt] ^
[apt] Problem encountered during annotation processing;
[apt] see stacktrace below for more information.
[apt] java.lang.annotation.AnnotationTypeMismatchException: Incorrectly ty
ped data found for annotation element public abstract javax.xml.bind.annotation.
AccessType javax.xml.bind.annotation.XmlAccessorType.value() (Found data of type
javax.xml.bind.annotation.AccessType)
[apt] at com.sun.tools.apt.mirror.declaration.AnnotationProxyMaker$Val
ueVisitor$1.(AnnotationProxyMaker.java:239)

kohsuke
Offline
Joined: 2003-06-09

FIELD is actually javax.xml.bind.annotation.AccessType.FIELD.

I assumed your IDE would figure that out given the signature of @XmlAccessorType :-)

hr_stoyanov
Offline
Joined: 2004-04-01

I was just about to appologize for the stupid quetsion :-)
Time to ditch the Eclipse crap, I guess ...

hr_stoyanov
Offline
Joined: 2004-04-01

.. but it is not nice when APT gives you:
-------------------------------------------------------------

compile.jaxrpc:
[apt] Problem encountered during annotation processing;
[apt] see stacktrace below for more information.
[apt] java.lang.NullPointerException
[apt] at com.sun.tools.jxc.model.nav.APTNavigator$3.toString(APTNaviga
tor.java:433)
[apt] at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.toStri
ng(IllegalAnnotationException.java:161)
[apt] at com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl$ErrorHandlerI
mpl.error(JavaCompilerImpl.java:80)
[apt] at com.sun.xml.bind.v2.model.impl.ModelBuilder.reportError(Model
Builder.java:238)
[apt] at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.(ClassInfo

kohsuke
Offline
Joined: 2003-06-09

Ouch. I think I actually fixed this bug in the repository just today.

Meanwhile, it's dying in trying to report an error,
and looking at the stack trace, I suspect that it's
reporting that some of the classes that participate
in the processing doesn't have the default constructor.

If I guessed incorrectly, please post the whole stack trace.

This is required by the spec, and it's another behavior I don't like. See my another blog about
this on http://weblogs.java.net/blog/kohsuke/archive/2005/02/jaxb_20_and_imm_1.html

hr_stoyanov
Offline
Joined: 2004-04-01

Kohshuke-,
It seems the problem is with new J2SE5.0 UUDI class as in:
-------------
@XmlRootElement
@XmlAccessorType(AccessType.FIELD)
public class FilingResult {
private UUID filingReference = UUID.randomUUID();

public UUID getFilingReference() {
return filingReference;
}
}
---------
If I comment the JAXB annotations out - all goes well. I will post the whole stacktrace to your e-mail.

Thanks
Hristo

kohsuke
Offline
Joined: 2003-06-09

Use @XmlJavaTypeAdapter and map UUID to String.

See my blog http://weblogs.java.net/blog/kohsuke/archive/2005/04/xmladapter_in_j.html for how to do it. Write XmlAdapter.

I'll let the spec team know that they should support this class out of the box.

(it's really starting to look like I'm advertizing my blogs, but that's not intended!)

hr_stoyanov
Offline
Joined: 2004-04-01

Okay. Another weird thing:
If you have a Collection member like in:
----------------
public class FilingBundle {
private FilingManifest manifest;
private Collection parts;
...
}
----------------
and generate the WSDL and the schema1.xsd file, weird thing happen when in the client, you try to generate stubs. You end up generating com....jaxrpc.Object class which breaks the compilation with other generated classes. Hopefully, the stub generation will be gone with the next release!

kohsuke
Offline
Joined: 2003-06-09

That doesn't sound like a JAXB issue, so I'll wait for the JAX-RPC expert to chime in...

kohlert
Offline
Joined: 2003-06-16

Hristo,
This is definately a bug in JAXRPC. The good new is that
stubs are going away in our next early access release just before JavaOne. In the meantime, if you change Collection to just Collection I believe it will work for you.