You need to change the line:
_subscribe_subscribeRequest.getFilter().getAny().add(topicExpression);
to something like:
JAXBElement<?> elem = ObjectFactory.createTopicExpression(topicExpression);
_subscribe_subscribeRequest.getFilter().getAny().add(elem);
(You would need to look in the ObjectFactory for the appropriate method)
Basically, the "xsd:any" that is required by the getFilter().getAny() call
needs to be a top level element, not a type. Thus, you need to find the
method that would wrapper the "type" with an appropriate element definition.
Dan
On Tue June 9 2009 8:05:25 am Diefenbach Anne wrote:
> Hello,
>
> I am trying to write a CXF-based webservice which consumes
> WS-Notifications. Using wsdl2java, I have obtained all necessary classes,
> but now I have trouble filling my subscription message. I do the following:
>
> org.oasis_open.docs.wsn.b_2.Subscribe _subscribe_subscribeRequest =
> new org.oasis_open.docs.wsn.b_2.Subscribe(); TopicExpressionType
> topicExpression = new TopicExpressionType();
> topicExpression.setDialect("http://docs.oasis-open.org/wsn/t-1/TopicExpress
>ion/Simple"); topicExpression.getContent().add("myTopic");
> _subscribe_subscribeRequest.setFilter(new FilterType());
>
> _subscribe_subscribeRequest.getFilter().getAny().add(topicExpression); ...
> org.oasis_open.docs.wsn.b_2.SubscribeResponse _subscribe__return =
> port.subscribe(_subscribe_subscribeRequest);
>
> When I try to run my service, the subscription fails with the following
> exception:
>
> 09.06.2009 11:10:21 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
> INFO: Interceptor has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Marshalling Error: unable to marshal type
> "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an element because it
> is missing an @XmlRootElement annotation at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:176
>) at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:166) at
> org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(Abs
>tractOutDatabindingInterceptor.java:104) at
> org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutIntercep
>tor.java:68) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
>n.java:220) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:466) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:299) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:251) at
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124) at
> $Proxy45.subscribe(Unknown Source)
> at
> org.oasis_open.docs.wsn.bw_2.NotificationConsumer_NotificationConsumerPort_
>Server.subscribe(NotificationConsumer_NotificationConsumerPort_Server.java:6
>9) at
> org.oasis_open.docs.wsn.bw_2.NotificationConsumer_NotificationConsumerPort_
>Server.main(NotificationConsumer_NotificationConsumerPort_Server.java:133)
> Caused by: javax.xml.bind.MarshalException
> - with linked exception:
> [com.sun.istack.SAXException2: unable to marshal type
> "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an element because it
> is missing an @XmlRootElement annotation] at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
> at
> javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImp
>l.java:75) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:
>381) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:155
>) ... 12 more
> Caused by: com.sun.istack.SAXException2: unable to marshal type
> "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an element because it
> is missing an @XmlRootElement annotation at
> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:24
>4) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoIm
>pl.java:303) at
> com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeLi
>stBody(ArrayReferenceNodeProperty.java:114) at
> com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERP
>roperty.java:152) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:322) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:681) at
> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBod
>y(SingleElementNodeProperty.java:150) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:322) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:681) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
>InfoImpl.java:151) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
>InfoImpl.java:185) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanIn
>foImpl.java:305) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
>foImpl.java:312) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
>foImpl.java:71) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:49
>0) at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
> ... 16 more
> 09.06.2009 11:10:21 com.sun.xml.messaging.saaj.soap.ver1_2.Fault1_2Impl
> checkIfStandardFaultCode SCHWERWIEGEND: SAAJ0435:
> {http://cxf.apache.org/faultcode}HandlerFault is not a standard Code value
> Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
> Marshalling Error: unable to marshal type
> "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an element because it
> is missing an @XmlRootElement annotation at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145) at
> $Proxy45.subscribe(Unknown Source)
> at
> org.oasis_open.docs.wsn.bw_2.NotificationConsumer_NotificationConsumerPort_
>Server.subscribe(NotificationConsumer_NotificationConsumerPort_Server.java:6
>9) at
> org.oasis_open.docs.wsn.bw_2.NotificationConsumer_NotificationConsumerPort_
>Server.main(NotificationConsumer_NotificationConsumerPort_Server.java:133)
> Caused by: org.apache.cxf.interceptor.Fault: Marshalling Error: unable to
> marshal type "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an
> element because it is missing an @XmlRootElement annotation at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:176
>) at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:166) at
> org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(Abs
>tractOutDatabindingInterceptor.java:104) at
> org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutIntercep
>tor.java:68) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
>n.java:220) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:466) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:299) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:251) at
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124) ...
> 3 more
> Caused by: javax.xml.bind.MarshalException
> - with linked exception:
> [com.sun.istack.SAXException2: unable to marshal type
> "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an element because it
> is missing an @XmlRootElement annotation] at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
> at
> javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImp
>l.java:75) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:
>381) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:155
>) ... 12 more
> Caused by: com.sun.istack.SAXException2: unable to marshal type
> "org.oasis_open.docs.wsn.b_2.TopicExpressionType" as an element because it
> is missing an @XmlRootElement annotation at
> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:24
>4) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoIm
>pl.java:303) at
> com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeLi
>stBody(ArrayReferenceNodeProperty.java:114) at
> com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERP
>roperty.java:152) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:322) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:681) at
> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBod
>y(SingleElementNodeProperty.java:150) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:322) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:681) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
>InfoImpl.java:151) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
>InfoImpl.java:185) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanIn
>foImpl.java:305) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
>foImpl.java:312) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
>foImpl.java:71) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:49
>0) at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
> ... 16 more
>
> The schema defines
>
> <xsd:complexType name="TopicExpressionType" mixed="true">
> <xsd:sequence>
> <xsd:any minOccurs="0" maxOccurs="1" processContents="lax" />
> </xsd:sequence>
> <xsd:attribute name="Dialect" type="xsd:anyURI" use="required" />
> <xsd:anyAttribute />
> </xsd:complexType>
>
> and
>
> <xsd:element name="TopicExpression" type="wsnt:TopicExpressionType" />
>
> How can I tell the framework to use the element TopicExpression to marshal
> instances of TopicExpressionType? I use the FUSE Services Framework
> 2.1.3.1.
>
> Thank you,
>
> Anne Diefenbach
> - FKIE-KOM -
> *************************************************
> Forschungsgesellschaft für
> Angewandte Naturwissenschaften e. V. (FGAN)
> Neuenahrer Str. 20, 53343 Wachtberg, Germany
> E-Mail: [email protected]
> Web: www.fgan.de
> ************************************************
--
Daniel Kulp
[email protected]
http://www.dankulp.com/blog