1

我目前正在尝试使用 Websphere 中提供的 Emitter 类(与 Java2WSDL 工具相同)从 java 源代码生成 JAX-RPC Web 服务。我目前正在使用 WAS6.1 和 WAS7.0 进行测试。问题是当我尝试为“FooRequest”生成 WSDL 时,ComplexType“Foo”在 wsdl 中的定义中缺少 Bar[]。当我将 'FooRequest' 更改为返回 Bar[] 时,wsdl 会正确生成并且一切都很好。

为什么在 wsdl 中没有正确生成数组?
有什么我做错了吗?
使用数组生成 wsdl 的正确方法是什么?


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();
        }
    }
}

酒吧.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>
4

1 回答 1

-1

我找到了一个解决方案,以防将来有人发现这个问题。

问题是我之前从旧的 websphere 6.1 安装中获得了 jars:

  • 引导程序.jar
  • 类加载器.jar
  • emf.jar
  • ffdc.jar
  • j2ee.jar
  • ras.jar
  • wccm_base.jar
  • webserverices.jar
  • wsdl4j.jar
  • wsexception.jar

这些罐子是通过未知的其他人传递给我的,没有任何版本号或任何形式的元数据。我不知道它们是否是完整的真实版本,但它们可以工作。最初我将它们与提供的 websphere 6.1 JRE (java 1.5) 一起使用,但是当我现在部署到 websphere 7.0 时,我将我的软件更改为使用 websphere 7.0 (java 1.6)。我不知道的是 jar 和 java 1.5 版本是彼此特定的,所以当使用 java 1.6 JRE 时,Emitter 类不会失败,只是生成一个不正确的 wsdl。

为了解决这个问题,我只是将软件改回使用 java 1.5 JRE,直到我有时间更正 jar。

于 2013-02-04T01:00:15.813 回答