Quantcast

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

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

metro-3
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"?>
<ns2:a xmlns:ns1="http://www.a.a/ns1"
 xmlns:ns2="http://www.a.a/ns2"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.a.a/location">
    <ns2:Header>
        <ns1:MessageID>00000000000000000</ns1:MessageID>
    </ns2:Header>
    <ns2:Response  ID="1">response</ns2:Response>
</ns2:a>

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
[Message sent by forum member 'joginek' (joginek)]

http://forums.java.net/jive/thread.jspa?messageID=300205

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

metro-3
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&expandFolder=9700&folderID=9003 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
[Message sent by forum member 'ramapulavarthi' (ramapulavarthi)]

http://forums.java.net/jive/thread.jspa?messageID=300212

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

metro-3
Or try JAX-WS 2.1.5 latest nightly build at https://jax-ws.dev.java.net/servlets/ProjectDocumentList?folderID=6020
[Message sent by forum member 'ramapulavarthi' (ramapulavarthi)]

http://forums.java.net/jive/thread.jspa?messageID=300215

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

metro-3
Thanks for answers,

I tryied both releases without success. I'll try tomorrow older then 2.1.3 (the same exception) releases
[Message sent by forum member 'joginek' (joginek)]

http://forums.java.net/jive/thread.jspa?messageID=300218

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Clive Brettingham-Moore-3
In reply to this post by metro-3
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

metro-3
Yes yes yes, forgot to set this - thanks very much
[Message sent by forum member 'joginek' (joginek)]

http://forums.java.net/jive/thread.jspa?messageID=300313

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

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

how will i remove ns2, please send me some example
[Message sent by forum member 'crabi_77' (crabi_77)]

http://forums.java.net/jive/thread.jspa?messageID=316797

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...