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 extends Collection