Thursday, May 10, 2012


Solution to - On creating apache cxf web service getting error: org.apache.cxf.service.factory.ServiceConstructionException and xxx counts of com.sun.xml.bind.v2.runtime.IllegalAnnotationExceptions


Complete stack trace is: - 



Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:351)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:460)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:548)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:523)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:271)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:177)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:100)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:102)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:115)
at com.landisgyr.iec61968.cl.transports.ummv2ws.ServiceObjectTransport.init(ServiceObjectTransport.java:59)
at com.landisgyr.iec61968.cl.transports.ummv2ws.ServiceObjectTransport.start(ServiceObjectTransport.java:44)
at com.landisgyr.iec61968.cl.protocols.CLProtocol.start(CLProtocol.java:454)
at com.landisgyr.iec61968.cl.common.CommunicationLibrary.start(CommunicationLibrary.java:181)
at c1.test.TestComLibPOC.main(TestComLibPOC.java:113)
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://iec.ch/TC57/2011/schema/message}Response". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.landisgyr.iec61968.cl.transports.ummv2ws.jaxws_asm.PublishEventResponse
this problem is related to the following location:
at com.landisgyr.iec61968.cl.transports.ummv2ws.jaxws_asm.RequestResponse
Two classes have the same XML type name "{http://iec.ch/TC57/2011/schema/message}Response". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.landisgyr.iec61968.cl.transports.ummv2ws.jaxws_asm.RequestResponse
this problem is related to the following location:
at com.landisgyr.iec61968.cl.transports.ummv2ws.jaxws_asm.Response
Two classes have the same XML type name "{http://iec.ch/TC57/2011/schema/message}Response". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.landisgyr.iec61968.cl.transports.ummv2ws.jaxws_asm.Response
this problem is related to the following location:
at com.landisgyr.iec61968.cl.transports.ummv2ws.jaxws_asm.ResponseResponse


at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1136)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:510)
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:334)
... 14 more

I have found the solution here - 

In my case the web service method name is: - 


    @RequestWrapper(localName = "Request", targetNamespace = "http://iec.ch/TC57/2011/schema/message", className = "IEC61968.ch.iec.tc57.LG._2011.RequestMessageType")
    @WebMethod(operationName = "Request", action = "http://iec.ch/61968/Request")
    @ResponseWrapper(localName = "Response", targetNamespace = "http://iec.ch/TC57/2011/schema/message", className = "IEC61968.ch.iec.tc57.LG._2011.ResponseMessageType")
    public void request(
        @WebParam(mode = WebParam.Mode.INOUT, name = "Header", targetNamespace = "")
        javax.xml.ws.Holder<HeaderType> header,
        @WebParam(name = "Request", targetNamespace = "http://iec.ch/TC57/2011/schema/message")
        RequestType request,
        @WebParam(mode = WebParam.Mode.INOUT, name = "Payload", targetNamespace = "")
        javax.xml.ws.Holder<PayloadType> payload,
        @WebParam(mode = WebParam.Mode.OUT, name = "Reply", targetNamespace = "")
        javax.xml.ws.Holder<ReplyType> reply
    );

In this case the method name is - 'request', and also the method parameter name is - 'request'

JAX-WS generates a class for each method, in this case the class name constructed is-methodName + "Response", which is actually translates toRequestResponse
In my case, the newly generated class by JAX-WS will have the same name as my method parameter  name which is a request by name, JAX-WS also generates the same class name - 'RequestResponse'. That is why the reason for conflict.

I have  changed the method parameter name from 'request' to 'req', and it works perfectly fine, and I am able to start the web service with no issues. Thanks to stackoverflow.com and Rosdi Kasim.