Skip to main content

Marshal problem - Namespace for prefix 'ns2' has not been declared

6 replies [Last post]
joginek
Offline
Joined: 2008-09-17

Hi,

I have problem with marshaling, and hope you can help. I generated ws client using jaxws-maven-plugin and wsimport goal. I wrote test class for it and during call to service I got exception listed below. While debugging I have noticed that class:
com.sun.org.apache.xerces.internal.dom.NodeImpl always return null for method getPrefix or getNamespaceURI (especially for Elements and Attributes - maybe there is problem?) and that results in empty NamespaceMappings object in parse() method of DOM2TO and consequently to this exception. What I do wrong? Is there a way of replacing this NodeImpl implementation?

JDK 1.5.0_14
jaxws 2.1.4, jaxb-impl 2.1.7, jaxb-api 2.1

Marshaled object is of type org.w3c.dom.Node and is created in a standard way:
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("a.xml").getDocumentElement().cloneNode(true);

a.xml:

<?xml version="1.0" encoding="UTF-8"?>

00000000000000000

response

exception:
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'ns2' has not been declared.]
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:322)
at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:258)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:153)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
at com.sun.xml.ws.client.Stub.process(Stub.java:222)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:135)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:109)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
at $Proxy31.sign(Unknown Source)
at ServiceTest.signTest(ServiceTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'ns2' has not been declared.]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:282)
at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:100)
at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:141)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:315)
... 34 more
Caused by: javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'ns2' has not been declared.
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:242)
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:257)
at com.sun.xml.bind.v2.runtime.XMLSerializer.writeDom(XMLSerializer.java:792)
at com.sun.xml.bind.v2.runtime.AnyTypeBeanInfo.serializeBody(AnyTypeBeanInfo.java:111)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:277)
... 37 more
Caused by: javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'ns2' has not been declared.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:670)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:300)
at com.sun.xml.bind.v2.runtime.XMLSerializer.writeDom(XMLSerializer.java:790)
... 43 more
Caused by: java.lang.RuntimeException: Namespace for prefix 'ns2' has not been declared.
at com.sun.org.apache.xml.internal.serializer.SerializerBase.getNamespaceURI(SerializerBase.java:874)
at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:198)
at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.characters(ToXMLSAXHandler.java:524)
at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.characters(ToXMLSAXHandler.java:467)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:229)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:215)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:81)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:615)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:661)
... 45 more

thanks for any help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Clive Brettingham-Moore

Just a stab in the dark, if you are using a DocumentBuilder to parse XML
with namespaces it is usually a good idea to make sure it is namespace
aware:
.setNamespaceAware(true) on the DocumentBuilderFactory before creating
the document builder.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net

joginek
Offline
Joined: 2008-09-17

Yes yes yes, forgot to set this - thanks very much

crabi_77
Offline
Joined: 2006-05-05

Hi
I am using
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);

how will i remove ns2, please send me some example

ramapulavarthi
Offline
Joined: 2004-06-01

There are some related bugs fixed in latest builds.
Can you try with latest Metro 1.4 nightly build from https://metro.dev.java.net/servlets/ProjectDocumentList?folderID=9700&ex... and see if this still happens.

If it does, please file an issue with a testcase at https://jax-ws.dev.java.net/servlets/ProjectIssues

ramapulavarthi
Offline
Joined: 2004-06-01
joginek
Offline
Joined: 2008-09-17

Thanks for answers,

I tryied both releases without success. I'll try tomorrow older then 2.1.3 (the same exception) releases