我正在尝试使用Apache CXF调用网络服务。
我从位于here的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>
* <complexType name="KomunikatZBMT">
* <complexContent>
* <extension base="{http://csioz.gov.pl/zsmopl/mt/}KomunikatMT">
* <sequence>
* <element name="idMPDPodmiotuRaportujacego" type="{http://csioz.gov.pl/zsmopl/mt/}IdentyfikatorMPDPodmiotuMT"/>
* <element name="komunikatTransakcja" type="{http://csioz.gov.pl/zsmopl/mt/}KomunikatTransakcjaZBMT" maxOccurs="unbounded"/>
* </sequence>
* </extension>
* </complexContent>
* </complexType>
* </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;
}
}
您知道导致此异常的原因是什么吗?