Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB, CXF: There's no ObjectFactory with an @XmlElementDecl for the element ... with

Tags:

java

wsdl

jaxb

cxf

I'm creating a WSDL first webservice with JAXB and CXF. I do not own the WSDL, so I cannot make changes to it. I'm using ftp://ftp.ihe.net/TF_Implementation_Material/ITI/wsdl/PIXManager.wsdl as my WSDL. I used CXF 2.3.0 to generate Java classes.

Java class generation went fine, but when I'm trying to run this in a web application, I get an error

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 17 counts of IllegalAnnotationExceptions

The 17 counts are of the format

There's no ObjectFactory with an @XmlElementDecl for the element {urn:hl7-org:v3}assignedDevice.
        this problem is related to the following location:
            at protected javax.xml.bind.JAXBElement org.hl7.v3.QUQIMT021001UV01AuthorOrPerformer.assignedDevice

When I go to the class mentioned, i.e. QUQIMT021001UV01AuthorOrPerformer and look at the field assignedDevice, I see this

@XmlElementRef(name = "assignedDevice", namespace = "urn:hl7-org:v3", type = JAXBElement.class)
protected JAXBElement<COCTMT090300UV01AssignedDevice> assignedDevice;

When I look at the ObjectFactory of the package, I see this

private final static QName _COCTMT090303UV01AssignedDeviceAssignedDevice_QNAME = new QName("urn:hl7-org:v3", "assignedDevice");

All my 17 errors are similar. What can I do during my codegen or runtime in order to get my service work?

like image 960
rahul Avatar asked May 09 '11 16:05

rahul


2 Answers

What Java version are you using at run-time? I had a similar issue with OTA schema when running with Java 6. I eliminated the problem by making the following changes to the Maven configuration:

  1. Use JAXB impl 2.1.* (instead of 2.2) with provided scope, to match JAXB version included in Java 6.
  2. Use JAX-WS 2.1 (instead of 2.2) to match Java 6 and JAXB 2.1.x.
  3. Add the option frontEnd to the Maven cxf-codegen-plugin plug-in and set it to jaxws21 (or if using wsdl2java on command line, use "-fe jaxws21" option).
like image 101
David J. Liszewski Avatar answered Nov 17 '22 04:11

David J. Liszewski


When you generate the classes, you also generate a file called jaxb.properties. Make sure this file is accessible to the application at runtime. I had the same problem and it was due to maven packaging: maven will not include in the package resource files (like jaxb.properties) that are below the src/main/java tree unless specifically instructed to do so. I did this using the org.codehaus.mojo:build-helper-maven-plugin with the add-resource goal. Hope this helps

like image 23
Martins Avatar answered Nov 17 '22 04:11

Martins