M
M
Mikhail Akushsky2015-09-28 08:48:02
Java
Mikhail Akushsky, 2015-09-28 08:48:02

How to screw together a JAX-WS web service and @XmlAnyElement?

I'm developing a SOAP @WebService using Spring and JAX-WS 2.2.10.
I will give the class code that describes part of the input parameter to the web service function:

package com.itu.messaging.regional;

import org.w3c.dom.Element;

import javax.xml.bind.annotation.*;
import java.io.Serializable;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GenericMessagePrimaryContent", propOrder = {
    "any"
})
public class GenericMessagePrimaryContent implements Serializable {

    @XmlAnyElement
    protected Element any;

    /**
     * Gets the value of the any property.
     * 
     * @return
     *     possible object is
     *     {@link Element }
     *     
     */
    public Element getAny() {
        return any;
    }

    /**
     * Sets the value of the any property.
     * 
     * @param value
     *     allowed object is
     *     {@link Element }
     *     
     */
    public void setAny(Element value) {
        this.any = value;
    }
}

However, when I deploy my code (and expect to see the generated WSDL) I get the following exception:
java.lang.ClassCastException: com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$26 cannot be cast to com.sun.xml.bind.v2.model.core.EnumLeafInfo.

And, most interestingly, the exception occurs in XmlSchemaGenerator.java, but not in JAX-WS XmlSchemaGenerator, but in Glassfish Metro 2.3.1 XmlSchemaGenerator.java. How this is generally the mystery of the century.
The project consists of several modules (maven), but this module does not have a reference to metro in its pom.xml at all, however, it must be clarified that there is another module that uses metro. What is it and how can it be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Akushsky, 2015-09-29
@Namelles_One

In the end, everything turned out to be simpler, although it is still incomprehensible.
Moved all classes containing @XmlAnyElement to another package and, as a result, another XML-namespace, in relation to the @XmlRootElement classes.
And everything started up, wsdl was generated and works without problems. Some kind of magic.

V
Vladimir Smirnov, 2015-09-28
@bobzer

Typically, application servers already contain libraries to support web services. Your application probably also contains some of these libraries, or dependencies.
Try to deploy a "clean" application server, from scratch. Then deploy your application, but remove all libraries from it, or better yet, leave only the web service class and web.xml in general. If the web service deploys in this configuration, then add the necessary libraries (maven dependencies) one by one, rebuild and deploy again, until the error repeats. So you will understand which library is conflicting. Probably, it will need to be removed from dependencies, or specified as Provided.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question