[英]Local part cannot be "null" when creating a QName
We are trying to track down a bug.我们正试图追踪一个错误。 We get the above error in the logs.
我们在日志中收到上述错误。
Can anyone explain what this message means?任何人都可以解释此消息的含义吗? Are there any typical reasons for getting this message?
收到此消息有任何典型原因吗?
The stacktrace is:堆栈跟踪是:
org.apache.axiom.om.OMException: java.lang.IllegalArgumentException: local part cannot be "null" when creating a QName
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:206)
at org.apache.axiom.om.impl.llom.OMNodeImpl.build(OMNodeImpl.java:318)
at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:618)
at org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.toOM(SAAJConverterImpl.java:147)
at org.apache.axis2.jaxws.message.impl.XMLPartImpl._convertSE2OM(XMLPartImpl.java:77)
at org.apache.axis2.jaxws.message.impl.XMLPartBase.getContentAsOMElement(XMLPartBase.java:203)
at org.apache.axis2.jaxws.message.impl.XMLPartBase.getAsOMElement(XMLPartBase.java:255)
at org.apache.axis2.jaxws.message.impl.MessageImpl.getAsOMElement(MessageImpl.java:464)
at org.apache.axis2.jaxws.message.util.MessageUtils.putMessageOnMessageContext(MessageUtils.java:202)
at org.apache.axis2.jaxws.core.controller.AxisInvocationController.prepareRequest(AxisInvocationController.java:370)
at org.apache.axis2.jaxws.core.controller.InvocationController.invoke(InvocationController.java:120)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:317)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:148)
I got the same error message (local part cannot be "null" when creating a QName) while trying to construct a org.w3c.dom.Document from String. 尝试从String构造org.w3c.dom.Document时,出现了相同的错误消息(创建QName时本地部分不能为“ null”)。 The problem went away after calling setNamespaceAware(true) on DocumentBuilderFactory.
在DocumentBuilderFactory上调用setNamespaceAware(true)后,问题消失了。 Working code snippet is given below.
工作代码段如下所示。
private static Document getDocumentFromString(final String xmlContent)
throws Exception
{
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
try
{
return documentBuilderFactory
.newDocumentBuilder()
.parse(new InputSource(new StringReader(xmlContent)));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
It means you are creating a DOM element or attribute using one of the namespace methods like createElementNS
thus 这意味着您正在使用诸如
createElementNS
之类的名称空间方法之一来创建DOM元素或属性,因此
document.createElementNS(namespace, null)
or createElementNS
or setAttrbuteNS
and the second argument, the qname is null
, or includes a prefix but no local part as in "foo:"
. 或
createElementNS
或setAttrbuteNS
以及第二个参数qname为null
,或包含前缀但不包含本地部分,如"foo:"
。
EDIT: 编辑:
I would try to run the XML it's parsing through a validator. 我会尝试运行通过验证器解析的XML。 It's likely there's some tag or attribute name like
foo:
or foo:bar:baz
that is a valid XML identifier but invalid according to the additional restrictions introduced by XML namespaces. 可能有一些标记或属性名称,例如
foo:
或foo:bar:baz
,它是有效的XML标识符,但根据XML名称空间引入的其他限制,它们是无效的。
After whole hours in searching, I just wanted to share the Answer in this thread helped me with a Talend code migration - involving SOAP messages - from java8 to java11.经过几个小时的搜索,我只想分享这个线程中的答案帮助我进行了 Talend 代码迁移——涉及 SOAP 条消息——从 java8 到 java11。
// Used libraries
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.SOAPBody;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
...
// This is the node I want to replace: "<DataArea><Contact/></DataArea>"
// <SOAP-ENV:Body> > SOAP Action (e.g. <ns:GetContact>) > <GetContactRequest> > <DataArea>
SOAPBody soapBodyRequest = objSOAPMessage.getSOAPPart().getEnvelope().getBody();
Node nodeDataArea = soapBodyRequest.getFirstChild().getFirstChild().getFirstChild();
// Build a valid Node object starting from a string e.g. "<Contact> etc etc nested-etc </Contact>"
DocumentBuilderFactory objDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
// As per java11, this is essential. It forces the Factory to consider the ':' as a namespace separator rather than part of a tag.
objDocumentBuilderFactory.setNamespaceAware(true);
// Create the node to replace "<DataArea><Contact/></DataArea>" with "<DataArea><Contact>content and nested tags</Contact></DataArea>"
Node nodeParsedFromString = objDocumentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(strDataArea.getBytes())).getDocumentElement();
// Import the newly parsed Node object in the request envelop being built and replace the existing node.
nodeDataArea.replaceChild(
/*newChild*/nodeDataArea.getOwnerDocument().importNode(nodeParsedFromString, true),
/*oldChild*/nodeDataArea.getFirstChild()
);
This throws the Local part cannot be "null" when creating a QName exception if you don't put the .setNamespaceAware(true)
instruction如果您不放置
.setNamespaceAware(true)
指令,则在创建 QName 异常时抛出 Local 部分不能为“null”
Although this is an old thread, I hope this answer would help some one else searching this error. 尽管这是一个旧线程,但我希望这个答案可以帮助其他人搜索此错误。 I have faced the same error when I was trying to build a web app using maven-enunciate-cxf-plugin:1.28.
当我尝试使用maven-enunciate-cxf-plugin:1.28构建Web应用程序时,遇到了相同的错误。
For me this was caused after I added a checked exception to my web service signature: 对我来说,这是在我向Web服务签名中添加了检查的异常后引起的:
@WebMethod(operationName = "enquirySth")
public IBANResponse enquirySth(String input) throws I
InvalidInputException { ...
I have used JAX-WS Spec for exception throwing but no success. 我已经使用JAX-WS Spec进行异常抛出,但是没有成功。 At the end I have found this issue in Enunciate issue tracker system which indicates this issue is resolved in current version, but I think it still exist.
最后,我在Enunciate问题跟踪器系统中发现了此问题 ,这表明此问题已在当前版本中解决,但我认为它仍然存在。
Finally I have done following workaround to fix my problem: adding @XmlRootElement to my FaultBean. 最终,我完成了以下变通办法来解决我的问题:将@XmlRootElement添加到我的FaultBean中。
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FaultBean",propOrder = {"errorDescription", "errorCode"})
public class FaultBean implements Serializable {
@XmlElement(required = true, nillable = true)
protected String errorDescription;
@XmlElement(required = true, nillable = true)
protected String errorCode;
public FaultBean() {
}
public String getErrorDescription() {
return this.errorDescription;
}
public void setErrorDescription(String var1) {
this.errorDescription = var1;
}
public String getErrorCode() {
return this.errorCode;
}
public void setErrorCode(String var1) {
this.errorCode = var1;
}
}
That's it. 而已。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.