javax.xml.ws.soap.SOAPFaultException: 解组错误
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error
我在从 Web 服务调用服务时遇到问题。
我无法弄清楚我收到的以下解组错误。请帮忙。我查看了已通过的帖子,但我不知道发生了什么,因为错误描述非常笼统。
要从 WSDL 生成 Java 客户端代码,我使用:
wsimport -b binding.xml service.wsdl
其中 binding.xml 是:
<bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="http://localhost:8080/services/service?wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<!-- Disable default wrapper style -->
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
(不幸的是,由于消息正文大小的限制,我无法附加我的 WSDL)
因此,在生成客户端并实现对服务的调用后,我收到了以下错误消息:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error:
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
at com.sun.proxy.$Proxy151.protocolInsert(Unknown Source)
...
这里有一段代码:
import javax.xml.ws.BindingProvider;
//other import
public class ProtocolHandler{
....
private ProtocolloServicePortType initServiceProtocol() throws Exception
{
// Init client WS
ProtocolloService invoiceProcolWs = new ProtocolloService();
ProtocolloServicePortType port = invoiceProcolWs.getProtocollo();
BindingProvider bp = (BindingProvider) port;
// Setting endopoint
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getUrl());
return port;
}
private void createProtocol(){
try{
//Initialize service
ProtocolloServicePortType protocolService = initServiceProtocol();
//Create a request
ProtocolInsertRequest request = prepareRequest();
//Call the method service protocolInsert
ProtocolResponse response = protocolService.protocolInsert(request);
}catch(Exception e){
//manage Exception
}
}
}
我使用 JDK 1.7.0_25, Eclipse Jee Neon.
我的项目使用了多个库:这些错误可能与不兼容问题有关吗?
有jaxbw-plugin-1.0.jar、jaxb-xjc-2.0.jar、jaxb-impl-2.0.jar、jaxb-api -2.0.jar,javaee-api-6.0.jar.
2018 年 10 月 18 日更新
我发现了问题。使用 SOAPHandler,我注意到在我的请求中缺少日期值,而在我对它们进行赋值时(调试时我看到我的请求对每个日期都进行了赋值)。
<ns5:protocolInsert xmlns="http://insielmercato.it/protocollo-ws/data/common" xmlns:ns2="http://insielmercato.it/protocollo-ws/data/anagrafic" xmlns:ns3="http://insielmercato.it/protocollo-ws/data/filing" xmlns:ns4="http://insielmercato.it/protocollo-ws/data/protocol" xmlns:ns5="http://insielmercato.it/protocollo-ws/services/protocolloService">
<ns4:user>
<code>USER</code>
<password>PSWD</password>
</ns4:user>
<ns4:operatingOfficeCode>OFFICE</ns4:operatingOfficeCode>
<ns4:officeCode>GEN</ns4:officeCode>
<ns4:registerCode>GEN</ns4:registerCode>
<ns4:direction>A</ns4:direction>
<ns4:sequenceCode>SEQUENCE</ns4:sequenceCode>
<ns4:subjectDocument>Test protocollazione notifica fattura passiva</ns4:subjectDocument>
<ns4:subjectProtocol>PROTOCOLLAZIONE DOC. PROVA000002</ns4:subjectProtocol>
<ns4:receptionSendingDate/>
<ns4:documentDetails>
<number>PROVA000002</number>
<date/>
<year>2018</year>
<documentTypeCode>FAT</documentTypeCode>
</ns4:documentDetails>
<ns4:senderList>
<ns4:sender>
<code>SENDER</code>
</ns4:sender>
</ns4:senderList>
如您所见,标签 <ns4:receptionSendingDate/>
和 <date/>
(在 <ns4:documentDetails>
内)为空,但我在我的方法中对它们进行了赋值。
从我的请求中删除此标签调用服务它正常运行而没有解组错误。
这怎么可能?
非常感谢您的关注。
我找到了问题的根源。
再次调试我注意到我的 XMLGregorianCalendar 将小时、分钟、秒和时区设置为 -2147483648,因为我的项目中包含的库 Utils 以这种方式设置 XMLGregorianCalendar:
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH)+1,
cal.get(Calendar.DAY_OF_MONTH),
DatatypeConstants.FIELD_UNDEFINED);
所以首先我在
中改变了这个方法
XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
其次我 "scolded" 制作了这个 XD。
我的问题已经解决了
我在从 Web 服务调用服务时遇到问题。 我无法弄清楚我收到的以下解组错误。请帮忙。我查看了已通过的帖子,但我不知道发生了什么,因为错误描述非常笼统。
要从 WSDL 生成 Java 客户端代码,我使用: wsimport -b binding.xml service.wsdl
其中 binding.xml 是:
<bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="http://localhost:8080/services/service?wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<!-- Disable default wrapper style -->
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
(不幸的是,由于消息正文大小的限制,我无法附加我的 WSDL)
因此,在生成客户端并实现对服务的调用后,我收到了以下错误消息:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error:
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
at com.sun.proxy.$Proxy151.protocolInsert(Unknown Source)
...
这里有一段代码:
import javax.xml.ws.BindingProvider;
//other import
public class ProtocolHandler{
....
private ProtocolloServicePortType initServiceProtocol() throws Exception
{
// Init client WS
ProtocolloService invoiceProcolWs = new ProtocolloService();
ProtocolloServicePortType port = invoiceProcolWs.getProtocollo();
BindingProvider bp = (BindingProvider) port;
// Setting endopoint
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getUrl());
return port;
}
private void createProtocol(){
try{
//Initialize service
ProtocolloServicePortType protocolService = initServiceProtocol();
//Create a request
ProtocolInsertRequest request = prepareRequest();
//Call the method service protocolInsert
ProtocolResponse response = protocolService.protocolInsert(request);
}catch(Exception e){
//manage Exception
}
}
}
我使用 JDK 1.7.0_25, Eclipse Jee Neon.
我的项目使用了多个库:这些错误可能与不兼容问题有关吗?
有jaxbw-plugin-1.0.jar、jaxb-xjc-2.0.jar、jaxb-impl-2.0.jar、jaxb-api -2.0.jar,javaee-api-6.0.jar.
2018 年 10 月 18 日更新
我发现了问题。使用 SOAPHandler,我注意到在我的请求中缺少日期值,而在我对它们进行赋值时(调试时我看到我的请求对每个日期都进行了赋值)。
<ns5:protocolInsert xmlns="http://insielmercato.it/protocollo-ws/data/common" xmlns:ns2="http://insielmercato.it/protocollo-ws/data/anagrafic" xmlns:ns3="http://insielmercato.it/protocollo-ws/data/filing" xmlns:ns4="http://insielmercato.it/protocollo-ws/data/protocol" xmlns:ns5="http://insielmercato.it/protocollo-ws/services/protocolloService">
<ns4:user>
<code>USER</code>
<password>PSWD</password>
</ns4:user>
<ns4:operatingOfficeCode>OFFICE</ns4:operatingOfficeCode>
<ns4:officeCode>GEN</ns4:officeCode>
<ns4:registerCode>GEN</ns4:registerCode>
<ns4:direction>A</ns4:direction>
<ns4:sequenceCode>SEQUENCE</ns4:sequenceCode>
<ns4:subjectDocument>Test protocollazione notifica fattura passiva</ns4:subjectDocument>
<ns4:subjectProtocol>PROTOCOLLAZIONE DOC. PROVA000002</ns4:subjectProtocol>
<ns4:receptionSendingDate/>
<ns4:documentDetails>
<number>PROVA000002</number>
<date/>
<year>2018</year>
<documentTypeCode>FAT</documentTypeCode>
</ns4:documentDetails>
<ns4:senderList>
<ns4:sender>
<code>SENDER</code>
</ns4:sender>
</ns4:senderList>
如您所见,标签 <ns4:receptionSendingDate/>
和 <date/>
(在 <ns4:documentDetails>
内)为空,但我在我的方法中对它们进行了赋值。
从我的请求中删除此标签调用服务它正常运行而没有解组错误。
这怎么可能?
非常感谢您的关注。
我找到了问题的根源。
再次调试我注意到我的 XMLGregorianCalendar 将小时、分钟、秒和时区设置为 -2147483648,因为我的项目中包含的库 Utils 以这种方式设置 XMLGregorianCalendar:
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH)+1,
cal.get(Calendar.DAY_OF_MONTH),
DatatypeConstants.FIELD_UNDEFINED);
所以首先我在
中改变了这个方法XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
其次我 "scolded" 制作了这个 XD。
我的问题已经解决了