java 创建 QName 时本地部分不能为“null”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10312514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Local part cannot be "null" when creating a QName
提问by Shiraz Bhaiji
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)
回答by Unnikrishnan Valsalan
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. The problem went away after calling setNamespaceAware(true) on DocumentBuilderFactory. Working code snippet is given below.
在尝试从字符串构造 org.w3c.dom.Document 时,我收到了相同的错误消息(创建 QName 时本地部分不能为“null”)。在 DocumentBuilderFactory 上调用 setNamespaceAware(true) 后问题就消失了。下面给出了工作代码片段。
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);
}
}
回答by Mike Samuel
It means you are creating a DOM element or attribute using one of the namespace methods like createElementNS
thus
这意味着要创建方法喜欢的名称空间的DOM元素或属性使用一个createElementNS
这样
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:"
.
or createElementNS
orsetAttrbuteNS
和第二个参数,qname is null
, or 包括一个前缀但没有像 in 那样的本地部分"foo:"
。
EDIT:
编辑:
I would try to run the XML it's parsing through a validator. 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.
我会尝试运行它通过验证器解析的 XML。根据 XML 名称空间引入的附加限制,很可能存在一些标签或属性名称,例如foo:
或者foo:bar:baz
是有效的 XML 标识符但无效。
回答by Kayvan Tehrani
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 Specfor exception throwing but no success. At the end I have found this issuein Enunciate issue tracker system which indicates this issue is resolved in current version, but I think it still exist.
我已经使用JAX-WS Spec进行异常抛出但没有成功。最后我在 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.
而已。希望能帮助到你。