Question

I am currently try to generate JAX-RPC webservices from java source using the Emitter class (the same as the Java2WSDL tool) provided in Websphere. I am currently using WAS6.1 and WAS7.0 for testing. The issue is when I attempt to generate the WSDL for 'FooRequest' the ComplexType 'Foo' is missing the Bar[] from it's definition in the wsdl. When I change 'FooRequest' to return Bar[] the wsdl is generated correctly and everything is fine.

Why aren't the arrays being generated in the wsdl correctly?
Is there something which I am doing wrong?
What is the correctly way to generate the wsdl with the arrays?


Foo.Java

package test;

import com.ibm.ws.webservices.wsdl.fromJava.Emitter;

public class Foo {

    private Bar[] bars;

    private Bar bar;

    private String[] data;

    public Bar[] getBars() {
        return bars;
    }

    public void setBars(Bar[] bars) {
        this.bars = bars;
    }

    public Bar getBar() {
        return bar;
    }

    public void setBar(Bar bar) {
        this.bar = bar;
    }

    public String[] getData() {
        return data;
    }

    public void setData(String[] data) {
        this.data = data;
    }

    public static void main(String[] args) {
        Emitter parser = new Emitter();

        parser.setCls("test.FooRequest");
        parser.setLocationUrl("http://localhost:8080/services/doFooService");

        // Set style/use
        parser.setStyle("document");
        parser.setUse("literal");

        parser.setIntfNamespace("urn:doFooService");
        parser.setClasspath("C:\\temp\\foo");

        parser.setWrapped(true);

        // Generate WSDL
        try {
            parser.emit("C:\\temp\\foo\\Foo.wsdl");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Bar.java

package test;

public class Bar {

    private String baz;

    public String getBaz() {
        return baz;
    }

    public void setBaz(String baz) {
        this.baz = baz;
    }
}

FooRequest.java

package test;

public class FooRequest {

    public Foo getFoo(String input) {
        Foo foo = new Foo();
        Bar[] bars = new Bar[5];
        Bar bar;
        for (int i = 0; i < bars.length; i++) {
            bar = new Bar();
            bar.setBaz("baz:" + (i + 1));
            bars[i] = bar;
        }
        foo.setBars(bars);
        bar = new Bar();
        bar.setBaz("Power Bar");
        foo.setBar(bar);

        String[] data = new String[5];
        for (int i = 0; i < data.length; i++) {
            data[i] = "baz:" + (i + 1);
        }
        return foo;
    }
}

Foo.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:impl="urn:doFooService" xmlns:intf="urn:doFooService" xmlns:tns1="http://test" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:doFooService">
    <wsdl:types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:doFooService">
            <import namespace="http://test" />
            <element name="getFooResponse">
                <complexType>
                    <sequence>
                        <element name="getFooReturn" nillable="true" type="tns1:Foo" />
                    </sequence>
                </complexType>
            </element>
            <element name="getFoo">
                <complexType>
                    <sequence>
                        <element name="input" nillable="true" type="xsd:string" />
                    </sequence>
                </complexType>
            </element>
        </schema>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test">
            <complexType name="Foo">
                <sequence>
                    <element name="bar" nillable="true" type="tns1:Bar" />
                </sequence>
            </complexType>
            <complexType name="Bar">
                <sequence>
                    <element name="baz" nillable="true" type="xsd:string" />
                </sequence>
            </complexType>
        </schema>
    </wsdl:types>
    <wsdl:message name="getFooResponse">
        <wsdl:part element="impl:getFooResponse" name="parameters" />
    </wsdl:message>
    <wsdl:message name="getFooRequest">
        <wsdl:part element="impl:getFoo" name="parameters" />
    </wsdl:message>
    <wsdl:portType name="FooRequest">
        <wsdl:operation name="getFoo">
            <wsdl:input message="impl:getFooRequest" name="getFooRequest" />
            <wsdl:output message="impl:getFooResponse" name="getFooResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="doFooServiceSoapBinding" type="impl:FooRequest">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="getFoo">
            <wsdlsoap:operation soapAction="" />
            <wsdl:input name="getFooRequest">
                <wsdlsoap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="getFooResponse">
                <wsdlsoap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="FooRequestService">
        <wsdl:port binding="impl:doFooServiceSoapBinding" name="doFooService">
            <wsdlsoap:address location="http://localhost:8080/services/doFooService" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
Was it helpful?

Solution

I found a solution in case anyone finds this question in the future.

The issue was that I had previously obtained jars from an installation of old websphere 6.1:

  • bootstrap.jar
  • classloader.jar
  • emf.jar
  • ffdc.jar
  • j2ee.jar
  • ras.jar
  • wccm_base.jar
  • webserverices.jar
  • wsdl4j.jar
  • wsexception.jar

These jars had been passed to me via unknown other other, with no version numbers or metadata of any form. I have no idea if they are real releases of intact, but they work. Initially I was using them with the provided websphere 6.1 JRE (java 1.5), but as I was now deploying to websphere 7.0 I changed my software to use the websphere 7.0 (java 1.6). What I wasn't aware of is that the jar's and the java 1.5 release were specific to each other, so when using the java 1.6 JRE the Emitter class wouldn't fail, simply generate an incorrect wsdl.

To fix this, I just changed the software back to use the java 1.5 JRE until I have the time to correct the jar's.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top