Results 1 to 6 of 6

Thread: Problems with JiBX WS Client

  1. #1
    Join Date
    Oct 2007
    Posts
    8

    Default Problems with JiBX WS Client

    I'm attempting to consume a WS and am having no luck Marshalling or UnMarshalling through JiBX. I was hoping some assistance from the board will prevent me from checking into the Loony Bin...

    I'm currently using JDK 1.5, and JiBX 1.1.5, and used xsd2jibx xsd2jibx-beta0.2b to generate my Client stubs & binding.xml

    Any examples using JiBX would be much appreciated, as I could not find any on the web.


    The Exception I'm getting:
    HTML Code:
    Unable to access binding information for class net.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled;
    My ApplicationContext is as follows:
    HTML Code:
    <bean id="webServiceClient" class="com.company.WebServiceClient">
    	<property name="defaultUri" value="http://www.webservicex.net/WeatherForecast.asmx"/>
    	<property name="marshaller" ref="marshaller" />
    	<property name="unmarshaller" ref="unmarshaller" />
    </bean>
    <bean id="marshaller" class="org.springframework.oxm.jibx.JibxMarshaller" >
     	<property name="targetClass"><value>net.webservicex.GetWeatherByZipCode</value></property>
    </bean>
    <bean id="unmarshaller" class="org.springframework.oxm.jibx.JibxMarshaller" >
    	<property name="targetClass"><value>net.webservicex.GetWeatherByZipCodeResponse</value></property>
    </bean>
    My Client Source is as follow:
    HTML Code:
    public class WebServiceClient extends WebServiceGatewaySupport{
    
    	public void customSendAndReceive() {
    	
    	GetWeatherByZipCode gvr = new GetWeatherByZipCode();
    	gvr.setZipCode("19026");
    	GetWeatherByZipCodeResponse response = (GetWeatherByZipCodeResponse) getWebServiceTemplate().marshalSendAndReceive(gvr, new WebServiceMessageCallback(){
            public void doInMessage(WebServiceMessage message) {
                ((SoapMessage)message).setSoapAction("http://www.webservicex.net/GetWeatherByZipCode");
            }
    
    		public void doWithMessage(WebServiceMessage arg0) throws IOException,
    				TransformerException {
    			// TODO Auto-generated method stub
    			
    		}			
    	});	
        }
    
    public static void main(String[] args) throws IOException {
    	ApplicationContext applicationContext =
    		new ClassPathXmlApplicationContext("applicationContext.xml", WebServiceClient.class);
    	WebServiceClient ws = (WebServiceClient) applicationContext.getBean("webServiceClient");
    	ws.customSendAndReceive();
    	
    The WSDL can be found at: http://localhost:8080/axis2/services...ngService?wsdl
    The Schema is as follow:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.webservicex.net"
              xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.webservicex.net">
          <s:element name="GetWeatherByZipCode">
            <s:complexType>
              <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="ZipCode" type="s:string"/>
              </s:sequence>
            </s:complexType>
          </s:element>
          <s:element name="GetWeatherByZipCodeResponse">
            <s:complexType>
              <s:sequence>
                <s:element minOccurs="1" maxOccurs="1" name="GetWeatherByZipCodeResult" type="tns:WeatherForecasts"/>
              </s:sequence>
            </s:complexType>
          </s:element>
          <s:complexType name="WeatherForecasts">
            <s:sequence>
              <s:element minOccurs="1" maxOccurs="1" name="Latitude" type="s:float"/>
              <s:element minOccurs="1" maxOccurs="1" name="Longitude" type="s:float"/>
              <s:element minOccurs="1" maxOccurs="1" name="AllocationFactor" type="s:float"/>
              <s:element minOccurs="0" maxOccurs="1" name="FipsCode" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="PlaceName" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="StateCode" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="Status" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="Details" type="tns:ArrayOfWeatherData"/>
            </s:sequence>
          </s:complexType>
          <s:complexType name="ArrayOfWeatherData">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="unbounded" name="WeatherData" type="tns:WeatherData"/>
            </s:sequence>
          </s:complexType>
          <s:complexType name="WeatherData">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="1" name="Day" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="WeatherImage" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="MaxTemperatureF" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="MinTemperatureF" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="MaxTemperatureC" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="MinTemperatureC" type="s:string"/>
            </s:sequence>
          </s:complexType>
    </s:schema>
    The JiBX Binding is as follow:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <binding>
      <mapping name="GetWeatherByZipCode" class="net.webservicex.GetWeatherByZipCode">
        <namespace uri="http://www.webservicex.net" default="elements"/>
        <value name="ZipCode" field="zipCode" usage="optional"/>
      </mapping>
      <mapping name="GetWeatherByZipCodeResponse" class="net.webservicex.GetWeatherByZipCodeResponse">
        <namespace uri="http://www.webservicex.net" default="elements"/>
        <structure field="getWeatherByZipCodeResult" usage="required" map-as="net.webservicex.WeatherForecasts"/>
      </mapping>
      <mapping name="GetWeatherByZipCodeResult" class="net.webservicex.WeatherForecasts">
        <namespace uri="http://www.webservicex.net" default="elements"/>
        <value name="Latitude" field="latitude" usage="required"/>
        <value name="Longitude" field="longitude" usage="required"/>
        <value name="AllocationFactor" field="allocationFactor" usage="required"/>
        <value name="FipsCode" field="fipsCode" usage="optional"/>
        <value name="PlaceName" field="placeName" usage="optional"/>
        <value name="StateCode" field="stateCode" usage="optional"/>
        <value name="Status" field="status" usage="optional"/>
        <structure field="details" usage="optional" map-as="net.webservicex.ArrayOfWeatherData"/>
      </mapping>
      <mapping name="Details" class="net.webservicex.ArrayOfWeatherData">
        <namespace uri="http://www.webservicex.net" default="elements"/>
        <collection field="weatherDataList">
          <structure map-as="net.webservicex.WeatherData"/>
        </collection>
      </mapping>
      <mapping name="WeatherData" class="net.webservicex.WeatherData">
        <namespace uri="http://www.webservicex.net" default="elements"/>
        <value name="Day" field="day" usage="optional"/>
        <value name="WeatherImage" field="weatherImage" usage="optional"/>
        <value name="MaxTemperatureF" field="maxTemperatureF" usage="optional"/>
        <value name="MinTemperatureF" field="minTemperatureF" usage="optional"/>
        <value name="MaxTemperatureC" field="maxTemperatureC" usage="optional"/>
        <value name="MinTemperatureC" field="minTemperatureC" usage="optional"/>
      </mapping>
    </binding>

    Thanks in advance!!!

    -Marcelo

  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    From glancing over it, it looks ok. WHat is the error you are getting? Could you add the log file as well?
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Oct 2007
    Posts
    8

    Default

    I'm thinking it has to be some sort of Jar conflict, but I've tried switching versions of particular Third-Party Jars, but still nothing...

    Here's my output:

    HTML Code:
    [ INFO] 14:41:35 ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c55e36: display name [org.springframework.context.support.ClassPathXmlApplicationContext@c55e36]; startup date [Tue Oct 30 14:41:35 EDT 2007]; root of context hierarchy
    [ INFO] 14:41:35 XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
    [ INFO] 14:41:36 ClassPathXmlApplicationContext - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@c55e36]: org.springframework.beans.factory.support.DefaultListableBeanFactory@a46701
    [ INFO] 14:41:36 DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@a46701: defining beans [webServiceClient,webServiceJaxbSoapClient,webServiceJibxSoapClient,messageFactory,webServiceTemplate,castorMarshaller,jibxMarshaller,jibxUnmarshaller,xmlBeansMarshaller,jaxb2Marshaller]; root of factory hierarchy
    [ INFO] 14:41:37 SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
    [ INFO] 14:41:37 SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
    [ INFO] 14:41:37 JibxMarshaller - Configured for target class [class net.jibx.webservicex.GetWeatherByZipCode]
    [ INFO] 14:41:37 DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@a46701: defining beans [webServiceClient,webServiceJaxbSoapClient,webServiceJibxSoapClient,messageFactory,webServiceTemplate,castorMarshaller,jibxMarshaller,jibxUnmarshaller,xmlBeansMarshaller,jaxb2Marshaller]; root of factory hierarchy
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webServiceJibxSoapClient' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'jibxMarshaller' while setting bean property 'marshaller'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jibxMarshaller' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.jibx.JibxSystemException: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled; nested exception is org.jibx.runtime.JiBXException: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jibxMarshaller' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.jibx.JibxSystemException: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled; nested exception is org.jibx.runtime.JiBXException: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled
    Caused by: org.springframework.oxm.jibx.JibxSystemException: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled; nested exception is org.jibx.runtime.JiBXException: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled
    Caused by: Unable to access binding information for class net.jibx.webservicex.GetWeatherByZipCode
    Make sure the binding has been compiled
    java.lang.NoSuchFieldException: JiBX_bindingList
    	at java.lang.Class.getDeclaredField(Class.java:1854)
    	at org.jibx.runtime.BindingDirectory.getBindingList(BindingDirectory.java:70)
    	at org.jibx.runtime.BindingDirectory.getFactory(BindingDirectory.java:207)
    	at org.springframework.oxm.jibx.JibxMarshaller.afterPropertiesSet(JibxMarshaller.java:132)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1095)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:180)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:155)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:141)
    	at com.jnj.hp2.benefitrisk.contentadapter.test.WebServiceClient.main(WebServiceClient.java:181)
    

  4. #4
    Join Date
    Oct 2007
    Posts
    8

    Default

    Do you need to have the JiBX Binding file within the classpath? Is that what's causing this problem? I haven't read anywhere that states that you need this, but I wasn't sure. If this is the case, what does it need to be named, and where should it be located? I've seen that you can set the bindingName like the following:

    HTML Code:
    <bean id="jibxMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller" >
            <property name="targetClass"><value>net.webservicex.GetWeatherByZipCode</value></property>
            <property name="bindingName" value="classpath:binding.xml"/>
    </bean>
    But am not 100% sure that is the correct way to configure this.

  5. #5
    Join Date
    Dec 2005
    Posts
    929

    Default

    I have seen this problem in my current application and I believe it is caused by one of 2 things.

    Are you using an IDE, like Eclipse? If so, how are you running the JiBX binding compiler task? I had to register a builder in Eclipse to run an Ant script:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
         Maven2 should be used for build. This build.xml is to inject JiBX binding into the compiled class files via externalToolBuilders feature of Eclipse. 
    -->
    <project name="pap-core" default="jibx_build" basedir=".">
    	<property name="build.classes.dir" value="${basedir}/target/classes" />
    	<property name="lib.dir" value="${M2_REPO}" />
    	<path id="build.classpath">
    		<fileset dir="${lib.dir}">
    			<include name="**/jibx/**/1.1.3/*.jar" />
    			<include name="**/bcel/**/5.2/*.jar" />
    			<include name="**/xpp3/**/1.1.3.4.O/*.jar" />
    			<include name="**/stax/stax-api/1.0.1/*.jar" />
    			<include name="**/stax/stax/1.2.0/*.jar" />
    		</fileset>
    	</path>
    	<taskdef name="bind" description="JiBX binding compiler task definition" classname="org.jibx.binding.ant.CompileTask" classpathref="build.classpath" />
    	<target name="jibx_build" description="Runs (BCEL) Byte Code Enhancement for XML binding for marshalling/unmarshaling ">
    		<bind verbose="true" load="false">
    			<bindingfileset dir=".">
    				<include name="etc/jibx_binding/pap_jibx_binding.xml" />
    			</bindingfileset>
    			<classpathset dir="${build.classes.dir}" />
    		</bind>
    	</target>
    </project>
    So whenever I do a clean or modify some code in this project, the ant script runs and the JiBX compiler does its stuff.

    If you do a clean within Eclipse, without re-running the JiBX compiler, the classes won't have the byte-code injected JiBX information them and you will get the error you mentioned.

    Secondly, are your XML messages namespace aware? I.e. do they have an xmlns attribute in them? If so, you will have to add the namespace to the binding, either at a global level (below the binding element) or in each mapping if the namespaces are different for each mapping. An example I have is:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <binding>
    	<namespace uri="http://www.gilbarco.com/schema/wow" default="elements" />
    	<mapping name="ClientInfo" class="au.com.woolworths.pap.oxm.ClientInfoDto" ordered="true">
    ....	
    	</mapping>
    Alan

  6. #6
    Join Date
    Oct 2007
    Posts
    8

    Default

    Alan your the greatest!!! I completely forgot about the JiBX Compiler step. It worked like a charm afterwards!

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •