Author: johndament
Date: Fri Aug 4 23:56:07 2017
New Revision: 1804166
URL: http://svn.apache.org/viewvc?rev=1804166&view=rev
Log:
GERONIMO-6576 Adding built in converter for URL.
Added:
geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/converters/URLConverter.java
Modified:
geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java?rev=1804166&r1=1804165&r2=1804166&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
(original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
Fri Aug 4 23:56:07 2017
@@ -18,6 +18,7 @@ package org.apache.geronimo.config;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.net.URL;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
@@ -51,6 +52,7 @@ import org.apache.geronimo.config.conver
import org.apache.geronimo.config.converters.OffsetDateTimeConverter;
import org.apache.geronimo.config.converters.OffsetTimeConverter;
import org.apache.geronimo.config.converters.StringConverter;
+import org.apache.geronimo.config.converters.URLConverter;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.Converter;
@@ -61,6 +63,7 @@ import javax.enterprise.inject.Vetoed;
/**
* @author <a href="mailto:struberg@apache.org">Mark Struberg</a>
+ * @author <a href="mailto:johndament@apache.org">John D. Ament</a>
*/
@Typed
@Vetoed
@@ -95,6 +98,8 @@ public class ConfigImpl implements Confi
converters.put(OffsetTime.class, OffsetTimeConverter.INSTANCE);
converters.put(OffsetDateTime.class, OffsetDateTimeConverter.INSTANCE);
converters.put(Instant.class, InstantConverter.INSTANCE);
+
+ converters.put(URL.class, URLConverter.INSTANCE);
}
Added: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/converters/URLConverter.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/converters/URLConverter.java?rev=1804166&view=auto
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/converters/URLConverter.java
(added)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/converters/URLConverter.java
Fri Aug 4 23:56:07 2017
@@ -0,0 +1,38 @@
+/*
+ * 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.geronimo.config.converters;
+
+import org.eclipse.microprofile.config.spi.Converter;
+
+import javax.annotation.Priority;
+import javax.enterprise.inject.Vetoed;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+@Vetoed
+@Priority(1)
+public class URLConverter implements Converter<URL> {
+ public static final URLConverter INSTANCE = new URLConverter();
+ @Override
+ public URL convert(String value) {
+ try {
+ return new URL(value);
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException("Invalid url "+value,e);
+ }
+ }
+}
|