CXF客户端 - 意外的XML标签。期望:{http://schemas.xmlsoap.org/soap/envelope/}Envelope,但发现:{null}html。

4

我正在尝试使用Apache CXF调用webservice。

我从此处生成了与wsdl文件相关的java类。

以下是我的主方法:

public static void main(String[] args) throws Exception {
    ObslugaKomunikatowService service = new ObslugaKomunikatowService();
    ObslugaKomunikatow client = service.getObslugaKomunikatowPort();
    client.zapiszKomunikatZB(new KomunikatZBMT());
}

这段代码会导致以下异常:

Exception in thread "main" com.sun.xml.internal.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html
    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:304)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:268)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
    at com.sun.proxy.$Proxy34.zapiszKomunikatZB(Unknown Source)
    at pl.opencare.zsmoplclient.ZSMOPLClient.main(ZSMOPLClient.java:98)
Caused by: com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(XMLStreamReaderUtil.java:261)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:205)
    at com.oracle.webservices.internal.impl.encoding.StreamDecoderImpl.decode(StreamDecoderImpl.java:49)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:234)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:151)
    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:299)
    ... 15 more

这里生成了一个服务类:

package pl.gov.csioz.zsmopl.ws;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service;

/**
 * This class was generated by Apache CXF 3.2.5
 * 2018-07-11T11:38:29.954+02:00
 * Generated source version: 3.2.5
 *
 */
@WebServiceClient(name = "ObslugaKomunikatowService",
                  wsdlLocation = "file:ZSMOPL.wsdl",
                  targetNamespace = "http://csioz.gov.pl/zsmopl/ws/")
public class ObslugaKomunikatowService extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("http://csioz.gov.pl/zsmopl/ws/", "ObslugaKomunikatowService");
    public final static QName ObslugaKomunikatowPort = new QName("http://csioz.gov.pl/zsmopl/ws/", "ObslugaKomunikatowPort");
    static {
        URL url = null;
        try {
            url = new URL("file:ZSMOPL.wsdl");
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(ObslugaKomunikatowService.class.getName())
                .log(java.util.logging.Level.INFO,
                     "Can not initialize the default wsdl from {0}", "file:ZSMOPL.wsdl");
        }
        WSDL_LOCATION = url;
    }

    public ObslugaKomunikatowService(URL wsdlLocation) {
        super(wsdlLocation, SERVICE);
    }

    public ObslugaKomunikatowService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public ObslugaKomunikatowService() {
        super(WSDL_LOCATION, SERVICE);
    }

    public ObslugaKomunikatowService(WebServiceFeature ... features) {
        super(WSDL_LOCATION, SERVICE, features);
    }

    public ObslugaKomunikatowService(URL wsdlLocation, WebServiceFeature ... features) {
        super(wsdlLocation, SERVICE, features);
    }

    public ObslugaKomunikatowService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
        super(wsdlLocation, serviceName, features);
    }




    /**
     *
     * @return
     *     returns ObslugaKomunikatow
     */
    @WebEndpoint(name = "ObslugaKomunikatowPort")
    public ObslugaKomunikatow getObslugaKomunikatowPort() {
        return super.getPort(ObslugaKomunikatowPort, ObslugaKomunikatow.class);
    }

    /**
     *
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns ObslugaKomunikatow
     */
    @WebEndpoint(name = "ObslugaKomunikatowPort")
    public ObslugaKomunikatow getObslugaKomunikatowPort(WebServiceFeature... features) {
        return super.getPort(ObslugaKomunikatowPort, ObslugaKomunikatow.class, features);
    }

}
生成了端口类:
package pl.gov.csioz.zsmopl.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 3.2.5
 * 2018-07-11T11:38:29.942+02:00
 * Generated source version: 3.2.5
 *
 */
@WebService(targetNamespace = "http://csioz.gov.pl/zsmopl/ws/", name = "ObslugaKomunikatow")
@XmlSeeAlso({pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ObjectFactory.class, pl.gov.csioz.zsmopl.mt.ObjectFactory.class})
public interface ObslugaKomunikatow {

    @WebMethod(action = "zapiszKomunikatZB")
    @RequestWrapper(localName = "zapiszKomunikatZB", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatZB")
    @ResponseWrapper(localName = "zapiszKomunikatZBResponse", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatZBResponse")
    @WebResult(name = "identyfikatorKomunikatu", targetNamespace = "")
    public pl.gov.csioz.zsmopl.mt.IdentyfikatorKomunikatuMT zapiszKomunikatZB(
        @WebParam(name = "komunikatZB", targetNamespace = "")
        pl.gov.csioz.zsmopl.mt.KomunikatZBMT komunikatZB
    ) throws BladTworzeniaIdentyfikatoraKomunikatu, BladDostepnosci;

    @WebMethod(action = "zapiszKomunikatOS")
    @RequestWrapper(localName = "zapiszKomunikatOS", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatOS")
    @ResponseWrapper(localName = "zapiszKomunikatOSResponse", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatOSResponse")
    @WebResult(name = "identyfikatorKomunikatu", targetNamespace = "")
    public pl.gov.csioz.zsmopl.mt.IdentyfikatorKomunikatuMT zapiszKomunikatOS(
        @WebParam(name = "komunikatOS", targetNamespace = "")
        pl.gov.csioz.zsmopl.mt.KomunikatOSMT komunikatOS
    ) throws BladTworzeniaIdentyfikatoraKomunikatu, BladDostepnosci;

    @WebMethod(action = "zapiszKomunikatPD")
    @RequestWrapper(localName = "zapiszKomunikatPD", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatPD")
    @ResponseWrapper(localName = "zapiszKomunikatPDResponse", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatPDResponse")
    @WebResult(name = "identyfikatorKomunikatu", targetNamespace = "")
    public pl.gov.csioz.zsmopl.mt.IdentyfikatorKomunikatuMT zapiszKomunikatPD(
        @WebParam(name = "komunikatPD", targetNamespace = "")
        pl.gov.csioz.zsmopl.mt.KomunikatPDMT komunikatPD
    ) throws BladTworzeniaIdentyfikatoraKomunikatu, BladDostepnosci;
}

我将要发送的生成类:

package pl.gov.csioz.zsmopl.mt;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * Komunikat zg�oszenia brak�w.
 *             
 * 
 * <p>Java class for KomunikatZBMT complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="KomunikatZBMT"&gt;
 *   &lt;complexContent&gt;
 *     &lt;extension base="{http://csioz.gov.pl/zsmopl/mt/}KomunikatMT"&gt;
 *       &lt;sequence&gt;
 *         &lt;element name="idMPDPodmiotuRaportujacego" type="{http://csioz.gov.pl/zsmopl/mt/}IdentyfikatorMPDPodmiotuMT"/&gt;
 *         &lt;element name="komunikatTransakcja" type="{http://csioz.gov.pl/zsmopl/mt/}KomunikatTransakcjaZBMT" maxOccurs="unbounded"/&gt;
 *       &lt;/sequence&gt;
 *     &lt;/extension&gt;
 *   &lt;/complexContent&gt;
 * &lt;/complexType&gt;
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "KomunikatZBMT", propOrder = {
    "idMPDPodmiotuRaportujacego",
    "komunikatTransakcja"
})
public class KomunikatZBMT
    extends KomunikatMT
{

    @XmlElement(required = true)
    protected IdentyfikatorMPDPodmiotuMT idMPDPodmiotuRaportujacego;
    @XmlElement(required = true)
    protected List<KomunikatTransakcjaZBMT> komunikatTransakcja;

    /**
     * Gets the value of the idMPDPodmiotuRaportujacego property.
     * 
     * @return
     *     possible object is
     *     {@link IdentyfikatorMPDPodmiotuMT }
     *     
     */
    public IdentyfikatorMPDPodmiotuMT getIdMPDPodmiotuRaportujacego() {
        return idMPDPodmiotuRaportujacego;
    }

    /**
     * Sets the value of the idMPDPodmiotuRaportujacego property.
     * 
     * @param value
     *     allowed object is
     *     {@link IdentyfikatorMPDPodmiotuMT }
     *     
     */
    public void setIdMPDPodmiotuRaportujacego(IdentyfikatorMPDPodmiotuMT value) {
        this.idMPDPodmiotuRaportujacego = value;
    }

    /**
     * Gets the value of the komunikatTransakcja property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the komunikatTransakcja property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getKomunikatTransakcja().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link KomunikatTransakcjaZBMT }
     * 
     * 
     */
    public List<KomunikatTransakcjaZBMT> getKomunikatTransakcja() {
        if (komunikatTransakcja == null) {
            komunikatTransakcja = new ArrayList<KomunikatTransakcjaZBMT>();
        }
        return this.komunikatTransakcja;
    }

}

您知道是什么导致了这个异常吗?


你在这方面有任何进展吗? - Dmytro Chasovskyi
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
1
也许这能帮到其他人: 我也遇到了错误信息。
Exception in thread "main" com.sun.xml.internal.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html

或者用德语说:

Unerwartetes Tag. Erwartet: {http://schemas.xmlsoap.org/soap/envelope/}Envelope, gefunden: {null}html

在没有出现错误之前,我什么也没改变,并且请求已被回答。

最终发现问题是服务器不可用并返回500内部服务器错误响应和HTML错误消息。如果您想查看HTTP错误,可以通过在代码中设置此系统属性打开HTTP日志记录:

System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true")
    System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true")
    System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true")
    System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true")
    System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold", "999999")

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,