我正在尝试使用Apache CXF调用Web服务。
我从位于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;
}
}
您知道导致此异常的原因吗?
1条答案
按热度按时间kmbjn2e31#
也许这对其他人有帮助:我还收到错误消息
或者用德语说:
我没有改变任何东西,之前的请求得到了回答,没有任何问题,直到错误发生。
最后的原因是,服务器不可用,并返回了一个内部服务器错误(500)响应和一个HTML错误消息。如果您想查看HTTP错误,可以通过在代码中设置以下系统属性来打开HTTP日志: