You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Johnson, Eric" <Er...@iona.com> on 2008/09/09 20:57:47 UTC

Adding JAXB classes in 2.0.x

I was looking over the system test for adding extra JAXB classes to the
JAXB context and noticed that it relied on ClassArrayFactoryBean.
ClassArrayFactoryBean is a system test specific class.
 
Is there an equivalent class in the regular CXF APIs? Or is there
another class I could use in its place?
 
Cheers,
Eric

Re: Adding JAXB classes in 2.0.x

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Johnson, Eric wrote:
> Will this also work for <jaxws:client>?

It should do.  I don't create my clients using Spring but I do the same
thing in my Java code that your Spring configuration does, and it works
for me.

Though thinking about it I don't use any of my extra classes as method
argument types, only as return types.  I don't know if that makes any
difference.

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

RE: Adding JAXB classes in 2.0.x

Posted by "Johnson, Eric" <Er...@iona.com>.
Will this also work for <jaxws:client>?

I'm trying to get an app running using the following Spring config:
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jaxws="http://cxf.apache.org/jaxws"
      xmlns:cxf="http://cxf.apache.org/core"
      xmlns:soap="http://cxf.apache.org/bindings/soap"
      xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schema/bindings/soap.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

     <jaxws:client
name="{http://apache.org/hello_world_soap_http}SoapPort"
        createdFromAPI="true">
 <jaxws:dataBinding>
      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
        <property name="extraClass">
          <list>
            <value>com.widgetvendor.types.basetypes.Reservation</value>
 
<value>com.widgetvendor.types.basetypes.ObjectFactory</value>
 
<value>com.widgetvendor.types.widgettypes.ObjectFactory</value>
 
<value>com.widgetvendor.types.widgettypes.ReserveActual</value>
          </list>
        </property>
      </bean>
    </jaxws:dataBinding>
    </jaxws:client>

    <jaxws:server
name="{http://apache.org/hello_world_soap_http}SoapPort"
        wsdlLocation="wsdl/hello_world.wsdl"
        createdFromAPI="true">
<jaxws:dataBinding>
      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
        <property name="extraClass">
          <list>
            <value>com.widgetvendor.types.basetypes.Reservation</value>
 
<value>com.widgetvendor.types.basetypes.ObjectFactory</value>
 
<value>com.widgetvendor.types.widgettypes.ObjectFactory</value>
 
<value>com.widgetvendor.types.widgettypes.ReserveActual</value>
          </list>
        </property>
      </bean>
    </jaxws:dataBinding>
    </jaxws:server>
</beans> 

The client throws the following exception when attempting to send a
request using a class that extends
com.widgetvendor.types.basetypes.Reservation:
     [java] Exception in thread "main"
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error : Unable to
create an instance of com.widgetvendor.types.basety
pes.Reservation
     [java]     at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:175)
     [java]     at $Proxy26.greetMe(Unknown Source)
     [java]     at demo.hw.client.Client.main(Client.java:68)
     [java] Caused by: org.apache.cxf.binding.soap.SoapFault:
Unmarshalling Error : Unable to create an instance of
com.widgetvendor.types.basetypes.Reservation

     [java]     at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleM
essage(Soap11FaultInInterceptor.java:70)
     [java]     at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleM
essage(Soap11FaultInInterceptor.java:35)
     [java]     at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:207)
     [java]     at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage
(AbstractFaultChainInitiatorObserver.java:90)
     [java]     at
org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMes
sage(ReadHeadersInterceptor.java:179)
     [java]     at
org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMes
sage(ReadHeadersInterceptor.java:56)
     [java]     at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:207)
     [java]     at
org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:395)
     [java]     at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResp
onse(HTTPConduit.java:1932)
     [java]     at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTP
Conduit.java:1790)
     [java]     at
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
     [java]     at
org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:576)
     [java]     at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingI
nterceptor.handleMessage(MessageSenderInterceptor.java:62)
     [java]     at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:207)
     [java]     at
org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
     [java]     at
org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:205)
     [java]     at
org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
     [java]     at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
     [java]     ... 2 more
     [java] Java Result: 1


-----Original Message-----
From: Ian Roberts [mailto:i.roberts@dcs.shef.ac.uk] 
Sent: Tuesday, September 09, 2008 7:43 PM
To: users@cxf.apache.org
Subject: Re: Adding JAXB classes in 2.0.x

Johnson, Eric wrote:
> I was looking over the system test for adding extra JAXB classes to 
> the JAXB context and noticed that it relied on ClassArrayFactoryBean.
> ClassArrayFactoryBean is a system test specific class.
>  
> Is there an equivalent class in the regular CXF APIs? Or is there 
> another class I could use in its place?

I do it like this:

  <jaxws:server id="serviceEndpoint"
                  serviceBean="#serviceImpl"
                  serviceClass="my.service.ServiceImpl"
                  address="/some-service">
    <jaxws:dataBinding>
      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
        <property name="extraClass">
          <list>
            <value>my.service.ExtraClass1</value>
            <value>my.service.ExtraClass2</value>
          </list>
        </property>
      </bean>
    </jaxws:dataBinding>
  </jaxws:server>


This works because the JAXBDataBinding.extraClass property is strongly
typed as a Class[], so Spring handles the type conversion from the
<list> value without needing a FactoryBean to do the work.

Note this doesn't work with <jaxws:endpoint>, but <jaxws:server> has
exactly the same effect, it just works slightly differently under the
covers.

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

Re: Adding JAXB classes in 2.0.x

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Johnson, Eric wrote:
> I was looking over the system test for adding extra JAXB classes to the
> JAXB context and noticed that it relied on ClassArrayFactoryBean.
> ClassArrayFactoryBean is a system test specific class.
>  
> Is there an equivalent class in the regular CXF APIs? Or is there
> another class I could use in its place?

I do it like this:

  <jaxws:server id="serviceEndpoint"
                  serviceBean="#serviceImpl"
                  serviceClass="my.service.ServiceImpl"
                  address="/some-service">
    <jaxws:dataBinding>
      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
        <property name="extraClass">
          <list>
            <value>my.service.ExtraClass1</value>
            <value>my.service.ExtraClass2</value>
          </list>
        </property>
      </bean>
    </jaxws:dataBinding>
  </jaxws:server>


This works because the JAXBDataBinding.extraClass property is strongly
typed as a Class[], so Spring handles the type conversion from the
<list> value without needing a FactoryBean to do the work.

Note this doesn't work with <jaxws:endpoint>, but <jaxws:server> has
exactly the same effect, it just works slightly differently under the
covers.

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK