Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 无法使用WSDL生成的存根解组响应_Spring_Web Services_Jaxb_Wsdl - Fatal编程技术网

Spring 无法使用WSDL生成的存根解组响应

Spring 无法使用WSDL生成的存根解组响应,spring,web-services,jaxb,wsdl,Spring,Web Services,Jaxb,Wsdl,我用Maven生成了JAXB文件。WSDL是。我使用过滤器对名称冲突进行编号 一旦我运行代码,它就会显示以下错误 [com.sun.istack.SAXException2: unable to marshal type "com.myproject.flight.SearchFlights2" as an element because it is missing an @XmlRootElement annotation] 一旦我将@XmlRootElement注释添加到SearchF

我用Maven生成了JAXB文件。WSDL是。我使用过滤器对名称冲突进行编号

一旦我运行代码,它就会显示以下错误

[com.sun.istack.SAXException2: unable to marshal type 
"com.myproject.flight.SearchFlights2" as an element because it is missing an 
@XmlRootElement annotation]
一旦我将
@XmlRootElement
注释添加到
SearchFlights2
类中,代码就会显示以下错误

Caused by: javax.xml.bind.UnmarshalException: unexpected element 
(uri:"ElsyArres.API", local:"SearchFlightsResponse"). Expected elements are 
<{ElsyArres.API}Inbound>,<{ElsyArres.API}Leg>,<{ElsyArres.API}Legs>,
<{ElsyArres.API}Outbound>,<{ElsyArres.API}searchFlights2>
客户端

SearchFlightsResponse response = (SearchFlightsResponse) webServiceTemplate
                    .marshalSendAndReceive(
                            "http://www5v80.elsyarres.net/service.asmx",
                            searchFlights, new WebServiceMessageCallback() {
                                public void doWithMessage(
                                        WebServiceMessage message) {
                                    ((SoapMessage) message)
                                            .setSoapAction("ElsyArres.API/SearchFlights");
                                }
                            });

            SearchFlightsResponse msg = (SearchFlightsResponse) response;
            System.err.println("Wegolo >>>"
                    + msg.getSoapMessage().getResponse().getFlights()
                            .getFlight().size());
JAXB

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "soapMessage" })
@XmlRootElement(name = "SearchFlightsResponse")
public class SearchFlightsResponse {

    @XmlElement(name = "SoapMessage")
    protected SearchFlights2 soapMessage;

    getters and setters



@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SearchFlights", propOrder = { "request", "response" })
public class SearchFlights2 extends SoapMessageBase {

    @XmlElement(name = "Request")
    protected SearchFlightsRequest request;
    @XmlElement(name = "Response")
    protected SearchFlightsResponse2 response;

    getters and setters


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SearchFlightsRequest", propOrder = { "departure",
        "destination", "departureDate", "returnDate", "numADT", "numINF",
        "numCHD", "currencyCode", "customContainer", "carrierList",
        "fareClasses", "providers", "waitForResult", "nearbyDepartures",
        "nearbyDestinations", "rrOnly", "metaSearch" })
public class SearchFlightsRequest {

    @XmlElement(name = "Departure")
    protected String departure;
    @XmlElement(name = "Destination")
    protected String destination;
    @XmlElement(name = "DepartureDate")
    protected String departureDate;
    @XmlElement(name = "ReturnDate")
    protected String returnDate;
    @XmlElement(name = "NumADT")
    protected int numADT;
    @XmlElement(name = "NumINF")
    protected int numINF;
    @XmlElement(name = "NumCHD")
    protected int numCHD;
    @XmlElement(name = "CurrencyCode", required = true)
    @XmlSchemaType(name = "string")
    protected CurrencyCode currencyCode;
    @XmlElement(name = "CustomContainer")
    protected String customContainer;
    @XmlElement(name = "CarrierList")
    protected ArrayOfString carrierList;
    @XmlElement(name = "FareClasses")
    protected ArrayOfFareClass fareClasses;
    @XmlElement(name = "Providers")
    protected ArrayOfProvider providers;
    @XmlElement(name = "WaitForResult")
    protected boolean waitForResult;
    @XmlElement(name = "NearbyDepartures")
    protected boolean nearbyDepartures;
    @XmlElement(name = "NearbyDestinations")
    protected boolean nearbyDestinations;
    @XmlElement(name = "RROnly")
    protected boolean rrOnly;
    @XmlElement(name = "MetaSearch")
    protected boolean metaSearch;

    getters and setters


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SearchFlightsResponse", propOrder = {
    "searchFlightId",
    "roundtrip",
    "currencyCode",
    "flights"
})
public class SearchFlightsResponse2 {

    @XmlElement(name = "SearchFlightId")
    protected String searchFlightId;
    @XmlElement(name = "Roundtrip")
    protected boolean roundtrip;
    @XmlElement(name = "CurrencyCode", required = true)
    @XmlSchemaType(name = "string")
    protected CurrencyCode currencyCode;
    @XmlElement(name = "Flights")
    protected ArrayOfFlight flights;

    getters and setters
马文


org.jvnet.jaxb2.maven2
maven-jaxb2-plugin
0.12.3
生成
-XautoNameResolution
WSDL
hello.wsdl
http://www5v80.elsyarres.net/service.asmx?wsdl

您需要使用如下绑定

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="http://www5v80.elsyarres.net/service.asmx?wsdl"
            xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='ElsyArres.API']">
        <jaxb:schemaBindings>
            <jaxb:nameXmlTransform>
                <jaxb:elementName suffix="Elem"/>
            </jaxb:nameXmlTransform>
        </jaxb:schemaBindings>
    </jaxws:bindings>
</jaxws:bindings>

您的maven应该使用以下插件

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <bindingFiles>
         <bindingFile>${basedir}/WebContent/resources/bindings.xjb</bindingFile>
        </bindingFiles>
        <wsdlUrls>
            <wsdlUrl>http://www5v80.elsyarres.net/service.asmx?wsdl</wsdlUrl>
        </wsdlUrls>
        <vmArgs>
            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
        </vmArgs>
    </configuration>
</plugin>

org.codehaus.mojo
jaxws-maven插件
2.4.1
wsimport
${basedir}/WebContent/resources/bindings.xjb
http://www5v80.elsyarres.net/service.asmx?wsdl
-Djavax.xml.accessExternalSchema=all

确保使用
SearchFlightsElem
进行请求,使用
SearchFlightsResponseElem
进行响应。

。使用我告诉过你的另一个maven插件。@Jah你是说org.codehaus.mojo:jaxws maven插件?我很困惑,是的。详见
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="http://www5v80.elsyarres.net/service.asmx?wsdl"
            xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='ElsyArres.API']">
        <jaxb:schemaBindings>
            <jaxb:nameXmlTransform>
                <jaxb:elementName suffix="Elem"/>
            </jaxb:nameXmlTransform>
        </jaxb:schemaBindings>
    </jaxws:bindings>
</jaxws:bindings>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <bindingFiles>
         <bindingFile>${basedir}/WebContent/resources/bindings.xjb</bindingFile>
        </bindingFiles>
        <wsdlUrls>
            <wsdlUrl>http://www5v80.elsyarres.net/service.asmx?wsdl</wsdlUrl>
        </wsdlUrls>
        <vmArgs>
            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
        </vmArgs>
    </configuration>
</plugin>