gpt4 book ai didi

从 SOAPFault 中提取错误消息时出现 java.lang.ClassCastException

转载 作者:太空宇宙 更新时间:2023-11-04 14:07:21 24 4
gpt4 key购买 nike

我正在尝试提取 Web 服务的soapFault 响应的错误代码和错误消息,但收到 ClasscasrException :

下面是网络服务响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:com="http://com.amdocs.bss.bsl/" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<bsl:BSLResponseHeader xmlns:bsl="http://com.amdocs.bss.bsl/">
<ResponseTimestamp>2015-02-24T11:34:03.419+01:00</ResponseTimestamp>
<MessageID>1234</MessageID>
<BSLServiceOperation>getTariffAndAddOns getTariffAndAddOns</BSLServiceOperation>
</bsl:BSLResponseHeader>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>BSL exception</faultstring>
<detail xmlns:com="http://com.amdocs.bss.bsl/" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<bsl:error xmlns:bsl="http://com.amdocs.bss.bsl/">
<errorCode>BSL-14004</errorCode>
<errorMessage>OMS login failure: Problem in OMS UAMS login -
Nested Exception/Error:
java.net.ConnectException: Tried all: '1' addresses, but could not connect over HTTP to server: '195.233.102.177', port: '40123'
</errorMessage>
<detail>
<ImplRetrieveCustomerAssignedProductRestOutput>
<transactionId>1424678882788</transactionId>
<?xml-multiple errorInfo?>
<errorInfo>
<errorCode>14004</errorCode>
<errorMessage>OMS login failure: Problem in OMS UAMS login -
Nested Exception/Error:
java.net.ConnectException: Tried all: '1' addresses, but could not connect over HTTP to server: '195.233.102.177', port: '40123'
</errorMessage>
<sourceSystem>MCSS</sourceSystem>
</errorInfo>
</ImplRetrieveCustomerAssignedProductRestOutput>
<httpstatusCode>500</httpstatusCode>
</detail>
</bsl:error>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

Blow 是要处理的代码:

catch (SOAPFaultException e) {


SOAPFault fault=e.getFault();
Detail soapfaultdeDetail= fault.getDetail();
Iterator detailEntries = soapfaultdeDetail.getDetailEntries();
System.out.println("kk");
while(detailEntries.hasNext()){
DetailEntry newEntry = (DetailEntry)detailEntries.next();
if( newEntry!=null ){
final Iterator childElementsIter = newEntry.getChildElements();
while ( childElementsIter.hasNext() ) {


final SOAPElement soapElement = (SOAPElement) childElementsIter.next();
if(soapElement.getElementName().getQualifiedName()!=null && soapElement.getElementName().getQualifiedName().equalsIgnoreCase("errorMessage") ){
String name=soapElement.getElementName().getQualifiedName();
String value = soapElement.getValue();
System.out.println(name +" : "+value);
} else if(soapElement.getElementName().getQualifiedName()!=null && soapElement.getElementName().getQualifiedName().equalsIgnoreCase("errorcode")){
String name=soapElement.getElementName().getQualifiedName();
String value = soapElement.getValue();
System.out.println(name +" : "+value);
}

}
}

}
}

下面是输出:

错误代码:BSL-14004errorMessage:OMS 登录失败:OMS UAMS 登录出现问题 -嵌套异常/错误:java.net.ConnectException:尝试了所有:“1”地址,但无法通过 HTTP 连接到服务器:“195.233.102.177”,端口:“40123”

线程“主线程”java.lang.ClassCastException 中出现异常:com.sun.xml.internal.messaging.saaj.soap.impl.TextImpl 在 msisdn.getTariffsAndAddOns(msisdn.java:155) 在 msisdn.main(msisdn.java:181)

final SOAPElement SoapElement = (SOAPElement) childElementsIter.next(); (这是第 155 行

从错误位置来看,前两个条件已成功执行,但第三次执行时抛出异常。有人可以建议我应该做什么来避免这种情况吗?

最佳答案

您确定前两次您获得的是 TextImpl.显然,它失败了,因为它试图将 TextImpl 类型转换为 SoapElement。如果您只期望 SoapElement 类型,那么也许您可以检查

if (childElementIter.next() instanceof SoapElement) 
{
// business logic
}

关于从 SOAPFault 中提取错误消息时出现 java.lang.ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28713336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com