diff --git a/core/pom.xml b/core/pom.xml index ca381ca..3810b83 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -7,7 +7,7 @@ net.cactusthorn.routing root - 0.23 + 0.24 core diff --git a/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java b/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java index e43182a..a9da43b 100644 --- a/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java +++ b/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java @@ -111,7 +111,7 @@ private void process(HttpServletRequest req, HttpServletResponse resp, List type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/ByteConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/ByteConverter.java index e95a46b..87f9a1c 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/ByteConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/ByteConverter.java @@ -13,7 +13,7 @@ public Byte convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/CharacterConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/CharacterConverter.java index 43c882d..5ae3976 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/CharacterConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/CharacterConverter.java @@ -16,7 +16,7 @@ public Character convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/ConsumerConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/ConsumerConverter.java index dac8f50..f00fda3 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/ConsumerConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/ConsumerConverter.java @@ -14,16 +14,12 @@ public final class ConsumerConverter implements Converter { } @Override // - public Object convert(RequestData requestData, Class type, String value) throws ConverterException { - try { - return consumer.consume(type, contentType, requestData); - } catch (Exception e) { - throw new ConverterException("Consumer converting failed", e); - } + public Object convert(RequestData requestData, Class type, String value) { + return consumer.consume(type, contentType, requestData); } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { throw new UnsupportedOperationException("Array support is senseless for consumer converting"); } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/Converter.java b/core/src/main/java/net/cactusthorn/routing/convert/Converter.java index 50c87a9..14f510e 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/Converter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/Converter.java @@ -6,21 +6,21 @@ public interface Converter { - default Object convert(Class type, String value) throws ConverterException { + default Object convert(Class type, String value) throws Exception { return convert(null, type, value); } - default Object convert(RequestData requestData, Class type) throws ConverterException { + default Object convert(RequestData requestData, Class type) throws Exception { return convert(requestData, type, (String) null); } - default Object convert(Class type, String[] value) throws ConverterException { + default Object convert(Class type, String[] value) throws Exception { return convert(null, type, value); } - Object convert(RequestData requestData, Class type, String value) throws ConverterException; + Object convert(RequestData requestData, Class type, String value) throws Exception; - default Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + default Object convert(RequestData requestData, Class type, String[] value) throws Exception { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/ConverterException.java b/core/src/main/java/net/cactusthorn/routing/convert/ConverterException.java index 0c7f118..a915c9e 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/ConverterException.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/ConverterException.java @@ -4,15 +4,9 @@ public class ConverterException extends Exception { private static final long serialVersionUID = 0L; - public ConverterException(String message, Throwable cause) { - super(message, cause); - } - - public ConverterException(String message, Throwable cause, Object param) { - super(String.format(message, param), cause); - } + private static final String MESSAGE = "Parameter position: %s; Parameter type: %s; %s"; - public ConverterException(Throwable cause) { - super(cause); + public ConverterException(Throwable cause, int position, String type) { + super(String.format(MESSAGE, position, type, cause), cause); } } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/DoubleConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/DoubleConverter.java index 45e8094..0965aeb 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/DoubleConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/DoubleConverter.java @@ -13,7 +13,7 @@ public Double convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/FloatConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/FloatConverter.java index 4430973..ab46cb5 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/FloatConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/FloatConverter.java @@ -13,7 +13,7 @@ public Float convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/IntegerConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/IntegerConverter.java index 15c4a1c..b031d54 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/IntegerConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/IntegerConverter.java @@ -13,7 +13,7 @@ public Integer convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/LongConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/LongConverter.java index 67c902d..f15042c 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/LongConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/LongConverter.java @@ -13,7 +13,7 @@ public Long convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/NullConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/NullConverter.java index 06d3e34..7fd8c3c 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/NullConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/NullConverter.java @@ -9,7 +9,7 @@ public final class NullConverter implements Converter { private PrimitiveConverter primitiveConverter = new PrimitiveConverter(); @Override // - public Object convert(RequestData requestData, Class type, String value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String value) throws Exception { if (type.isPrimitive()) { return primitiveConverter.convert(type, (String) null); } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/ShortConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/ShortConverter.java index 5709c0d..595034f 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/ShortConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/ShortConverter.java @@ -13,7 +13,7 @@ public Short convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/convert/StaticStringMethodConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/StaticStringMethodConverter.java index 1b38667..2680173 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/StaticStringMethodConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/StaticStringMethodConverter.java @@ -20,16 +20,13 @@ public StaticStringMethodConverter(String methodName) { } @Override // - public Object convert(RequestData requestData, Class type, String value) throws ConverterException { - try { - if (value == null) { - return null; - } - Method method = methods.get(type); - return method.invoke(null, value); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new ConverterException("The problem with method invocation", e); + public Object convert(RequestData requestData, Class type, String value) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + if (value == null) { + return null; } + Method method = methods.get(type); + return method.invoke(null, value); } boolean register(Class type) { diff --git a/core/src/main/java/net/cactusthorn/routing/convert/StringConstructorConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/StringConstructorConverter.java index ab826ba..4bcbd57 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/StringConstructorConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/StringConstructorConverter.java @@ -14,15 +14,12 @@ public class StringConstructorConverter implements Converter { private final Map, Constructor> constructors = new HashMap<>(); @Override // - public Object convert(RequestData requestData, Class type, String value) throws ConverterException { - try { - if (value == null) { - return null; - } - return constructors.get(type).newInstance(value); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new ConverterException("The problem with method invocation", e); + public Object convert(RequestData requestData, Class type, String value) + throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + if (value == null) { + return null; } + return constructors.get(type).newInstance(value); } boolean register(Class type) { diff --git a/core/src/main/java/net/cactusthorn/routing/convert/StringConverter.java b/core/src/main/java/net/cactusthorn/routing/convert/StringConverter.java index adc9fb5..5b9f3fc 100644 --- a/core/src/main/java/net/cactusthorn/routing/convert/StringConverter.java +++ b/core/src/main/java/net/cactusthorn/routing/convert/StringConverter.java @@ -10,7 +10,7 @@ public String convert(RequestData requestData, Class type, String value) { } @Override // - public Object convert(RequestData requestData, Class type, String[] value) throws ConverterException { + public Object convert(RequestData requestData, Class type, String[] value) { if (value == null) { return null; } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/BodyParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/BodyParameter.java index d3a4d54..13f7d40 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/BodyParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/BodyParameter.java @@ -9,8 +9,8 @@ import javax.servlet.http.HttpServletResponse; import net.cactusthorn.routing.RequestData; +import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.convert.ConsumerConverter; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public final class BodyParameter extends MethodParameter { @@ -21,15 +21,14 @@ public BodyParameter(Method method, Parameter parameter, ConvertersHolder conver super(parameter); Optional optional = convertersHolder.findConsumerConverter(contentType); if (!optional.isPresent()) { - throw new IllegalArgumentException( - "@Context: consumer for contentType " + contentType + " unknown; Method: " + method.toGenericString()); + throw new RoutingInitializationException( + "@Context: consumer for contentType %s unknown; Method: %s", contentType, method); } converter = optional.get(); } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { return converter.convert(requestData, classType()); } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/CookieParamParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/CookieParamParameter.java index 7df27ef..cb7fb5f 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/CookieParamParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/CookieParamParameter.java @@ -11,7 +11,6 @@ import net.cactusthorn.routing.RequestData; import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.annotation.CookieParam; -import net.cactusthorn.routing.convert.ConverterException; public class CookieParamParameter extends MethodParameter { @@ -28,21 +27,16 @@ public CookieParamParameter(Method method, Parameter parameter) { } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { - try { - Cookie[] cookies = req.getCookies(); - if (cookies == null) { - return null; - } - for (Cookie cookie : cookies) { - if (name.equals(cookie.getName())) { - return cookie; - } - } + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { + Cookie[] cookies = req.getCookies(); + if (cookies == null) { return null; - } catch (Exception e) { - throw new ConverterException("Type Converting problem", e); } + for (Cookie cookie : cookies) { + if (name.equals(cookie.getName())) { + return cookie; + } + } + return null; } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/FormPartParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/FormPartParameter.java index 139cff8..6b77218 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/FormPartParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/FormPartParameter.java @@ -12,7 +12,6 @@ import net.cactusthorn.routing.RequestData; import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.annotation.FormPart; -import net.cactusthorn.routing.convert.ConverterException; public class FormPartParameter extends MethodParameter { @@ -29,21 +28,16 @@ public FormPartParameter(Method method, Parameter parameter) { } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { - try { - Collection parts = req.getParts(); - if (parts == null) { - return null; - } - for (Part part : req.getParts()) { - if (name.equals(part.getName())) { - return part; - } - } + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { + Collection parts = req.getParts(); + if (parts == null) { return null; - } catch (Exception e) { - throw new ConverterException("Type Converting problem", e); } + for (Part part : req.getParts()) { + if (name.equals(part.getName())) { + return part; + } + } + return null; } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/HeaderParamParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/HeaderParamParameter.java index b1e16c2..fa3d4f7 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/HeaderParamParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/HeaderParamParameter.java @@ -9,7 +9,6 @@ import net.cactusthorn.routing.RequestData; import net.cactusthorn.routing.annotation.HeaderParam; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class HeaderParamParameter extends PathParamParameter { @@ -28,19 +27,12 @@ protected String initName(Parameter parameter) { } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { - try { - String value = req.getHeader(name()); - if (defaultValue() != null && value == null) { - value = defaultValue(); - } - return converter().convert(classType(), value); - } catch (ConverterException ce) { - throw ce; - } catch (Exception e) { - throw new ConverterException("Type Converting failed: header parameter \"%s\"", e, name()); + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { + String value = req.getHeader(name()); + if (defaultValue() != null && value == null) { + value = defaultValue(); } + return converter().convert(classType(), value); } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletRequestParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletRequestParameter.java index 6abfeb8..8321306 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletRequestParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletRequestParameter.java @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletResponse; import net.cactusthorn.routing.RequestData; -import net.cactusthorn.routing.convert.ConverterException; public final class HttpServletRequestParameter extends MethodParameter { @@ -17,7 +16,7 @@ public HttpServletRequestParameter(Parameter parameter) { @Override // HttpServletRequest findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { + throws Exception { return req; } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletResponseParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletResponseParameter.java index 10f5f94..384b3b8 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletResponseParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/HttpServletResponseParameter.java @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletResponse; import net.cactusthorn.routing.RequestData; -import net.cactusthorn.routing.convert.ConverterException; public final class HttpServletResponseParameter extends MethodParameter { @@ -17,7 +16,7 @@ public HttpServletResponseParameter(Parameter parameter) { @Override // HttpServletResponse findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { + throws Exception { return res; } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/HttpSessionParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/HttpSessionParameter.java index 0595dac..0c2ed5e 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/HttpSessionParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/HttpSessionParameter.java @@ -8,7 +8,6 @@ import javax.servlet.http.HttpSession; import net.cactusthorn.routing.RequestData; -import net.cactusthorn.routing.convert.ConverterException; public final class HttpSessionParameter extends MethodParameter { @@ -18,7 +17,7 @@ public HttpSessionParameter(Parameter parameter) { @Override // HttpSession findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { + throws Exception { return req.getSession(false); } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/MethodComplexParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/MethodComplexParameter.java index 616ce83..d130bf2 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/MethodComplexParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/MethodComplexParameter.java @@ -5,7 +5,6 @@ import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.convert.Converter; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public abstract class MethodComplexParameter extends MethodParameter { @@ -82,25 +81,12 @@ protected Optional> collectionType() { @SuppressWarnings("unchecked") // protected Object createCollection(Class collectionType, Class converterType, Converter converter, String[] values) - throws ConverterException { + throws Exception { if (values == null) { return null; } - - Constructor> constructor; - try { - constructor = (Constructor>) collectionType.getConstructor(); - } catch (NoSuchMethodException | SecurityException e) { - throw new ConverterException(e); - } - - Collection newCollection; - try { - newCollection = constructor.newInstance(); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new ConverterException(e); - } - + Constructor> constructor = (Constructor>) collectionType.getConstructor(); + Collection newCollection = constructor.newInstance(); for (String value : values) { newCollection.add(converter.convert(converterType, value)); } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/MethodInvoker.java b/core/src/main/java/net/cactusthorn/routing/invoke/MethodInvoker.java index bcf982a..efa20fd 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/MethodInvoker.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/MethodInvoker.java @@ -62,7 +62,12 @@ public Object invoke(HttpServletRequest req, HttpServletResponse res, ServletCon } for (int i = 0; i < parameters.size(); i++) { - values[i] = parameters.get(i).findValue(req, res, con, requestData); + MethodParameter parameter = parameters.get(i); + try { + values[i] = parameter.findValue(req, res, con, requestData); + } catch (Exception e) { + throw new ConverterException(e, i + 1, parameter.getClass().getSimpleName()); + } } try { diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/MethodParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/MethodParameter.java index 97969df..5dd8513 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/MethodParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/MethodParameter.java @@ -17,7 +17,6 @@ import net.cactusthorn.routing.annotation.PathParam; import net.cactusthorn.routing.annotation.QueryParam; import net.cactusthorn.routing.annotation.DefaultValue; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public abstract class MethodParameter { @@ -42,7 +41,7 @@ protected Class classType() { } abstract Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException; + throws Exception; static final class Factory { diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/PathParamParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/PathParamParameter.java index e49a809..459bbec 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/PathParamParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/PathParamParameter.java @@ -12,7 +12,6 @@ import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.annotation.PathParam; import net.cactusthorn.routing.convert.Converter; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class PathParamParameter extends MethodComplexParameter { @@ -55,18 +54,11 @@ protected String initName(Parameter parameter) { } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { - try { - String value = requestData.pathValues().value(name); - if (defaultValue() != null && "".equals(value)) { - value = defaultValue(); - } - return converter.convert(classType(), value); - } catch (ConverterException ce) { - throw ce; - } catch (Exception e) { - throw new ConverterException("Type Converting failed: path parameter \"%s\"", e, name); + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { + String value = requestData.pathValues().value(name); + if (defaultValue() != null && "".equals(value)) { + value = defaultValue(); } + return converter.convert(classType(), value); } } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/QueryParamParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/QueryParamParameter.java index 2c5e769..7b37cec 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/QueryParamParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/QueryParamParameter.java @@ -11,7 +11,6 @@ import net.cactusthorn.routing.RequestData; import net.cactusthorn.routing.annotation.QueryParam; import net.cactusthorn.routing.convert.Converter; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class QueryParamParameter extends MethodComplexParameter { @@ -55,28 +54,18 @@ protected String initName(Parameter parameter) { } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { - try { - - if (array) { - return converter.convert(converterType, arrayValues(req)); - } - - if (collection) { - return createCollection(collectionType, converterType, converter, arrayValues(req)); - } - - String value = req.getParameter(name); - if (defaultValue() != null && value == null) { - value = defaultValue(); - } - return converter.convert(converterType, value); - } catch (ConverterException ce) { - throw ce; - } catch (Exception e) { - throw new ConverterException("Type Converting failed: request parameter \"%s\"", e, name); + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { + if (array) { + return converter.convert(converterType, arrayValues(req)); + } + if (collection) { + return createCollection(collectionType, converterType, converter, arrayValues(req)); + } + String value = req.getParameter(name); + if (defaultValue() != null && value == null) { + value = defaultValue(); } + return converter.convert(converterType, value); } private String[] arrayValues(HttpServletRequest req) { diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/ServletContextParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/ServletContextParameter.java index 90d9df4..c5daf25 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/ServletContextParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/ServletContextParameter.java @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletResponse; import net.cactusthorn.routing.RequestData; -import net.cactusthorn.routing.convert.ConverterException; public final class ServletContextParameter extends MethodParameter { @@ -17,8 +16,7 @@ public ServletContextParameter(Parameter parameter) { @Override // ServletContext findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { + throws Exception { return con; } - } diff --git a/core/src/main/java/net/cactusthorn/routing/invoke/UnknownParameter.java b/core/src/main/java/net/cactusthorn/routing/invoke/UnknownParameter.java index 12b4fff..69b2ad5 100644 --- a/core/src/main/java/net/cactusthorn/routing/invoke/UnknownParameter.java +++ b/core/src/main/java/net/cactusthorn/routing/invoke/UnknownParameter.java @@ -7,7 +7,6 @@ import javax.servlet.http.HttpServletResponse; import net.cactusthorn.routing.RequestData; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.NullConverter; public final class UnknownParameter extends MethodParameter { @@ -17,8 +16,7 @@ public UnknownParameter(Parameter parameter) { } @Override // - Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) - throws ConverterException { + Object findValue(HttpServletRequest req, HttpServletResponse res, ServletContext con, RequestData requestData) throws Exception { return NullConverter.NULL.convert(getClass(), (String) null); } } diff --git a/core/src/test/java/net/cactusthorn/routing/convert/BooleanConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/BooleanConverterTest.java index 14de327..f3caace 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/BooleanConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/BooleanConverterTest.java @@ -7,7 +7,7 @@ public class BooleanConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { BooleanConverter c = new BooleanConverter(); Boolean result = (Boolean) c.convert(Boolean.class, "true"); assertTrue(result); @@ -18,7 +18,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { BooleanConverter c = new BooleanConverter(); String[] value = new String[] { "true", null, "false" }; Boolean[] valuesAsBoolean = new Boolean[] { true, null, false }; @@ -27,7 +27,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { BooleanConverter c = new BooleanConverter(); Object result = (Object) c.convert(Boolean.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/ByteConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/ByteConverterTest.java index 306a09f..dfa61fb 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/ByteConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/ByteConverterTest.java @@ -9,7 +9,7 @@ public class ByteConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { ByteConverter c = new ByteConverter(); Byte result = (Byte) c.convert(Byte.class, "125"); assertEquals((byte)125, result); @@ -20,7 +20,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { ByteConverter c = new ByteConverter(); String[] value = new String[] { "125", " ", "16" }; Byte[] valuesAsByte = new Byte[] { 125, null, 16 }; @@ -29,7 +29,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { ByteConverter c = new ByteConverter(); Object result = (Object) c.convert(Byte.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/CharacterConvertorTest.java b/core/src/test/java/net/cactusthorn/routing/convert/CharacterConvertorTest.java index 8f83624..4e1b29a 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/CharacterConvertorTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/CharacterConvertorTest.java @@ -9,7 +9,7 @@ public class CharacterConvertorTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { CharacterConverter c = new CharacterConverter(); Character result = (Character) c.convert(Character.class, "125"); assertEquals('1', result); @@ -20,7 +20,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { CharacterConverter c = new CharacterConverter(); String[] value = new String[] { "215", " ", "61" }; Character[] valuesAsCharacter = new Character[] { '2', ' ', '6' }; @@ -29,7 +29,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { CharacterConverter c = new CharacterConverter(); Object result = (Object) c.convert(Character.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/ConsumerConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/ConsumerConverterTest.java index a50f924..bcf9bb6 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/ConsumerConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/ConsumerConverterTest.java @@ -25,6 +25,6 @@ public void array() { @Test // public void error() { ConsumerConverter c = new ConsumerConverter("aa/bb", EXCEPTION_CONSUMER); - assertThrows(ConverterException.class, () -> c.convert(null, java.util.Date.class, (String)null)); + assertThrows(RuntimeException.class, () -> c.convert(null, java.util.Date.class, (String)null)); } } diff --git a/core/src/test/java/net/cactusthorn/routing/convert/ConvertersHolderTest.java b/core/src/test/java/net/cactusthorn/routing/convert/ConvertersHolderTest.java index 822e7b7..f8733fe 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/ConvertersHolderTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/ConvertersHolderTest.java @@ -20,7 +20,7 @@ public class ConvertersHolderTest { }; @Test // - public void register() throws ConverterException { + public void register() throws Exception { ConvertersHolder holder = new ConvertersHolder(); holder.register(java.util.Date.class, TEST_CONVERTER); Converter converter = holder.findConverter(java.util.Date.class).get(); @@ -33,7 +33,7 @@ public static enum TestEnum { } @Test // - public void valueOf() throws ConverterException { + public void valueOf() throws Exception { ConvertersHolder holder = new ConvertersHolder(); Converter converter = holder.findConverter(TestEnum.class).get(); assertEquals(StaticStringMethodConverter.class, converter.getClass()); @@ -70,14 +70,14 @@ public void consumerNotFound() { } @Test // - public void fromString() throws ConverterException { + public void fromString() throws Exception { ConvertersHolder holder = new ConvertersHolder(); Converter converter = holder.findConverter(UUID.class).get(); assertEquals(StaticStringMethodConverter.class, converter.getClass()); } @Test // - public void constructor() throws ConverterException { + public void constructor() throws Exception { ConvertersHolder holder = new ConvertersHolder(); Converter converter = holder.findConverter(StringBuilder.class).get(); assertEquals(StringConstructorConverter.class, converter.getClass()); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/DoubleConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/DoubleConverterTest.java index 8acde6f..87418f6 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/DoubleConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/DoubleConverterTest.java @@ -9,7 +9,7 @@ public class DoubleConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { DoubleConverter c = new DoubleConverter(); Double result = (Double) c.convert(Double.class, "125.5"); assertEquals(125.5d, result); @@ -20,7 +20,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { DoubleConverter c = new DoubleConverter(); String[] value = new String[] { "125.5", " ", "16.3" }; Double[] valuesAsDouble = new Double[] { 125.5d, null, 16.3d }; @@ -29,7 +29,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { DoubleConverter c = new DoubleConverter(); Object result = (Object) c.convert(Double.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/FloatConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/FloatConverterTest.java index 946522e..9ee3afa 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/FloatConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/FloatConverterTest.java @@ -9,7 +9,7 @@ public class FloatConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { FloatConverter c = new FloatConverter(); Float result = (Float) c.convert(Float.class, "125.5"); assertEquals(125.5f, result); @@ -20,7 +20,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { FloatConverter c = new FloatConverter(); String[] value = new String[] { "125.5", " ", "16.3" }; Float[] valuesAsFloat = new Float[] { 125.5f, null, 16.3f }; @@ -29,7 +29,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { FloatConverter c = new FloatConverter(); Object result = (Object) c.convert(Float.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/IntegerConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/IntegerConverterTest.java index 56af3d4..5329558 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/IntegerConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/IntegerConverterTest.java @@ -7,7 +7,7 @@ public class IntegerConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { IntegerConverter c = new IntegerConverter(); Integer result = (Integer) c.convert(Integer.class, "125"); assertEquals(125, result); @@ -18,7 +18,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { IntegerConverter c = new IntegerConverter(); String[] value = new String[] { "125", " ", "3456" }; Integer[] valuesAsInt = new Integer[] { 125, null, 3456 }; @@ -27,7 +27,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { IntegerConverter c = new IntegerConverter(); Object result = (Object) c.convert(Integer.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/LongConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/LongConverterTest.java index c5c80b3..f8a1a69 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/LongConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/LongConverterTest.java @@ -9,7 +9,7 @@ public class LongConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { LongConverter c = new LongConverter(); Long result = (Long) c.convert(Long.class, "125"); assertEquals(125L, result); @@ -20,7 +20,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { LongConverter c = new LongConverter(); String[] value = new String[] { "125", " ", "16" }; Long[] valuesAsLong = new Long[] { 125L, null, 16L }; @@ -29,7 +29,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { LongConverter c = new LongConverter(); Object result = (Object) c.convert(Long.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/NullConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/NullConverterTest.java index 98da857..63b6863 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/NullConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/NullConverterTest.java @@ -7,21 +7,21 @@ public class NullConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { NullConverter c = new NullConverter(); Object result = c.convert(Object.class, "1"); assertNull(result); } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { NullConverter c = new NullConverter(); Object result = c.convert(Object.class, new String[] { "125", "3456" }); assertNull(result); } @Test // - public void testPrimitive() throws ConverterException { + public void testPrimitive() throws Exception { NullConverter c = new NullConverter(); byte b = (byte) c.convert(Byte.TYPE, (String) null); assertEquals((byte) 0, b); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/PrimitiveConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/PrimitiveConverterTest.java index 435421f..8c50da5 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/PrimitiveConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/PrimitiveConverterTest.java @@ -7,7 +7,7 @@ public class PrimitiveConverterTest { @Test // - public void byteTest() throws ConverterException { + public void byteTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); byte v = (byte) c.convert(Byte.TYPE, "1"); assertEquals((byte) 1, v); @@ -18,7 +18,7 @@ public void byteTest() throws ConverterException { } @Test // - public void byteArrayTest() throws ConverterException { + public void byteArrayTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); String[] value = new String[] { "125", "34" }; byte[] valuesAsByte = new byte[] { (byte) 125, (byte) 34 }; @@ -27,14 +27,14 @@ public void byteArrayTest() throws ConverterException { } @Test // - public void byteNullArrayTest() throws ConverterException { + public void byteNullArrayTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); Object result = c.convert(Byte.TYPE, (String[]) null); assertNull(result); } @Test // - public void shortTest() throws ConverterException { + public void shortTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); short v = (short) c.convert(Short.TYPE, "1"); assertEquals((short) 1, v); @@ -45,7 +45,7 @@ public void shortTest() throws ConverterException { } @Test // - public void intTest() throws ConverterException { + public void intTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); int v = (int) c.convert(Integer.TYPE, "1"); assertEquals(1, v); @@ -56,7 +56,7 @@ public void intTest() throws ConverterException { } @Test // - public void longTest() throws ConverterException { + public void longTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); long v = (long) c.convert(Long.TYPE, "1"); assertEquals(1L, v); @@ -67,7 +67,7 @@ public void longTest() throws ConverterException { } @Test // - public void floatTest() throws ConverterException { + public void floatTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); float v = (float) c.convert(Float.TYPE, "1.1"); assertEquals(1.1f, v); @@ -78,7 +78,7 @@ public void floatTest() throws ConverterException { } @Test // - public void doubleTest() throws ConverterException { + public void doubleTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); double v = (double) c.convert(Double.TYPE, "1.1"); assertEquals(1.1d, v); @@ -89,7 +89,7 @@ public void doubleTest() throws ConverterException { } @Test // - public void charTest() throws ConverterException { + public void charTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); char v = (char) c.convert(Character.TYPE, "abc"); assertEquals('a', v); @@ -100,7 +100,7 @@ public void charTest() throws ConverterException { } @Test // - public void boolTest() throws ConverterException { + public void boolTest() throws Exception { PrimitiveConverter c = new PrimitiveConverter(); boolean v = (boolean) c.convert(Boolean.TYPE, "true"); assertTrue(v); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/ShortConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/ShortConverterTest.java index f618434..8f18dc7 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/ShortConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/ShortConverterTest.java @@ -9,7 +9,7 @@ public class ShortConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { ShortConverter c = new ShortConverter(); Short result = (Short) c.convert(Short.class, "125"); assertEquals((short)125, result); @@ -20,7 +20,7 @@ public void test() throws ConverterException { } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { ShortConverter c = new ShortConverter(); String[] value = new String[] { "125", " ", "3456" }; Short[] valuesAsShort = new Short[] { 125, null, 3456 }; @@ -29,7 +29,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { ShortConverter c = new ShortConverter(); Object result = (Object) c.convert(Short.class, (String[]) null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/StaticStringMethodConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/StaticStringMethodConverterTest.java index 80d2a8e..72518b1 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/StaticStringMethodConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/StaticStringMethodConverterTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.*; +import java.lang.reflect.InvocationTargetException; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -27,28 +28,29 @@ public void support() { } @Test // - public void invoke() throws ConverterException { + public void invoke() throws Exception { StaticStringMethodConverter c = new StaticStringMethodConverter("valueOf"); c.register(Integer.class); assertEquals(123, c.convert(null, Integer.class, "123")); } @Test // - public void wrong() { + public void wrong() throws Exception { StaticStringMethodConverter c = new StaticStringMethodConverter("valueOf"); c.register(Integer.class); - assertThrows(ConverterException.class, () -> c.convert(Integer.class, "12dd")); + Exception exception = assertThrows(InvocationTargetException.class, () -> c.convert(Integer.class, "12dd")); + assertEquals(NumberFormatException.class, exception.getCause().getClass()); } @Test // - public void nullValue() throws ConverterException { + public void nullValue() throws Exception { StaticStringMethodConverter c = new StaticStringMethodConverter("valueOf"); c.register(Integer.class); @SuppressWarnings("unused") Integer i = (Integer) c.convert(Integer.class, (String) null); } @Test // - public void fromString() throws ConverterException { + public void fromString() throws Exception { StaticStringMethodConverter c = new StaticStringMethodConverter("fromString"); c.register(UUID.class); UUID uuid = (UUID) c.convert(UUID.class, "46400000-8cc0-11bd-b43e-10d46e4ef14d"); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/StringConstructorConvertorTest.java b/core/src/test/java/net/cactusthorn/routing/convert/StringConstructorConvertorTest.java index 682f880..c272190 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/StringConstructorConvertorTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/StringConstructorConvertorTest.java @@ -9,7 +9,7 @@ public class StringConstructorConvertorTest { @Test // - public void simple() throws ConverterException { + public void simple() throws Exception { StringConstructorConverter c = new StringConstructorConverter(); c.register(StringBuilder.class); StringBuilder s = (StringBuilder) c.convert(StringBuilder.class, "test it"); @@ -17,13 +17,13 @@ public void simple() throws ConverterException { } @Test // - public void notSupported() throws ConverterException { + public void notSupported() throws Exception { StringConstructorConverter c = new StringConstructorConverter(); assertFalse(c.register(Math.class)); } @Test // - public void nullTest() throws ConverterException { + public void nullTest() throws Exception { StringConstructorConverter c = new StringConstructorConverter(); c.register(StringBuilder.class); StringBuilder s = (StringBuilder) c.convert(StringBuilder.class, (String) null); @@ -31,7 +31,7 @@ public void nullTest() throws ConverterException { } @Test // - public void array() throws ConverterException { + public void array() throws Exception { StringConstructorConverter c = new StringConstructorConverter(); c.register(StringBuilder.class); StringBuilder[] s = (StringBuilder[]) c.convert(StringBuilder.class, new String[] { "aaa", "bbb" }); diff --git a/core/src/test/java/net/cactusthorn/routing/convert/StringConverterTest.java b/core/src/test/java/net/cactusthorn/routing/convert/StringConverterTest.java index f7a008d..22bdf18 100644 --- a/core/src/test/java/net/cactusthorn/routing/convert/StringConverterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/convert/StringConverterTest.java @@ -8,14 +8,14 @@ public class StringConverterTest { @Test // - public void test() throws ConverterException { + public void test() throws Exception { StringConverter c = new StringConverter(); String result = (String) c.convert(String.class, "abc"); assertEquals("abc", result); } @Test // - public void testArray() throws ConverterException { + public void testArray() throws Exception { StringConverter c = new StringConverter(); String[] value = new String[] { "abc", "xyz" }; String[] result = (String[]) c.convert(String.class, value); @@ -23,7 +23,7 @@ public void testArray() throws ConverterException { } @Test // - public void testNullArray() throws ConverterException { + public void testNullArray() throws Exception { StringConverter c = new StringConverter(); Object result = (Object)c.convert(String.class, (String[])null); assertNull(result); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/BodyParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/BodyParameterTest.java index 2788d9c..f6053bd 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/BodyParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/BodyParameterTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test; +import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.convert.ConvertersHolder; public class BodyParameterTest { @@ -23,7 +24,7 @@ public java.util.Date context(java.util.Date date) { public void exception() { Method m = findMethod("context"); Parameter p = m.getParameters()[0]; - assertThrows(IllegalArgumentException.class, () -> new BodyParameter(m, p, HOLDER, "aa/bb")); + assertThrows(RoutingInitializationException.class, () -> new BodyParameter(m, p, HOLDER, "aa/bb")); } private Method findMethod(String methodName) { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java index 91b77d7..ded9d34 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java @@ -14,7 +14,6 @@ import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.annotation.CookieParam; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class CookieParamParameterTest { @@ -38,7 +37,7 @@ void setUp() { } @Test // - public void simple() throws ConverterException { + public void simple() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -51,14 +50,14 @@ public void simple() throws ConverterException { } @Test // - public void wrongType() throws ConverterException { + public void wrongType() throws Exception { Method m = findMethod("wrongType"); Parameter p = m.getParameters()[0]; assertThrows(RoutingInitializationException.class, () -> MethodParameter.Factory.create(m, p, HOLDER, "*/*")); } @Test // - public void nullCookies() throws ConverterException { + public void nullCookies() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -69,12 +68,12 @@ public void nullCookies() throws ConverterException { } @Test // - public void nullCookie() throws ConverterException { + public void nullCookie() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); - Cookie[] cookies = new Cookie[] {new Cookie("xxx", "xxx")}; + Cookie[] cookies = new Cookie[] { new Cookie("xxx", "xxx") }; Mockito.when(request.getCookies()).thenReturn(cookies); Cookie cookie = (Cookie) mp.findValue(request, null, null, null); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java index 900e4d8..94f7da2 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java @@ -42,7 +42,7 @@ void setUp() { } @Test // - public void simple() throws ConverterException { + public void simple() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "application/x-www-form-urlencoded"); @@ -53,7 +53,7 @@ public void simple() throws ConverterException { } @Test // - public void defaultArray() throws ConverterException { + public void defaultArray() throws Exception { Method m = findMethod("defaultArray"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "application/x-www-form-urlencoded"); @@ -65,7 +65,7 @@ public void defaultArray() throws ConverterException { } @Test // - public void defaultValue() throws ConverterException { + public void defaultValue() throws Exception { Method m = findMethod("defaultValue"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "application/x-www-form-urlencoded"); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java index 030b870..98c053b 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.List; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Part; @@ -93,7 +92,7 @@ void setUp() { } @Test // - public void simple() throws ConverterException, IOException, ServletException { + public void simple() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -107,7 +106,7 @@ public void simple() throws ConverterException, IOException, ServletException { } @Test // - public void notfound() throws ConverterException, IOException, ServletException { + public void notfound() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -118,7 +117,7 @@ public void notfound() throws ConverterException, IOException, ServletException } @Test // - public void notfound2() throws ConverterException, IOException, ServletException { + public void notfound2() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java index 856cf95..b3c73cc 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java @@ -15,7 +15,6 @@ import net.cactusthorn.routing.RoutingInitializationException; import net.cactusthorn.routing.annotation.DefaultValue; import net.cactusthorn.routing.annotation.HeaderParam; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class HeaderParamParameterTest { @@ -42,7 +41,7 @@ void setUp() { } @Test // - public void simple() throws ConverterException { + public void simple() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -53,7 +52,7 @@ public void simple() throws ConverterException { } @Test // - public void defaultValue() throws ConverterException { + public void defaultValue() throws Exception { Method m = findMethod("defaultValue"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -64,7 +63,7 @@ public void defaultValue() throws ConverterException { } @Test // - public void simpleArray() throws ConverterException { + public void simpleArray() { Method m = findMethod("simpleArray"); Parameter p = m.getParameters()[0]; assertThrows(RoutingInitializationException.class, () -> MethodParameter.Factory.create(m, p, HOLDER, "*/*")); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java index d4b34c6..8b9f5da 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java @@ -25,7 +25,6 @@ import net.cactusthorn.routing.RoutingConfig.ConfigProperty; import net.cactusthorn.routing.PathTemplate.PathValues; import net.cactusthorn.routing.annotation.*; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class MethodInvokerTest { @@ -115,7 +114,7 @@ void mock() throws IOException { } @Test // - public void invokeM1() throws ConverterException { + public void invokeM1() throws Exception { Method method = findMethod("m1"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -129,7 +128,7 @@ public void invokeM1() throws ConverterException { } @Test // - public void invokeM0() throws ConverterException { + public void invokeM0() throws Exception { Method method = findMethod("m0"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -142,7 +141,7 @@ public void invokeM0() throws ConverterException { } @Test // - public void invokeM2() throws ConverterException { + public void invokeM2() throws Exception { Method method = findMethod("m2"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -155,7 +154,7 @@ public void invokeM2() throws ConverterException { } @Test // - public void invokeM3() throws ConverterException { + public void invokeM3() throws Exception { Method method = findMethod("m3"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -169,7 +168,7 @@ public void invokeM3() throws ConverterException { } @Test // - public void invokeM4() throws ConverterException { + public void invokeM4() throws Exception { Method method = findMethod("m4"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -180,7 +179,7 @@ public void invokeM4() throws ConverterException { } @Test // - public void invokeM5() throws ConverterException { + public void invokeM5() throws Exception { Method method = findMethod("m5"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -191,7 +190,7 @@ public void invokeM5() throws ConverterException { } @Test // - public void invokeM6() throws ConverterException { + public void invokeM6() throws Exception { Method method = findMethod("m6"); MethodInvoker caller = new MethodInvoker(EntryPoint1.class, method, provider, holder, "*/*", configProperties); @@ -202,7 +201,7 @@ public void invokeM6() throws ConverterException { } @Test // - public void invokeM7() throws IOException, ConverterException { + public void invokeM7() throws Exception { BufferedReader reader = new BufferedReader(new StringReader("TO HAVE BODY")); Mockito.when(request.getReader()).thenReturn(reader); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java index fa6272f..7874a20 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java @@ -14,7 +14,6 @@ import net.cactusthorn.routing.RequestData; import net.cactusthorn.routing.annotation.DefaultValue; import net.cactusthorn.routing.annotation.PathParam; -import net.cactusthorn.routing.convert.ConverterException; import net.cactusthorn.routing.convert.ConvertersHolder; public class PathParamParameterTest { @@ -64,7 +63,7 @@ public void math() { } @Test // - public void defaultValue() throws ConverterException { + public void defaultValue() throws Exception { Method m = findMethod("defaultValue"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -79,7 +78,7 @@ public void defaultValue() throws ConverterException { } @Test // - public void simple() throws ConverterException { + public void simple() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -94,7 +93,7 @@ public void simple() throws ConverterException { } @Test // - public void simpleWithValue() throws ConverterException { + public void simpleWithValue() throws Exception { Method m = findMethod("simple"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java index ef49c83..12e7ee8 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java @@ -61,14 +61,14 @@ void setUp() { } @Test // - public void collectionNoGeneric() throws ConverterException { + public void collectionNoGeneric() { Method m = findMethod("collectionNoGeneric"); Parameter p = m.getParameters()[0]; assertThrows(RoutingInitializationException.class, () -> MethodParameter.Factory.create(m, p, HOLDER, "*/*")); } @Test // - public void linkedList() throws ConverterException { + public void linkedList() throws Exception { Method m = findMethod("linkedList"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -84,7 +84,7 @@ public void linkedList() throws ConverterException { } @Test // - public void sortedSet() throws ConverterException { + public void sortedSet() throws Exception { Method m = findMethod("sortedSet"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -100,7 +100,7 @@ public void sortedSet() throws ConverterException { } @Test // - public void set() throws ConverterException { + public void set() throws Exception { Method m = findMethod("set"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -115,7 +115,7 @@ public void set() throws ConverterException { } @Test // - public void list() throws ConverterException { + public void list() throws Exception { Method m = findMethod("list"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -131,7 +131,7 @@ public void list() throws ConverterException { } @Test // - public void collection() throws ConverterException { + public void collection() throws Exception { Method m = findMethod("collection"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -147,7 +147,7 @@ public void collection() throws ConverterException { } @Test // - public void nullCcollection() throws ConverterException { + public void nullCcollection() throws Exception { Method m = findMethod("collection"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -162,7 +162,7 @@ public void nullCcollection() throws ConverterException { } @Test // - public void array() throws ConverterException { + public void array() throws Exception { Method m = findMethod("array"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -182,7 +182,7 @@ public void multiArray() { } @Test // - public void wrong() throws ConverterException { + public void wrong() { Method m = findMethod("wrong"); Parameter p = m.getParameters()[0]; MethodParameter mp = MethodParameter.Factory.create(m, p, HOLDER, "*/*"); @@ -190,7 +190,7 @@ public void wrong() throws ConverterException { Mockito.when(request.getParameter("val")).thenReturn("abc"); RequestData data = new RequestData(null); - assertThrows(ConverterException.class, () -> mp.findValue(request, null, null, data)); + assertThrows(NumberFormatException.class, () -> mp.findValue(request, null, null, data)); } private Method findMethod(String methodName) { diff --git a/demo-jetty/pom.xml b/demo-jetty/pom.xml index 0e353e4..917fbb3 100644 --- a/demo-jetty/pom.xml +++ b/demo-jetty/pom.xml @@ -7,7 +7,7 @@ net.cactusthorn.routing root - 0.23 + 0.24 demo-jetty diff --git a/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/LocalDateConverter.java b/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/LocalDateConverter.java index 9840900..0493de7 100644 --- a/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/LocalDateConverter.java +++ b/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/LocalDateConverter.java @@ -6,7 +6,6 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; public class LocalDateConverter implements Converter { @@ -17,11 +16,7 @@ public LocalDate convert(RequestData requestData, Class type, String value) t if (value == null || value.trim().isEmpty()) { return null; } - try { - return LocalDate.parse(value, FORMATTER); - } catch (DateTimeParseException e) { - throw new ConverterException("LocalDate converting failed", e); - } + return LocalDate.parse(value, FORMATTER); } } diff --git a/json-gson/pom.xml b/json-gson/pom.xml index 3c42d8e..e261264 100644 --- a/json-gson/pom.xml +++ b/json-gson/pom.xml @@ -7,7 +7,7 @@ net.cactusthorn.routing root - 0.23 + 0.24 json-gson diff --git a/pom.xml b/pom.xml index 3787a60..6e1dab6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.cactusthorn.routing root - 0.23 + 0.24 pom Routing :: Root diff --git a/thymeleaf/pom.xml b/thymeleaf/pom.xml index 0e4b5a5..775b259 100644 --- a/thymeleaf/pom.xml +++ b/thymeleaf/pom.xml @@ -7,7 +7,7 @@ net.cactusthorn.routing root - 0.23 + 0.24 thymeleaf