You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by bhaskerhari <bh...@yahoo.com> on 2013/08/16 15:28:35 UTC

Namespace prefix ns1 is missing in cxf soap response

We just migrated to CXF 2.7.5 from CXF 2.2 and the new SOAP response has ns2
as prefix in the response wrapper. This is causing an error at our clients
end. 

Jus tried deploying a sample cxf service and there also, I see the prefix as
ns2 instead of ns1. Any idea how i can get control over the namespace
prefixes? I am using JDK6.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:sayHiToUserResponse xmlns:ns2="http://server.hw.demo/">
         <return>Hello ?</return>
      </ns2:sayHiToUserResponse>
   </soap:Body>
</soap:Envelope>



--
View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Namespace prefix ns1 is missing in cxf soap response

Posted by Aki Yoshida <el...@gmail.com>.
regarding your mentioning of the outTransform not working, could it be
that there is a space in front of the HelloMessage in the value
attribute of your configuration? Your posted message includes the
space and that will be definitely raising an exception. Make sure that
the value attribute is correctly set to
"{http://test.ws.com/}HelloWorld".

I mentioned of the transform based workaround because I replied to
another message asking for the transform feature today and somehow my
mind was set to the transform feature. But as Dan mentioned, if you
could correct the serialization at the source, that would be a better
solution. (I mean the correct in compared to the above workaround
using the transform feature).

regards, aki

2013/8/19 bhaskerhari <bh...@yahoo.com>:
> I am already using the transformfeature inTransformElements. But for
> outTransformElements, it did not work. So when I gave the below entry, it
> still produces <HelloMessage>Hello.</HelloMessage> instead of
> <ns2:HelloMessage xmlns:ns2="http://test.ws.com/">Hello.</HelloMessage>
>
> <property name="outTransformElements">
>     <map>
>       <entry key="HelloMessage" value="{http://test.ws.com/} HelloMessage"/>
>     </map>
>   </property>
>
>
> And adding package-info.java also does not produce the desired response. If
> I specify namespace as well to the package-info.java, then it would add an
> extra namespace to the response wrapper instead of the xmlrootelement.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560p5732669.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Namespace prefix ns1 is missing in cxf soap response

Posted by bhaskerhari <bh...@yahoo.com>.
I am already using the transformfeature inTransformElements. But for
outTransformElements, it did not work. So when I gave the below entry, it
still produces <HelloMessage>Hello.</HelloMessage> instead of
<ns2:HelloMessage xmlns:ns2="http://test.ws.com/">Hello.</HelloMessage>

<property name="outTransformElements">
    <map>
      <entry key="HelloMessage" value="{http://test.ws.com/} HelloMessage"/>
    </map>
  </property>


And adding package-info.java also does not produce the desired response. If
I specify namespace as well to the package-info.java, then it would add an
extra namespace to the response wrapper instead of the xmlrootelement.



--
View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560p5732669.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Namespace prefix ns1 is missing in cxf soap response

Posted by Aki Yoshida <el...@gmail.com>.
if you want to promote the non-namespaced HelloWorld to the namespaced
{http://test.ws.com/}HelloWorld element, you can use the transform
feature.
http://cxf.apache.org/docs/transformationfeature.html#TransformationFeature-Changinginputandoutputelementnamesandnamespaces

<!-- qualify "HelloWorld" with "http://test.ws.com/" -->
      <entry key="HelloWorld" value="{http://test.ws.com/}HelloWorld"/>


2013/8/19 bhaskerhari <bh...@yahoo.com>:
> Thanks for the reply, I got this sorted out by adding package-info.java to
> the package, but i am facing a new problem now. I dont get namespace in the
> XMLRootElement. Though I am specifying the namespace to the XMLRootElement
> for which I want to see the namespace, it appears in the Response wrapper
> element instead of the XML element i added.
>
> So the response I get is
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>    <soap:Body>
>       <ns2: getMessageResponse xmlns:ns2="http://test.ws.com/">
>          <HelloMessage>Hello.</HelloMessage>
>       </ns2:getMessageResponse>
>    </soap:Body>
> </soap:Envelope>
>
> But the response I need is
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>    <soap:Body>
>       <ns1:getMessageResponse xmlns:ns1="http://test.ws.com/">
>          <ns2:HelloMessage
> xmlns:ns2="http://test.ws.com/">Hello.</HelloMessage>
>       </ns2:getMessageResponse>
>    </soap:Body>
> </soap:Envelope>
>
> How can I get a namespace added to the XMLRootElement? I tried several
> options, but it keeps adding the namespace to the response wrapper
> (getMessageResponse in this case) instead of getMessageResponse.
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560p5732654.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Namespace prefix ns1 is missing in cxf soap response

Posted by Daniel Kulp <dk...@apache.org>.
On Aug 19, 2013, at 8:25 AM, bhaskerhari <bh...@yahoo.com> wrote:

> Thanks for the reply, I got this sorted out by adding package-info.java to
> the package, but i am facing a new problem now. I dont get namespace in the
> XMLRootElement. Though I am specifying the namespace to the XMLRootElement
> for which I want to see the namespace, it appears in the Response wrapper
> element instead of the XML element i added.

In the package-info.java, you could try adding:

@javax.xml.bind.annotation.XmlSchema(namespace = ".…...",
                                     elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)

To force the child elements to be qualified.   Alternatively, if using Java7/JAXB2.2, you can add @XmlElement(namespace="…..") attributes to the parameters on the service.


Dan


> 
> So the response I get is 
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>   <soap:Body>
>      <ns2: getMessageResponse xmlns:ns2="http://test.ws.com/">
>         <HelloMessage>Hello.</HelloMessage>
>      </ns2:getMessageResponse>
>   </soap:Body>
> </soap:Envelope>
> 
> But the response I need is 
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>   <soap:Body>
>      <ns1:getMessageResponse xmlns:ns1="http://test.ws.com/">
>         <ns2:HelloMessage
> xmlns:ns2="http://test.ws.com/">Hello.</HelloMessage>
>      </ns2:getMessageResponse>
>   </soap:Body>
> </soap:Envelope>
> 
> How can I get a namespace added to the XMLRootElement? I tried several
> options, but it keeps adding the namespace to the response wrapper
> (getMessageResponse in this case) instead of getMessageResponse.
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560p5732654.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Namespace prefix ns1 is missing in cxf soap response

Posted by bhaskerhari <bh...@yahoo.com>.
Thanks for the reply, I got this sorted out by adding package-info.java to
the package, but i am facing a new problem now. I dont get namespace in the
XMLRootElement. Though I am specifying the namespace to the XMLRootElement
for which I want to see the namespace, it appears in the Response wrapper
element instead of the XML element i added.

So the response I get is 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2: getMessageResponse xmlns:ns2="http://test.ws.com/">
         <HelloMessage>Hello.</HelloMessage>
      </ns2:getMessageResponse>
   </soap:Body>
</soap:Envelope>

But the response I need is 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns1:getMessageResponse xmlns:ns1="http://test.ws.com/">
         <ns2:HelloMessage
xmlns:ns2="http://test.ws.com/">Hello.</HelloMessage>
      </ns2:getMessageResponse>
   </soap:Body>
</soap:Envelope>

How can I get a namespace added to the XMLRootElement? I tried several
options, but it keeps adding the namespace to the response wrapper
(getMessageResponse in this case) instead of getMessageResponse.




--
View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560p5732654.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Namespace prefix ns1 is missing in cxf soap response

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

Your client is a little bit weird as the soap message with ns2 prefix is totally valid.

Anyway, you can specify a soap.env.ns.map property for cxf server which is a map for the prefix--namespace where you can specify the prefix you want.
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: @Freeman小屋



On 2013-8-16, at 下午9:28, bhaskerhari wrote:

> We just migrated to CXF 2.7.5 from CXF 2.2 and the new SOAP response has ns2
> as prefix in the response wrapper. This is causing an error at our clients
> end. 
> 
> Jus tried deploying a sample cxf service and there also, I see the prefix as
> ns2 instead of ns1. Any idea how i can get control over the namespace
> prefixes? I am using JDK6.
> 
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
>   <soap:Body>
>      <ns2:sayHiToUserResponse xmlns:ns2="http://server.hw.demo/">
>         <return>Hello ?</return>
>      </ns2:sayHiToUserResponse>
>   </soap:Body>
> </soap:Envelope>
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: Namespace prefix ns1 is missing in cxf soap response

Posted by "oleg.efrem" <ol...@yahoo.com>.
I assume you have control over the WS Server Side as well, if you do and you
just want ns2 to be replaced with ns1 in your case you need to put this in
your applicationContext.xml: 

    <jaxws:endpoint
            ...>
        <jaxws:dataBinding>
            <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
                <property name="namespaceMap">
                    <map>
                        <entry>
                            <key><value>http://test.ws.com/</value></key>
                            <value>ns1</value>
                        </entry>
                    </map>
                </property>
            </bean>
        </jaxws:dataBinding>
    </jaxws:endpoint>

But as Freeman mentioned your client is a bit weird, since any name space
prefixes are valid as long as they are mapped:
xmlns:ns2="http://test.ws.com/" in the envelope or are part of node's
attibute, in your case: <ns2:getMessageResponse
xmlns:ns2="http://test.ws.com/">. So your client shouldn't have any problem
in resolving ns2. NS1, NS2 are just short notations for the full namespace
added by JAXB in order not to use the full namespace allover the places
where namespace reference is needed. 
This being said, you'd probably want instead of tweaking the Web Service
Server side solve problem with your client, otherwise you might end up
fixing problems for one "weird" client and break things for many other
properly implemented clients using same Web Service Server. 



--
View this message in context: http://cxf.547215.n5.nabble.com/Namespace-prefix-ns1-is-missing-in-cxf-soap-response-tp5732560p5737112.html
Sent from the cxf-user mailing list archive at Nabble.com.