Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5BD08200C2A for ; Wed, 1 Mar 2017 13:00:54 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5A54F160B70; Wed, 1 Mar 2017 12:00:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7B030160B5E for ; Wed, 1 Mar 2017 13:00:53 +0100 (CET) Received: (qmail 46596 invoked by uid 500); 1 Mar 2017 12:00:52 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Received: (qmail 46578 invoked by uid 99); 1 Mar 2017 12:00:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2017 12:00:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CF23718819F for ; Wed, 1 Mar 2017 12:00:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.199 X-Spam-Level: * X-Spam-Status: No, score=1.199 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_SORBS_SPAM=0.5] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=regvart.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id O12qJCpM-lNF for ; Wed, 1 Mar 2017 12:00:49 +0000 (UTC) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 2CB345F23D for ; Wed, 1 Mar 2017 12:00:49 +0000 (UTC) Received: by mail-wr0-f194.google.com with SMTP id u108so1278643wrb.2 for ; Wed, 01 Mar 2017 04:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=regvart.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=s2p+7vmHQQXcKF25e9iqsEW0KYgV/hNsZ/PBsrsGXYo=; b=de2MZdiV5npjbkICXfVe01ivHhWIh5IIWMDvGzDJ2j2gUaCgXSqFS48pt1tA8fw96n 3rVcy6unU7VXArGJFRJD468d/2qv33FMZ1cXyCyeetf1pabfpS+j61/MjgN6IFFjff+z /KrumGTTsrZS5XJl0JpDAjTq+xNQzLsSKuvyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=s2p+7vmHQQXcKF25e9iqsEW0KYgV/hNsZ/PBsrsGXYo=; b=Hb0cpkOF0nb+9EKmvUFAuFixm/UgTkAE9NiBgjy1f9Cv5l2oUo/Li9kju6zHEFa5dI SihKm5ILuWOsSSVBhbCB14rOij1lwDdUMccLM8iaXYeBwwJTTwUV6PkWkd2Ur5zBC8nb x/V2P8NLR6NCB7jA29MS+fU7qESDRHcYqOPzZrsdnbxbxDASSahSXEYu56X7sMnqa94e dHnpHQ2ubGg/ATwsvvRiTcURP+Cv0bnW1PSToT66g0+gqyyQvVDmyq7Qi/KO+OuT8uAo 5aoa7EnV1b58B25oZrSZPMhaeIdUYL/NOa/XFiBYLC1bHPJBkwxYRQpa40FUa900h3dk V5PQ== X-Gm-Message-State: AMke39mdS+d3ROjLe0RujXUJjUNuV4cSZJwfpuac25YG9R9+FFbhDctfcWbC1Fi8CO9liikH8HFby0gtQEnw3Q== X-Received: by 10.223.151.217 with SMTP id t25mr7679153wrb.95.1488369647674; Wed, 01 Mar 2017 04:00:47 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.138.33 with HTTP; Wed, 1 Mar 2017 04:00:27 -0800 (PST) In-Reply-To: References: <0266d564db534dd38ad7122a00c20505@git.apache.org> From: Zoran Regvart Date: Wed, 1 Mar 2017 13:00:27 +0100 Message-ID: Subject: Re: camel git commit: CAMEL-10915 Add type conversion support for jav... To: dev@camel.apache.org Cc: commits@camel.apache.org Content-Type: text/plain; charset=UTF-8 archived-at: Wed, 01 Mar 2017 12:00:54 -0000 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 wrote: > On Wed, Mar 1, 2017 at 12:21 PM, 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 >> Authored: Wed Mar 1 12:17:52 2017 +0100 >> Committer: Zoran Regvart >> 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