Skip to content

Commit 5461ac9

Browse files
2 parents de18e95 + 9092d36 commit 5461ac9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/java/com/thinkinglogic/rest/mock/ResponseBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ protected int getStatus() {
274274
return 500;
275275
}
276276
try {
277-
return Integer.parseInt(IOUtils.toString(stream, UTF8));
277+
return Integer.parseInt(IOUtils.toString(stream, UTF8).trim());
278278
} catch (IOException | RuntimeException e) {
279279
logger.error("Unable to get status from stream", e);
280280
return 500;
@@ -427,7 +427,7 @@ protected String matchDirHeader(final String headerName) {
427427
if (resource != null) {
428428
return shortType;
429429
}
430-
// try to find type/default.body
430+
// try to find type/path.properties
431431
filename = derivedPath + shortType + "/" + PATH_PROPERTIES_FILE;
432432
logger.debug("Trying to match Accept header '" + type + "': Looking for " + filename);
433433
resource = this.getClass().getResource(filename);

src/java/com/thinkinglogic/rest/mock/RestServlet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.BufferedReader;
44
import java.io.IOException;
5+
import java.io.UnsupportedEncodingException;
6+
import java.net.URLDecoder;
57
import java.util.Enumeration;
68
import java.util.Map;
79
import java.util.TreeMap;
@@ -21,6 +23,7 @@ public class RestServlet extends HttpServlet {
2123
private static final Logger logger = Logger.getLogger(RestServlet.class);
2224

2325
private static final long serialVersionUID = 1L;
26+
private static final String UTF8 = "UTF-8";
2427

2528
public static final String GET = "GET";
2629
public static final String PUT = "PUT";
@@ -132,15 +135,16 @@ protected String getBody(final HttpServletRequest request, final String requestM
132135
/**
133136
* @param request the current request.
134137
* @return the query parameters, as a map.
138+
* @throws UnsupportedEncodingException
135139
*/
136-
protected Map<String, String> getQueryParams(final HttpServletRequest request) {
140+
protected Map<String, String> getQueryParams(final HttpServletRequest request) throws UnsupportedEncodingException {
137141
String queryString = notNullString(request.getQueryString());
138142
Map<String, String> queryParams = new TreeMap<>();
139143
String[] split = queryString.split("&");
140144
for (String string : split) {
141145
String[] strings = string.split("=");
142146
if (strings.length == 2) {
143-
queryParams.put(strings[0], strings[1]);
147+
queryParams.put(URLDecoder.decode(strings[0], UTF8), URLDecoder.decode(strings[1], UTF8));
144148
}
145149
}
146150
return queryParams;

0 commit comments

Comments
 (0)