You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by santodip <sa...@gmail.com> on 2014/10/06 13:49:04 UTC
CXF accepts 'tru*' for boolean fields
I have written a web service using CXF. The WSDL contains one of the field as
'boolean'. Unfortunately at runtime I found that when "trud", "trua" or
"truee" is passed through that field, it accepts the value as "true". This
should have been a "false" value for a boolean field.
Any suggestion is highly appreciated
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-accepts-tru-for-boolean-fields-tp5749458.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: CXF accepts 'tru*' for boolean fields
Posted by Ron Wheeler <rw...@artifact-software.com>.
On 06/10/2014 7:49 AM, santodip wrote:
> I have written a web service using CXF. The WSDL contains one of the field as
> 'boolean'. Unfortunately at runtime I found that when "trud", "trua" or
> "truee" is passed through that field, it accepts the value as "true". This
> should have been a "false" value for a boolean field.
>
> Any suggestion is highly appreciated
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-accepts-tru-for-boolean-fields-tp5749458.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
By the same argument "fals", "falsee", "fase" should all be considered
as "true" since they are not "false".
Unfortunately, Boolean only has 2 possible values and lacks a way to
signal"wtf?".
You might want to document your web service to warn programmers writing
clients to use booleans properly and warn them that the results will be
indeterminate if they send values other than "true" or "false".
What happens if you send in "dog" or "cat" as the Boolean? What would
you like to happen?
You could use a string instead of a Boolean if you need to handle
non-Boolean input. Then you can parse the input and decide what you want
"truee" or "dog" to mean.
--
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102
Re: CXF accepts 'tru*' for boolean fields
Posted by Ron Wheeler <rw...@artifact-software.com>.
According the docs at
https://jaxb.java.net/nonav/2.2.4/docs/api/javax/xml/bind/DatatypeConverter.html#parseBoolean(java.lang.String)
"parseBoolean
public static boolean parseBoolean(String
<http://download.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true> lexicalXSDBoolean)
IllegalArgumentException
<http://download.oracle.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true> -
if string parameter does not conform to lexical value space defined in
XML Schema Part 2: Datatypes for xsd:boolean."
According to
http://www.w3.org/TR/xmlschema-2/#boolean
"An instance of a datatype that is defined as ·boolean· can have the
following legal literals {true, false, 1, 0}."
From this, it appears that the examples cited should cause a
IllegalArgumentException.
Ron
On 06/10/2014 1:32 PM, Gary Gregory wrote:
> what about doIt("truthiness")?
> :-)
> Gary
>
> On Mon, Oct 6, 2014 at 10:49 AM, Daniel Kulp <dk...@apache.org> wrote:
>
>> This is also not really a bug in CXF but a bug in the JDK. The JAXB
>> runtime would use javax.xml.bind.DatatypeConverter to parse the booleans
>> and if I write a quick test like:
>>
>> @Test
>> public void foo() {
>> doIt("true");
>> doIt("1");
>> doIt("trud");
>> doIt("trus”);
>> doIt("trued");
>> }
>> public static void doIt(String s) {
>> Boolean b = javax.xml.bind.DatatypeConverter.parseBoolean(s);
>> System.out.println(s + ": " + b);
>> }
>>
>> I get:
>> true: true
>> 1: true
>> trud: true
>> trus: true
>> trued: true
>>
>> Thus, this is really outside of CXF’s control as Oracle would need to fix
>> this in the JAXB runtime.
>>
>> That said, you can turn on schema validation and that SHOULD catch this.
>> I believe the schema validator is much much more strict about this.
>>
>> Dan
>>
>>
>>
>>
>>
>> On Oct 6, 2014, at 7:49 AM, santodip <sa...@gmail.com> wrote:
>>
>>> I have written a web service using CXF. The WSDL contains one of the
>> field as
>>> 'boolean'. Unfortunately at runtime I found that when "trud", "trua" or
>>> "truee" is passed through that field, it accepts the value as "true".
>> This
>>> should have been a "false" value for a boolean field.
>>>
>>> Any suggestion is highly appreciated
>>>
>>>
>>>
>>> --
>>> View this message in context:
>> http://cxf.547215.n5.nabble.com/CXF-accepts-tru-for-boolean-fields-tp5749458.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
>>
>>
>
--
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102
Re: CXF accepts 'tru*' for boolean fields
Posted by Gary Gregory <ga...@gmail.com>.
what about doIt("truthiness")?
:-)
Gary
On Mon, Oct 6, 2014 at 10:49 AM, Daniel Kulp <dk...@apache.org> wrote:
>
> This is also not really a bug in CXF but a bug in the JDK. The JAXB
> runtime would use javax.xml.bind.DatatypeConverter to parse the booleans
> and if I write a quick test like:
>
> @Test
> public void foo() {
> doIt("true");
> doIt("1");
> doIt("trud");
> doIt("trus”);
> doIt("trued");
> }
> public static void doIt(String s) {
> Boolean b = javax.xml.bind.DatatypeConverter.parseBoolean(s);
> System.out.println(s + ": " + b);
> }
>
> I get:
> true: true
> 1: true
> trud: true
> trus: true
> trued: true
>
> Thus, this is really outside of CXF’s control as Oracle would need to fix
> this in the JAXB runtime.
>
> That said, you can turn on schema validation and that SHOULD catch this.
> I believe the schema validator is much much more strict about this.
>
> Dan
>
>
>
>
>
> On Oct 6, 2014, at 7:49 AM, santodip <sa...@gmail.com> wrote:
>
> > I have written a web service using CXF. The WSDL contains one of the
> field as
> > 'boolean'. Unfortunately at runtime I found that when "trud", "trua" or
> > "truee" is passed through that field, it accepts the value as "true".
> This
> > should have been a "false" value for a boolean field.
> >
> > Any suggestion is highly appreciated
> >
> >
> >
> > --
> > View this message in context:
> http://cxf.547215.n5.nabble.com/CXF-accepts-tru-for-boolean-fields-tp5749458.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
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: CXF accepts 'tru*' for boolean fields
Posted by Daniel Kulp <dk...@apache.org>.
This is also not really a bug in CXF but a bug in the JDK. The JAXB runtime would use javax.xml.bind.DatatypeConverter to parse the booleans and if I write a quick test like:
@Test
public void foo() {
doIt("true");
doIt("1");
doIt("trud");
doIt("trus”);
doIt("trued");
}
public static void doIt(String s) {
Boolean b = javax.xml.bind.DatatypeConverter.parseBoolean(s);
System.out.println(s + ": " + b);
}
I get:
true: true
1: true
trud: true
trus: true
trued: true
Thus, this is really outside of CXF’s control as Oracle would need to fix this in the JAXB runtime.
That said, you can turn on schema validation and that SHOULD catch this. I believe the schema validator is much much more strict about this.
Dan
On Oct 6, 2014, at 7:49 AM, santodip <sa...@gmail.com> wrote:
> I have written a web service using CXF. The WSDL contains one of the field as
> 'boolean'. Unfortunately at runtime I found that when "trud", "trua" or
> "truee" is passed through that field, it accepts the value as "true". This
> should have been a "false" value for a boolean field.
>
> Any suggestion is highly appreciated
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-accepts-tru-for-boolean-fields-tp5749458.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