You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2017/03/01 11:29:52 UTC

Re: camel git commit: CAMEL-10915 Add type conversion support for jav...

On Wed, Mar 1, 2017 at 12:21 PM,  <zr...@apache.org> wrote:
> Repository: camel
> Updated Branches:
>   refs/heads/master c6a15565a -> d569b80d8
>
>
> CAMEL-10915 Add type conversion support for jav...
>
> ...a.net.URI
>
> Adds converter to and from `java.net.URI` and `java.lang.CharSequence`.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d569b80d
> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d569b80d
> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d569b80d
>
> Branch: refs/heads/master
> Commit: d569b80d81b200ca83a1f7e56d5e20c6f59f6427
> Parents: c6a1556
> Author: Zoran Regvart <zr...@apache.org>
> Authored: Wed Mar 1 12:17:52 2017 +0100
> Committer: Zoran Regvart <zr...@apache.org>
> Committed: Wed Mar 1 12:20:49 2017 +0100
>
> ----------------------------------------------------------------------
>  .../converter/CorePackageScanClassResolver.java |  1 +
>  .../camel/impl/converter/UriTypeConverter.java  | 53 +++++++++++++++++++
>  .../impl/converter/UriTypeConverterTest.java    | 54 ++++++++++++++++++++
>  3 files changed, 108 insertions(+)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
> ----------------------------------------------------------------------
> diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
> index ed11fa9..65ec445 100644
> --- a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
> +++ b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
> @@ -77,6 +77,7 @@ public class CorePackageScanClassResolver implements PackageScanClassResolver {
>          converters.add(GenericFileConverter.class);
>          converters.add(DurationConverter.class);
>          converters.add(AttachmentConverter.class);
> +        converters.add(UriTypeConverter.class);
>      }
>
>      @Override
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
> ----------------------------------------------------------------------
> diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java b/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
> new file mode 100644
> index 0000000..aab8e14
> --- /dev/null
> +++ b/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
> @@ -0,0 +1,53 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.camel.impl.converter;
> +
> +import java.net.URI;
> +import java.net.URISyntaxException;
> +
> +import org.apache.camel.Converter;
> +import org.apache.camel.TypeConversionException;
> +import org.apache.camel.TypeConverter;
> +
> +/**
> + * A {@link TypeConverter} that converts to and from {@link URI}s.
> + */
> +public class UriTypeConverter {
> +
> +    @Converter
> +    public static CharSequence toCharSequence(final Object value) {
> +        final URI uri = toUri(value);
> +
> +        return uri.toString();
> +    }

-1 be careful to do such open ended conversion from Object -> Char
which is not related to URI.
That converter should be removed


> +
> +    @Converter
> +    public static URI toUri(final Object value) {
> +        if (value instanceof URI) {
> +            return (URI)value;
> +        }
> +
> +        final String stringValue = String.valueOf(value);
> +
> +        try {
> +            return new URI(stringValue);
> +        } catch (final URISyntaxException e) {
> +            throw new TypeConversionException(value, URI.class, e);
> +        }
> +    }
> +

This should not be Object either, its a String -> URI




> +}
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
> ----------------------------------------------------------------------
> diff --git a/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java b/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
> new file mode 100644
> index 0000000..9cb4289
> --- /dev/null
> +++ b/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
> @@ -0,0 +1,54 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.camel.impl.converter;
> +
> +import java.net.URI;
> +
> +import org.apache.camel.TypeConversionException;
> +import org.junit.Test;
> +
> +import static org.junit.Assert.assertEquals;
> +
> +public class UriTypeConverterTest {
> +
> +    static final String EXAMPLE = "http://www.example.com";
> +
> +    static final URI EXAMPLE_URI = URI.create(EXAMPLE);
> +
> +    static final String INVALID = ":";
> +
> +    @Test(expected = TypeConversionException.class)
> +    public void shouldComplainOnInvalidStringUrisConvertingToStrings() {
> +        UriTypeConverter.toCharSequence(INVALID);
> +    }
> +
> +    @Test(expected = TypeConversionException.class)
> +    public void shouldComplainOnInvalidStringUrisConvertingToUri() {
> +        UriTypeConverter.toUri(INVALID);
> +    }
> +
> +    @Test
> +    public void shouldConvertFromStringsToUris() {
> +        assertEquals(EXAMPLE_URI, UriTypeConverter.toUri(EXAMPLE));
> +    }
> +
> +    @Test
> +    public void shouldConvertFromUrisToStrings() {
> +        assertEquals(EXAMPLE, UriTypeConverter.toCharSequence(EXAMPLE_URI));
> +    }
> +
> +}
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: camel git commit: CAMEL-10915 Add type conversion support for jav...

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

That sounds like a fine use-case.

+1

On Wed, Mar 1, 2017 at 1:11 PM, Zoran Regvart <zo...@regvart.com> wrote:
> Hi,
> On Wed, Mar 1, 2017 at 1:04 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>
>> But is there something about creating URI is expensive? I vaguely
>> recall something about creating either that or URL that may do some
>> hostname lookup or something.
>
> java.net.URL is the evil blocking one it blocks in hashCode on DNS
> lookup[1], java.net.URI is inexpensive
>
>> Btw what is the need for this type converter? Where are you going to
>> use it more specific?
>
> I would like @UriParam to be typed java.net.URI, it seems wasteful and
> error prone to have scheme, host, port, path as separate properties,
> so I added a converter that would convert String to URI so that the
> parameters would be set from endpoint URI. Does that make sense?
>
> zoran
>
>
> [1] http://michaelscharf.blogspot.de/2006/11/javaneturlequals-and-hashcode-make.html
> (first hit on Google)
> --
> Zoran Regvart



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: camel git commit: CAMEL-10915 Add type conversion support for jav...

Posted by Zoran Regvart <zo...@regvart.com>.
Hi,
On Wed, Mar 1, 2017 at 1:04 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
> But is there something about creating URI is expensive? I vaguely
> recall something about creating either that or URL that may do some
> hostname lookup or something.

java.net.URL is the evil blocking one it blocks in hashCode on DNS
lookup[1], java.net.URI is inexpensive

> Btw what is the need for this type converter? Where are you going to
> use it more specific?

I would like @UriParam to be typed java.net.URI, it seems wasteful and
error prone to have scheme, host, port, path as separate properties,
so I added a converter that would convert String to URI so that the
parameters would be set from endpoint URI. Does that make sense?

zoran


[1] http://michaelscharf.blogspot.de/2006/11/javaneturlequals-and-hashcode-make.html
(first hit on Google)
-- 
Zoran Regvart

Re: camel git commit: CAMEL-10915 Add type conversion support for jav...

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

That kind is fine. You should avoid using Object. As long as the from
-> to are specific types and not open ended like Object. The latter
requests to use a fallback type converter and some more "tricky" code
to do this correctly.

But is there something about creating URI is expensive? I vaguely
recall something about creating either that or URL that may do some
hostname lookup or something.

Btw what is the need for this type converter? Where are you going to
use it more specific?

On Wed, Mar 1, 2017 at 1:00 PM, Zoran Regvart <zo...@regvart.com> wrote:
> Hi Claus,
> thanks for reviewing :) Would this be better?
>
> CharSequence toCharSequence(URI value)
>
> and
>
> URI toUri(CharSequence value)
>
> or do you think that URI type converter support should be removed entirely?
>
> zoran
>
> On Wed, Mar 1, 2017 at 12:29 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> On Wed, Mar 1, 2017 at 12:21 PM,  <zr...@apache.org> wrote:
>>> Repository: camel
>>> Updated Branches:
>>>   refs/heads/master c6a15565a -> d569b80d8
>>>
>>>
>>> CAMEL-10915 Add type conversion support for jav...
>>>
>>> ...a.net.URI
>>>
>>> Adds converter to and from `java.net.URI` and `java.lang.CharSequence`.
>>>
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d569b80d
>>> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d569b80d
>>> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d569b80d
>>>
>>> Branch: refs/heads/master
>>> Commit: d569b80d81b200ca83a1f7e56d5e20c6f59f6427
>>> Parents: c6a1556
>>> Author: Zoran Regvart <zr...@apache.org>
>>> Authored: Wed Mar 1 12:17:52 2017 +0100
>>> Committer: Zoran Regvart <zr...@apache.org>
>>> Committed: Wed Mar 1 12:20:49 2017 +0100
>>>
>>> ----------------------------------------------------------------------
>>>  .../converter/CorePackageScanClassResolver.java |  1 +
>>>  .../camel/impl/converter/UriTypeConverter.java  | 53 +++++++++++++++++++
>>>  .../impl/converter/UriTypeConverterTest.java    | 54 ++++++++++++++++++++
>>>  3 files changed, 108 insertions(+)
>>> ----------------------------------------------------------------------
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>>> ----------------------------------------------------------------------
>>> diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>>> index ed11fa9..65ec445 100644
>>> --- a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>>> +++ b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>>> @@ -77,6 +77,7 @@ public class CorePackageScanClassResolver implements PackageScanClassResolver {
>>>          converters.add(GenericFileConverter.class);
>>>          converters.add(DurationConverter.class);
>>>          converters.add(AttachmentConverter.class);
>>> +        converters.add(UriTypeConverter.class);
>>>      }
>>>
>>>      @Override
>>>
>>> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
>>> ----------------------------------------------------------------------
>>> diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java b/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
>>> new file mode 100644
>>> index 0000000..aab8e14
>>> --- /dev/null
>>> +++ b/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
>>> @@ -0,0 +1,53 @@
>>> +/**
>>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>>> + * contributor license agreements.  See the NOTICE file distributed with
>>> + * this work for additional information regarding copyright ownership.
>>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>>> + * (the "License"); you may not use this file except in compliance with
>>> + * the License.  You may obtain a copy of the License at
>>> + *
>>> + *      http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing, software
>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>> + * See the License for the specific language governing permissions and
>>> + * limitations under the License.
>>> + */
>>> +package org.apache.camel.impl.converter;
>>> +
>>> +import java.net.URI;
>>> +import java.net.URISyntaxException;
>>> +
>>> +import org.apache.camel.Converter;
>>> +import org.apache.camel.TypeConversionException;
>>> +import org.apache.camel.TypeConverter;
>>> +
>>> +/**
>>> + * A {@link TypeConverter} that converts to and from {@link URI}s.
>>> + */
>>> +public class UriTypeConverter {
>>> +
>>> +    @Converter
>>> +    public static CharSequence toCharSequence(final Object value) {
>>> +        final URI uri = toUri(value);
>>> +
>>> +        return uri.toString();
>>> +    }
>>
>> -1 be careful to do such open ended conversion from Object -> Char
>> which is not related to URI.
>> That converter should be removed
>>
>>
>>> +
>>> +    @Converter
>>> +    public static URI toUri(final Object value) {
>>> +        if (value instanceof URI) {
>>> +            return (URI)value;
>>> +        }
>>> +
>>> +        final String stringValue = String.valueOf(value);
>>> +
>>> +        try {
>>> +            return new URI(stringValue);
>>> +        } catch (final URISyntaxException e) {
>>> +            throw new TypeConversionException(value, URI.class, e);
>>> +        }
>>> +    }
>>> +
>>
>> This should not be Object either, its a String -> URI
>>
>>
>>
>>
>>> +}
>>>
>>> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
>>> ----------------------------------------------------------------------
>>> diff --git a/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java b/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
>>> new file mode 100644
>>> index 0000000..9cb4289
>>> --- /dev/null
>>> +++ b/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
>>> @@ -0,0 +1,54 @@
>>> +/**
>>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>>> + * contributor license agreements.  See the NOTICE file distributed with
>>> + * this work for additional information regarding copyright ownership.
>>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>>> + * (the "License"); you may not use this file except in compliance with
>>> + * the License.  You may obtain a copy of the License at
>>> + *
>>> + *      http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing, software
>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>> + * See the License for the specific language governing permissions and
>>> + * limitations under the License.
>>> + */
>>> +package org.apache.camel.impl.converter;
>>> +
>>> +import java.net.URI;
>>> +
>>> +import org.apache.camel.TypeConversionException;
>>> +import org.junit.Test;
>>> +
>>> +import static org.junit.Assert.assertEquals;
>>> +
>>> +public class UriTypeConverterTest {
>>> +
>>> +    static final String EXAMPLE = "http://www.example.com";
>>> +
>>> +    static final URI EXAMPLE_URI = URI.create(EXAMPLE);
>>> +
>>> +    static final String INVALID = ":";
>>> +
>>> +    @Test(expected = TypeConversionException.class)
>>> +    public void shouldComplainOnInvalidStringUrisConvertingToStrings() {
>>> +        UriTypeConverter.toCharSequence(INVALID);
>>> +    }
>>> +
>>> +    @Test(expected = TypeConversionException.class)
>>> +    public void shouldComplainOnInvalidStringUrisConvertingToUri() {
>>> +        UriTypeConverter.toUri(INVALID);
>>> +    }
>>> +
>>> +    @Test
>>> +    public void shouldConvertFromStringsToUris() {
>>> +        assertEquals(EXAMPLE_URI, UriTypeConverter.toUri(EXAMPLE));
>>> +    }
>>> +
>>> +    @Test
>>> +    public void shouldConvertFromUrisToStrings() {
>>> +        assertEquals(EXAMPLE, UriTypeConverter.toCharSequence(EXAMPLE_URI));
>>> +    }
>>> +
>>> +}
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Zoran Regvart



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: camel git commit: CAMEL-10915 Add type conversion support for jav...

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Claus,
thanks for reviewing :) Would this be better?

CharSequence toCharSequence(URI value)

and

URI toUri(CharSequence value)

or do you think that URI type converter support should be removed entirely?

zoran

On Wed, Mar 1, 2017 at 12:29 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Wed, Mar 1, 2017 at 12:21 PM,  <zr...@apache.org> wrote:
>> Repository: camel
>> Updated Branches:
>>   refs/heads/master c6a15565a -> d569b80d8
>>
>>
>> CAMEL-10915 Add type conversion support for jav...
>>
>> ...a.net.URI
>>
>> Adds converter to and from `java.net.URI` and `java.lang.CharSequence`.
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d569b80d
>> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d569b80d
>> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d569b80d
>>
>> Branch: refs/heads/master
>> Commit: d569b80d81b200ca83a1f7e56d5e20c6f59f6427
>> Parents: c6a1556
>> Author: Zoran Regvart <zr...@apache.org>
>> Authored: Wed Mar 1 12:17:52 2017 +0100
>> Committer: Zoran Regvart <zr...@apache.org>
>> Committed: Wed Mar 1 12:20:49 2017 +0100
>>
>> ----------------------------------------------------------------------
>>  .../converter/CorePackageScanClassResolver.java |  1 +
>>  .../camel/impl/converter/UriTypeConverter.java  | 53 +++++++++++++++++++
>>  .../impl/converter/UriTypeConverterTest.java    | 54 ++++++++++++++++++++
>>  3 files changed, 108 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>> ----------------------------------------------------------------------
>> diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>> index ed11fa9..65ec445 100644
>> --- a/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>> +++ b/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
>> @@ -77,6 +77,7 @@ public class CorePackageScanClassResolver implements PackageScanClassResolver {
>>          converters.add(GenericFileConverter.class);
>>          converters.add(DurationConverter.class);
>>          converters.add(AttachmentConverter.class);
>> +        converters.add(UriTypeConverter.class);
>>      }
>>
>>      @Override
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
>> ----------------------------------------------------------------------
>> diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java b/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
>> new file mode 100644
>> index 0000000..aab8e14
>> --- /dev/null
>> +++ b/camel-core/src/main/java/org/apache/camel/impl/converter/UriTypeConverter.java
>> @@ -0,0 +1,53 @@
>> +/**
>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>> + * contributor license agreements.  See the NOTICE file distributed with
>> + * this work for additional information regarding copyright ownership.
>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>> + * (the "License"); you may not use this file except in compliance with
>> + * the License.  You may obtain a copy of the License at
>> + *
>> + *      http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing, software
>> + * distributed under the License is distributed on an "AS IS" BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> + * See the License for the specific language governing permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.camel.impl.converter;
>> +
>> +import java.net.URI;
>> +import java.net.URISyntaxException;
>> +
>> +import org.apache.camel.Converter;
>> +import org.apache.camel.TypeConversionException;
>> +import org.apache.camel.TypeConverter;
>> +
>> +/**
>> + * A {@link TypeConverter} that converts to and from {@link URI}s.
>> + */
>> +public class UriTypeConverter {
>> +
>> +    @Converter
>> +    public static CharSequence toCharSequence(final Object value) {
>> +        final URI uri = toUri(value);
>> +
>> +        return uri.toString();
>> +    }
>
> -1 be careful to do such open ended conversion from Object -> Char
> which is not related to URI.
> That converter should be removed
>
>
>> +
>> +    @Converter
>> +    public static URI toUri(final Object value) {
>> +        if (value instanceof URI) {
>> +            return (URI)value;
>> +        }
>> +
>> +        final String stringValue = String.valueOf(value);
>> +
>> +        try {
>> +            return new URI(stringValue);
>> +        } catch (final URISyntaxException e) {
>> +            throw new TypeConversionException(value, URI.class, e);
>> +        }
>> +    }
>> +
>
> This should not be Object either, its a String -> URI
>
>
>
>
>> +}
>>
>> http://git-wip-us.apache.org/repos/asf/camel/blob/d569b80d/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
>> ----------------------------------------------------------------------
>> diff --git a/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java b/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
>> new file mode 100644
>> index 0000000..9cb4289
>> --- /dev/null
>> +++ b/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
>> @@ -0,0 +1,54 @@
>> +/**
>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>> + * contributor license agreements.  See the NOTICE file distributed with
>> + * this work for additional information regarding copyright ownership.
>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>> + * (the "License"); you may not use this file except in compliance with
>> + * the License.  You may obtain a copy of the License at
>> + *
>> + *      http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing, software
>> + * distributed under the License is distributed on an "AS IS" BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> + * See the License for the specific language governing permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.camel.impl.converter;
>> +
>> +import java.net.URI;
>> +
>> +import org.apache.camel.TypeConversionException;
>> +import org.junit.Test;
>> +
>> +import static org.junit.Assert.assertEquals;
>> +
>> +public class UriTypeConverterTest {
>> +
>> +    static final String EXAMPLE = "http://www.example.com";
>> +
>> +    static final URI EXAMPLE_URI = URI.create(EXAMPLE);
>> +
>> +    static final String INVALID = ":";
>> +
>> +    @Test(expected = TypeConversionException.class)
>> +    public void shouldComplainOnInvalidStringUrisConvertingToStrings() {
>> +        UriTypeConverter.toCharSequence(INVALID);
>> +    }
>> +
>> +    @Test(expected = TypeConversionException.class)
>> +    public void shouldComplainOnInvalidStringUrisConvertingToUri() {
>> +        UriTypeConverter.toUri(INVALID);
>> +    }
>> +
>> +    @Test
>> +    public void shouldConvertFromStringsToUris() {
>> +        assertEquals(EXAMPLE_URI, UriTypeConverter.toUri(EXAMPLE));
>> +    }
>> +
>> +    @Test
>> +    public void shouldConvertFromUrisToStrings() {
>> +        assertEquals(EXAMPLE, UriTypeConverter.toCharSequence(EXAMPLE_URI));
>> +    }
>> +
>> +}
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Zoran Regvart