diff --git a/build.gradle b/build.gradle index 2230f69a..96aa4c3f 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ */ ext { - projectVersion = '1.9.4' + projectVersion = '1.9.5' boonVersion = '0.6.2' boonGroup = "io.advantageous.boon" springFrameworkVersion = '4.2.5.RELEASE' diff --git a/qbit/core/src/main/java/io/advantageous/qbit/http/request/HttpRequest.java b/qbit/core/src/main/java/io/advantageous/qbit/http/request/HttpRequest.java index 9a8e6e19..86154ec3 100644 --- a/qbit/core/src/main/java/io/advantageous/qbit/http/request/HttpRequest.java +++ b/qbit/core/src/main/java/io/advantageous/qbit/http/request/HttpRequest.java @@ -104,13 +104,9 @@ public MultiMap headers() { public MultiMap formParams() { if (formParams == null) { - formParams = formParamsSupplier.get(); - } - return formParams; - } public MultiMap getFormParams() { @@ -280,4 +276,13 @@ public String toString() { ", handled=" + handled + '}'; } + + public String getParam(String name) { + String value = null; + value = this.params().get(name); + if (value == null) { + value = this.formParams().get(name); + } + return value; + } } diff --git a/qbit/core/src/main/java/io/advantageous/qbit/meta/transformer/StandardRequestTransformer.java b/qbit/core/src/main/java/io/advantageous/qbit/meta/transformer/StandardRequestTransformer.java index 46de5b9d..9acbca12 100644 --- a/qbit/core/src/main/java/io/advantageous/qbit/meta/transformer/StandardRequestTransformer.java +++ b/qbit/core/src/main/java/io/advantageous/qbit/meta/transformer/StandardRequestTransformer.java @@ -145,8 +145,7 @@ public MethodCall transformByPosition(final HttpRequest request, switch (paramType) { case REQUEST: namedParam = ((NamedParam) parameterMeta.getParam()); - value = request.params().get(namedParam.getName()); - + value = request.getParam(namedParam.getName()); if (namedParam.isRequired() && Str.isEmpty(value)) { errorsList.add(sputs("Unable to find required request param", namedParam.getName())); break loop; @@ -155,9 +154,7 @@ public MethodCall transformByPosition(final HttpRequest request, if (Str.isEmpty(value)) { value = namedParam.getDefaultValue(); } - value = value != null ? decodeURLEncoding(value.toString()) : value; - break; case HEADER: namedParam = ((NamedParam) parameterMeta.getParam()); @@ -166,7 +163,6 @@ public MethodCall transformByPosition(final HttpRequest request, errorsList.add(sputs("Unable to find required header param", namedParam.getName())); break loop; } - if (Str.isEmpty(value)) { value = namedParam.getDefaultValue(); } @@ -185,9 +181,7 @@ public MethodCall transformByPosition(final HttpRequest request, break; case PATH_BY_NAME: URINamedParam uriNamedParam = ((URINamedParam) parameterMeta.getParam()); - final String[] split = Str.split(request.address(), '/'); - if (uriNamedParam.getIndexIntoURI() >= split.length) { if (uriNamedParam.isRequired()) { errorsList.add(sputs("Unable to find required path param", uriNamedParam.getName())); @@ -204,12 +198,9 @@ public MethodCall transformByPosition(final HttpRequest request, } value = value != null ? decodeURLEncoding(value.toString()) : value; break; - case PATH_BY_POSITION: URIPositionalParam positionalParam = ((URIPositionalParam) parameterMeta.getParam()); - final String[] pathSplit = Str.split(request.address(), '/'); - value = null; if (positionalParam.getIndexIntoURI() >= pathSplit.length) { if (positionalParam.isRequired()) { @@ -225,7 +216,6 @@ public MethodCall transformByPosition(final HttpRequest request, break loop; } } - if (Str.isEmpty(value)) { value = positionalParam.getDefaultValue(); } @@ -235,47 +225,30 @@ public MethodCall transformByPosition(final HttpRequest request, case BODY: final BodyParam bodyParam = (BodyParam) parameterMeta.getParam(); value = request.body(); - final String contentType = request.getContentType(); - if (isJsonContent(contentType)) { - - if (value instanceof byte[]) { final byte[] bytes = (byte[]) value; value = new String(bytes, StandardCharsets.UTF_8); } - if (bodyParam.isRequired() && Str.isEmpty(value)) { - errorsList.add("Unable to find body"); break loop; - } - - if (Str.isEmpty(value)) { value = bodyParam.getDefaultValue(); - - } - if (byPosition) { - value = jsonMapper.get().fromJson(value.toString()); value = ValueContainer.toObject(value); - if (value instanceof List) { value = ((List) value).get(index); value = ValueContainer.toObject(value); } - try { if (parameterMeta.isArray() || parameterMeta.isCollection()) { - value = MapObjectConversion.convertListOfMapsToObjects(parameterMeta.getComponentClass(), (List) value); } else { - if (value instanceof Map) { value = MapObjectConversion.fromMap((Map) value, parameterMeta.getClassType()); } else { @@ -283,11 +256,9 @@ public MethodCall transformByPosition(final HttpRequest request, } } } catch (Exception exception) { - handleMehtodTransformError(errorsList, methodCallBuilder, exception); } } else { - try { if (parameterMeta.isArray() || parameterMeta.isCollection()) { value = jsonMapper.get().fromJsonArray(value.toString(), parameterMeta.getComponentClass()); @@ -299,7 +270,6 @@ public MethodCall transformByPosition(final HttpRequest request, value = jsonMapper.get().fromJson(value.toString(), parameterMeta.getClassType()); } } catch (Exception exception) { - handleMehtodTransformError(errorsList, methodCallBuilder, exception); } } @@ -310,7 +280,6 @@ public MethodCall transformByPosition(final HttpRequest request, } } break; - case BODY_BY_POSITION: BodyArrayParam bodyArrayParam = (BodyArrayParam) parameterMeta.getParam(); value = request.body(); diff --git a/qbit/vertx/src/test/java/io/advantageous/qbit/vertx/bugs/Bug724.java b/qbit/vertx/src/test/java/io/advantageous/qbit/vertx/bugs/Bug724.java index cafd1233..62432eb0 100644 --- a/qbit/vertx/src/test/java/io/advantageous/qbit/vertx/bugs/Bug724.java +++ b/qbit/vertx/src/test/java/io/advantageous/qbit/vertx/bugs/Bug724.java @@ -14,6 +14,8 @@ import io.advantageous.qbit.util.PortUtils; import org.junit.Test; +import static junit.framework.Assert.assertEquals; + public class Bug724 { @Test @@ -34,9 +36,10 @@ public void test() { final HttpTextResponse httpTextResponse = httpClient.sendRequestAndWait(httpRequest); - //assertEquals("was=Rick Loves Java", httpTextResponse.body()); + assertEquals("\"was=Rick Loves Java\"", httpTextResponse.body()); } + @RequestMapping("/") public static class MyService { @RequestMapping(value = "/reverse", method = RequestMethod.POST, code = 200)