Skip to main content

JAX-WS: xmlstreamreaderexception unexpected xml tag

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
RookyMoto
Offline
Joined: 2013-10-08

Hello,

I try to run a JAX-WS Web Service. Therefore I created a Web Service from WSDL with NetBeans 7.3.1. If I run the Web Service I get this error:
Caused by: com.sun.xml.ws.streaming.XMLStreamReaderException: unexpected xml tag. expected {http://example.com/exmaple/example/}, but found {http://exmaple.com/schema/}

I have nowhere in my entire project the string "http://exmaple.com/schema/" also not in the WSDL file. Then I tried to implement a SOAPHandler like this guy recommended:
http://stackoverflow.com/questions/10235145/webservice-response-namespac...

I had to change the code otherwise I get:
Caused by: java.lang.ClassCastException: com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPElement

to:

Text textElement = (Text) soapBody.getFirstChild();
SOAPElement oldElement = textElement.getParentElement();

but I run into java.lang.StackOverflowError. Reason is the recursive method:

private void cloneToNewNamespace(Node nodeToRename, SOAPElement parentElement, String prefix) throws SOAPException {
        if (nodeToRename instanceof SOAPElement) {
            SOAPElement elementToRename = (SOAPElement) nodeToRename;
            SOAPElement newElement = parentElement.addChildElement(elementToRename.getElementName().getLocalName(), prefix);
            int tmp = elementToRename.getChildNodes().getLength();

            for (int index = 0; index < elementToRename.getChildNodes().getLength(); index++) {
                Node childNode = elementToRename.getChildNodes().item(index);
                cloneToNewNamespace(childNode, newElement, prefix);
            }
        } else {
            parentElement.addTextNode(nodeToRename.getNodeValue());
        }
    }

I also tried to intercept this issue by adding a javax.xml.ws.handler.LogicalHandler, but there was no chance to change anything.

Another guy posted also this issue in this forum:
https://www.java.net//forum/topic/glassfish/metro-and-jaxb/accessing-web...
but I don't use or have sun-jaxws.xml. So this workaround doesn't work for me.

In this blog somebody gave the advice to annotate bidirectional objects with @Transient:
http://extremejava.tpk.com.br/2010/04/23/mixing-jpa-with-jaxbjaxws/
But I have no bidirectional mapping. So this is also not the solution.

My pom.xml looks like this:

<dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <webResources>
                        <resource>
                            <directory>src</directory>
                            <targetPath>WEB-INF</targetPath>
                            <includes>
                                <include>jax-ws-catalog.xml</include>
                                <include>wsdl/**</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.2.1</version>

                <dependencies>
                    <dependency>
                        <groupId>javax.xml</groupId>
                        <artifactId>webservices-api</artifactId>
                        <version>1.4</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
                    <xnocompile>true</xnocompile>
                    <verbose>true</verbose>
                    <extension>true</extension>
                    <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
                </configuration>
            </plugin>

I use the following versions:

Glassfish: 3.1.2.2
JAX-WS: JAX-WS RI 2.2.7-b01
JDK: 1.7.25

Can somebody give me a hint to solve this issue?
(I also posted this question on StackOverflow, but didn't get an answer)