Skip to content

Commit

Permalink
1.9.5 fixed issue with #724
Browse files Browse the repository at this point in the history
  • Loading branch information
MammatusPlatypus committed Jun 8, 2016
1 parent 3b91474 commit aa6b711
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 38 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,9 @@ public MultiMap<String, String> headers() {

public MultiMap<String, String> formParams() {
if (formParams == null) {

formParams = formParamsSupplier.get();

}

return formParams;

}

public MultiMap<String, String> getFormParams() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ public MethodCall<Object> 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;
Expand All @@ -155,9 +154,7 @@ public MethodCall<Object> 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());
Expand All @@ -166,7 +163,6 @@ public MethodCall<Object> transformByPosition(final HttpRequest request,
errorsList.add(sputs("Unable to find required header param", namedParam.getName()));
break loop;
}

if (Str.isEmpty(value)) {
value = namedParam.getDefaultValue();
}
Expand All @@ -185,9 +181,7 @@ public MethodCall<Object> 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()));
Expand All @@ -204,12 +198,9 @@ public MethodCall<Object> 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()) {
Expand All @@ -225,7 +216,6 @@ public MethodCall<Object> transformByPosition(final HttpRequest request,
break loop;
}
}

if (Str.isEmpty(value)) {
value = positionalParam.getDefaultValue();
}
Expand All @@ -235,59 +225,40 @@ public MethodCall<Object> 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<Map>) value);
} else {

if (value instanceof Map) {
value = MapObjectConversion.fromMap((Map) value, parameterMeta.getClassType());
} else {
value = Conversions.coerce(parameterMeta.getClassType(), value);
}
}
} catch (Exception exception) {

handleMehtodTransformError(errorsList, methodCallBuilder, exception);
}
} else {

try {
if (parameterMeta.isArray() || parameterMeta.isCollection()) {
value = jsonMapper.get().fromJsonArray(value.toString(), parameterMeta.getComponentClass());
Expand All @@ -299,7 +270,6 @@ public MethodCall<Object> transformByPosition(final HttpRequest request,
value = jsonMapper.get().fromJson(value.toString(), parameterMeta.getClassType());
}
} catch (Exception exception) {

handleMehtodTransformError(errorsList, methodCallBuilder, exception);
}
}
Expand All @@ -310,7 +280,6 @@ public MethodCall<Object> transformByPosition(final HttpRequest request,
}
}
break;

case BODY_BY_POSITION:
BodyArrayParam bodyArrayParam = (BodyArrayParam) parameterMeta.getParam();
value = request.body();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import io.advantageous.qbit.util.PortUtils;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;

public class Bug724 {

@Test
Expand All @@ -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)
Expand Down

0 comments on commit aa6b711

Please sign in to comment.