IllegalAnnotationException: Two classes have the same XML type name
Asked Answered
S

4

38

I am developing web service under JBoss 5 and Java 1.6. What could possibly cause this exception? Below is my simplified web service code.

@Stateless
@WebService()
public class AccountWS {

@WebMethod()
public CreateAccountResponse createAccount(@WebParam(name = "request") CreateAccountRequest request) {
    return null;
}

And below is the full stack trace.

16:19:03,421 ERROR [AbstractKernelController] Error installing to Real: name=vfsfile:/C:/Apps/jbdevstudio/jboss-eap/jboss-as/server/default/deploy/sif_esb.esb/ state=PreReal mode=Manual requiredState=Real
org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/C:/Apps/jbdevstudio/jboss-eap/jboss-as/server/default/deploy/sif_esb.esb/
at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:177)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1440)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1158)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1099)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1633)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:935)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:985)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:823)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:782)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:403)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1633)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:935)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1083)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:985)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:775)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.registerProfile(AbstractProfileService.java:308)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:256)
at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
at org.jboss.Main.boot(Main.java:221)
at org.jboss.Main$1.run(Main.java:556)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Cannot build JAXB context
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.createJAXBContext(JAXWSMetaDataBuilder.java:984)
at org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder.buildWebServiceMetaData(JAXWSWebServiceMetaDataBuilder.java:151)
at org.jboss.ws.metadata.builder.jaxws.JAXWSServerMetaDataBuilder.setupProviderOrWebService(JAXWSServerMetaDataBuilder.java:50)
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilderEJB3.buildMetaData(JAXWSMetaDataBuilderEJB3.java:76)
at org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect.start(UnifiedMetaDataDeploymentAspect.java:69)
at org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl.deploy(DeploymentAspectManagerImpl.java:129)
at org.jboss.wsf.container.jboss50.deployer.ArchiveDeployerHook.deploy(ArchiveDeployerHook.java:76)
at org.jboss.wsf.container.jboss50.deployer.AbstractWebServiceDeployer.internalDeploy(AbstractWebServiceDeployer.java:60)
at org.jboss.wsf.container.jboss50.deployer.WebServiceDeployerEJB.internalDeploy(WebServiceDeployerEJB.java:113)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
... 29 more
Caused by: org.jboss.ws.WSException: Failed to create JAXBContext
at org.jboss.ws.core.jaxws.CustomizableJAXBContextFactory.createContext(CustomizableJAXBContextFactory.java:114)
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.createJAXBContext(JAXWSMetaDataBuilder.java:980)
... 39 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://kona.webservice.sif.unidata.com/}createAccountResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
    at com.unidata.sif.kona.account.message.CreateAccountResponse
    at private com.unidata.sif.kona.account.message.CreateAccountResponse com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse._return
    at com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse
this problem is related to the following location:
    at com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse

at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:448)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:297)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
at org.jboss.ws.core.jaxws.CustomizableJAXBContextFactory.createContext(CustomizableJAXBContextFactory.java:108)
... 40 more
Soerabaja answered 23/11, 2010 at 9:9 Comment(0)
S
88

I found the cause of my problem.

This problem occurs because JAX-WS generates a class for each method and the class name is constructed by concatenating methodName + "Response". In my case, the newly generated class by JAX-WS will have the same name as my response object.

Example:

@Stateless
@WebService()
public class AccountWS {

    @WebMethod()
    public CreateAccountResponse createAccount(@WebParam(name = "request") CreateAccountRequest request) {
        return null;
    }
}

JAX-WS will generate a new class CreateAccountResponse for Web Method createAccount which has the same name as the response object.

Solution:

Make sure that the name of the response object and method doesn't match. The same thing applies to the method parameter as well.

Soerabaja answered 25/11, 2010 at 10:20 Comment(1)
+1 for sharing the right solution (and very useful info about JAX-WS)Moritz
M
15

You have two XML schema elements with the same name (createAccountResponse) and the same namespace (http://kona.webservice.sif.unidata.com/) corresponding to the Java types com.unidata.sif.kona.account.message.CreateAccountResponse and com.unidata.sif.webservice.kona.jaxws.CreateAccountResponse. As the second one is "automagicaly" generated by the WebMethod annotation, it will be easier changing the XMLType anotation for the message element.

To solve it, you should change the name for one of them, or define two separated namespaces (one for the message elements, and another one for the WS request and response components). I recommend the last approach (two separated namespaces).

I.E:

1. Changing the name of the message element com.unidata.sif.kona.account.message.CreateAccountResponse.

@XMLType(name="CreateAccountResponseMsg", namespace="http://kona.webservice.sif.unidata.com")

2. Changing the namespace at message elements (package com.unidata.sif.kona.account.message)

@XMLType(name="CreateAccountResponse", namespace="http://kona.webservice.sif.unidata.com/message")
Moritz answered 23/11, 2010 at 9:22 Comment(3)
That is what the stack trace is trying to tell me I believe. But what I don't understand is why my other web services do not throw this exception.. I have checked against the other web services and the code is more or less similar.Soerabaja
With the information I have, I can't tell you the reason of this different behaviour. Sorry.Moritz
I found the cause.. checkout my answer.Soerabaja
T
5

I got the same error but I couldn't ajust the classes with @XmlType annotation (coming from library) So another solution is to provide a com.unidata.sif.kona.account.message/package-info.java with following code inside

@javax.xml.bind.annotation.XmlSchema(namespace = "http://kona.webservice.sif.unidata.com/")
package com.sopra.banking.processengine.servicecontract.v1_1.dto;
Tablet answered 2/10, 2015 at 16:6 Comment(0)
L
4

Another solution is to use @WebMethod(operationName="differentFromMethodName"). This will even change the interface method name on the client. JAX-WS still generates the classes for both wsgen and wsimport using the SEI's method name; but now the message element classes are different than the JAX_WS internally generated ones.

I did not want to touch the wsgen generated classes (message element classes).

Lobito answered 14/9, 2012 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.