You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Aki Yoshida <el...@googlemail.com> on 2012/03/05 18:07:56 UTC

Transform feature to preserve prefix values (Re: svn commit: r1295714

Hi Sergey, Dan,

We are currently not enforcing the namespace bindings to preserve the
namespace prefix values. For most applications, there is no need to
preserve the prefix values.  But I just noticed that if you have an
element value typed as QName,  you want to preserve its original
prefix value so that this QName value can be interpreted correctly by
the schema-aware binding framework.

For example, if you have an input XML:
<a:foo xmlns:a="urn:abc">
  <a2:bar xmlns:a2="urn:abc">a2:text</a2:bar>
</a:foo>
and suppose the content of element bar is of type QName.

If we are transforming from {urn:abc}* to {urn:a}*, we should not
simply generate:
<a:foo xmlns:a="urn:a">
  <a:bar>a2:text</a:bar>
</a:foo>

Instead, we should generate:
<a:foo xmlns:a="urn:a">
  <a2:bar xmlns:a2="urn:a">a2:text</a2:bar>
</a:foo>
so that the QName a2:text can be correctly interpreted.

Currently, the output transformer preserves all the non-empty
namespace bindings, so it generates the desired output in the above
case. But it does not preserve the default namespace binding, so the
desired output is not generated, if the input is given as:

<a:foo xmlns:a="urn:abc">
  <bar xmlns="urn:abc">text</bar>
</a:foo>

In this case, we are generating:
<a:foo xmlns:a="urn:a">
  <a:bar>text</bar>
</a:foo>

instead of generating the desired output
<a:foo xmlns:a="urn:a">
  <bar xmlns="urn:a">text</bar>
</a:foo>

I think we need an option to preserve the namespace prefixes including
the empty ones. But currently, there is an explicit logic to replace
all empty prefixes with non-empty ones and to generate an empty prefix
only if it is explicitly configured to use the default namespace for
that particular namespace.

In order to remain compatible with this latter usage, we can activate
this prefix preserving mode only if this defaultNamespace setting is
inactive.

For the inbound, the prefixes are not preserved at all.

Do you think we should add this prefix preserving mode as an explicit
option or as the default behavior?

regards, aki


2012/3/2 Aki Yoshida <el...@googlemail.com>:
> Hi Sergey, Dan,
> thanks for the background information. There were a few things I
> noticed too late.
> I added back the original uri handling for CXF-3958 so that all test
> cases are working.
>
> Although my second fix handles the existing jaxrs systests and Oli's
> new test case that I added for CXF-4150 yesterday, we need another
> approach to handle other possible cases. So, I will be making another
> change.
>
> Regards, aki
>
> 2012/3/1 Daniel Kulp <dk...@apache.org>:
>> On Thursday, March 01, 2012 10:01:59 PM Sergey Beryozkin wrote:
>>> Hi Aki,
>>>
>>> Thanks for fixing this issue.
>>> As far as I recall, the written uris property was added to address
>>> https://issues.apache.org/jira/browse/CXF-3958
>>>
>>> I can get the test added asap just to confirm the fix you provided will
>>> also do for CXF-3958
>>
>> Well, it was modified for CXF-3958, not added.
>>
>> However, with this change, I am seeing test failures which Jenkins is seeing as well:
>>
>> https://builds.apache.org/view/A-F/view/CXF/job/CXF-Trunk-JDK15/org.apache.cxf.systests$cxf-systests-jaxrs/3065/testReport/
>>
>> So that definitely needs to be addresed.
>>
>> Dan
>>
>>
>>>
>>> Thanks, Sergey
>>>
>>> On 01/03/12 17:58, ay@apache.org wrote:
>>> > Author: ay
>>> > Date: Thu Mar  1 17:58:19 2012
>>> > New Revision: 1295714
>>> >
>>> > URL: http://svn.apache.org/viewvc?rev=1295714&view=rev
>>> > Log:
>>> > [CXF-4150] Transform feature's OutTransformWriter may not correctly
>>> > generate namespace declarations>
>>> > Added:
>>> >      cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/wstrus
>>> >      tReqSTRC.xml   (with props)
>>> >      cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/wstru
>>> >      stReqSTRCIn1.xml   (with props)>
>>> > Modified:
>>> >      cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTra
>>> >      nsformWriter.java
>>> >      cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTra
>>> >      nsformReaderTest.java
>>> >      cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTr
>>> >      ansformWriterTest.java>
>>> > Modified:
>>> > cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransfo
>>> > rmWriter.java URL:
>>> > http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/s
>>> > taxutils/transform/OutTransformWriter.java?rev=1295714&r1=1295713&r2=12957
>>> > 14&view=diff
>>> > =========================================================================
>>> > ===== ---
>>> > cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransfo
>>> > rmWriter.java (original) +++
>>> > cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransfo
>>> > rmWriter.java Thu Mar  1 17:58:19 2012 @@ -20,8 +20,6 @@ package
>>> > org.apache.cxf.staxutils.transfo
>>> >
>>> >   import java.util.ArrayList;
>>> >   import java.util.HashMap;
>>> >
>>> > -import java.util.HashSet;
>>> > -import java.util.LinkedList;
>>> >
>>> >   import java.util.List;
>>> >   import java.util.Map;
>>> >   import java.util.Set;
>>> >
>>> > @@ -43,7 +41,6 @@ public class OutTransformWriter extends
>>> >
>>> >       private QNamesMap attributesMap;
>>> >       private Map<QName, ElementProperty>  appendMap = new HashMap<QName,
>>> >       ElementProperty>(5); private Map<String, String>  nsMap = new
>>> >       HashMap<String, String>(5);>
>>> > -    private List<Set<String>>  writtenUris = new
>>> > LinkedList<Set<String>>();>
>>> >       private Set<QName>  dropElements;
>>> >       private Stack<List<ParsingEvent>>  pushedAheadEvents = new
>>> >       Stack<List<ParsingEvent>>();>
>>> > @@ -96,7 +93,7 @@ public class OutTransformWriter extends
>>> >
>>> >           uri = value != null ? value : uri;
>>> >
>>> > -        if (writtenUris.get(0).contains(uri)) {
>>> > +        if (prefix.equals(getPrefix(uri))) {
>>> >
>>> >               return;
>>> >
>>> >           }
>>> >
>>> > @@ -108,7 +105,6 @@ public class OutTransformWriter extends
>>> >
>>> >               }
>>> >               super.writeNamespace(prefix, uri);
>>> >
>>> >           }
>>> >
>>> > -        writtenUris.get(0).add(uri);
>>> >
>>> >       }
>>> >
>>> >       @Override
>>> >
>>> > @@ -117,13 +113,6 @@ public class OutTransformWriter extends
>>> >
>>> >           if (matchesDropped(false)) {
>>> >
>>> >               return;
>>> >
>>> >           }
>>> >
>>> > -        Set<String>  s;
>>> > -        if (writtenUris.isEmpty()) {
>>> > -            s = new HashSet<String>();
>>> > -        } else {
>>> > -            s = new HashSet<String>(writtenUris.get(0));
>>> > -        }
>>> > -        writtenUris.add(0, s);
>>> >
>>> >           final QName theName = new QName(uri, local, prefix);
>>> >           final ElementProperty appendProp = appendMap.remove(theName);
>>> >
>>> > @@ -243,9 +232,7 @@ public class OutTransformWriter extends
>>> >
>>> >           } else if (dropDepth>  0) {
>>> >
>>> >               dropDepth = 0;
>>> >
>>> >           }
>>> >
>>> > -        if (!writtenUris.isEmpty()) {
>>> > -            writtenUris.remove(0);
>>> > -        }
>>> > +
>>> >
>>> >           QName theName = elementsStack.pop();
>>> >           final boolean dropped = dropElements.contains(theName);
>>> >           if (!dropped) {
>>> >
>>> > Added:
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/wstrustReq
>>> > STRC.xml URL:
>>> > http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/s
>>> > taxutils/resources/wstrustReqSTRC.xml?rev=1295714&view=auto
>>> > =========================================================================
>>> > ===== Binary file - no diff available.
>>> >
>>> > Propchange:
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/wstrustReq
>>> > STRC.xml
>>> > -------------------------------------------------------------------------
>>> > ----->
>>> >      svn:mime-type = application/xml
>>> >
>>> > Added:
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/wstrustReq
>>> > STRCIn1.xml URL:
>>> > http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/s
>>> > taxutils/resources/wstrustReqSTRCIn1.xml?rev=1295714&view=auto
>>> > =========================================================================
>>> > ===== Binary file - no diff available.
>>> >
>>> > Propchange:
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/wstrustReq
>>> > STRCIn1.xml
>>> > -------------------------------------------------------------------------
>>> > ----->
>>> >      svn:mime-type = application/xml
>>> >
>>> > Modified:
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransfor
>>> > mReaderTest.java URL:
>>> > http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/s
>>> > taxutils/transform/InTransformReaderTest.java?rev=1295714&r1=1295713&r2=12
>>> > 95714&view=diff
>>> > =========================================================================
>>> > ===== ---
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransfor
>>> > mReaderTest.java (original) +++
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransfor
>>> > mReaderTest.java Thu Mar  1 17:58:19 2012 @@ -424,4 +424,18 @@ public
>>> > class InTransformReaderTest exten
>>> >
>>> >       }
>>> >
>>> > +    @Test
>>> > +    public void testOldSTSTransform() throws Exception {
>>> > +        Map<String, String>  transformElements = new HashMap<String,
>>> > String>(); +
>>> > +
>>> > transformElements.put("{http://docs.oasis-open.org/ws-sx/ws-trust/200512}
>>> > *", +
>>> > "{http://schemas.xmlsoap.org/ws/2005/02/trust}*"); +
>>> > +
>>> > +
>>> > TransformTestUtils.transformInStreamAndCompare("../resources/wstrustReqST
>>> > RCIn1.xml", +
>>> > "../resources/wstrustReqSTRC.xml", +
>>> > transformElements, null, null, null, null); +
>>> > +    }
>>> > +
>>> >
>>> >   }
>>> >
>>> > Modified:
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransfo
>>> > rmWriterTest.java URL:
>>> > http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/s
>>> > taxutils/transform/OutTransformWriterTest.java?rev=1295714&r1=1295713&r2=1
>>> > 295714&view=diff
>>> > =========================================================================
>>> > ===== ---
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransfo
>>> > rmWriterTest.java (original) +++
>>> > cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransfo
>>> > rmWriterTest.java Thu Mar  1 17:58:19 2012 @@ -396,4 +396,14 @@ public
>>> > class OutTransformWriterTest exte
>>> >
>>> >       }
>>> >
>>> > +    @Test
>>> > +    public void testOldSTSTransform() throws Exception {
>>> > +        Map<String, String>  transformElements = new HashMap<String,
>>> > String>(); +
>>> > transformElements.put("{http://docs.oasis-open.org/ws-sx/ws-trust/200512}
>>> > *", +
>>> > "{http://schemas.xmlsoap.org/ws/2005/02/trust}*"); +
>>> > +
>>> > TransformTestUtils.transformOutStreamAndCompare("../resources/wstrustReqS
>>> > TRCIn1.xml", +
>>> > "../resources/wstrustReqSTRC.xml", +
>>> > transformElements, null, null, null, null); +    }
>>> >
>>> >   }
>> --
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com

Re: Transform feature to preserve prefix values (Re: svn commit: r1295714

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Aki
On 05/03/12 17:07, Aki Yoshida wrote:
> Hi Sergey, Dan,
>
> We are currently not enforcing the namespace bindings to preserve the
> namespace prefix values. For most applications, there is no need to
> preserve the prefix values.  But I just noticed that if you have an
> element value typed as QName,  you want to preserve its original
> prefix value so that this QName value can be interpreted correctly by
> the schema-aware binding framework.
>
> For example, if you have an input XML:
> <a:foo xmlns:a="urn:abc">
>    <a2:bar xmlns:a2="urn:abc">a2:text</a2:bar>
> </a:foo>
> and suppose the content of element bar is of type QName.
>
> If we are transforming from {urn:abc}* to {urn:a}*, we should not
> simply generate:
> <a:foo xmlns:a="urn:a">
>    <a:bar>a2:text</a:bar>
> </a:foo>
>
> Instead, we should generate:
> <a:foo xmlns:a="urn:a">
>    <a2:bar xmlns:a2="urn:a">a2:text</a2:bar>
> </a:foo>
> so that the QName a2:text can be correctly interpreted.
>
> Currently, the output transformer preserves all the non-empty
> namespace bindings, so it generates the desired output in the above
> case. But it does not preserve the default namespace binding, so the
> desired output is not generated, if the input is given as:
>
> <a:foo xmlns:a="urn:abc">
>    <bar xmlns="urn:abc">text</bar>
> </a:foo>
>
> In this case, we are generating:
> <a:foo xmlns:a="urn:a">
>    <a:bar>text</bar>
> </a:foo>
>
> instead of generating the desired output
> <a:foo xmlns:a="urn:a">
>    <bar xmlns="urn:a">text</bar>
> </a:foo>
>
> I think we need an option to preserve the namespace prefixes including
> the empty ones. But currently, there is an explicit logic to replace
> all empty prefixes with non-empty ones and to generate an empty prefix
> only if it is explicitly configured to use the default namespace for
> that particular namespace.
>
> In order to remain compatible with this latter usage, we can activate
> this prefix preserving mode only if this defaultNamespace setting is
> inactive.
>
> For the inbound, the prefixes are not preserved at all.
>
> Do you think we should add this prefix preserving mode as an explicit
> option or as the default behavior?
>
I think having the prefix preserving mode makes sense, I'm not exactly 
sure if it should be set by default :-), probably yes... It seems that 
the default namespace mode should always take precedence for a given 
namespace, if it's set

Thanks, Sergey

> regards, aki
>