use of io.apiman.gateway.engine.beans.util.QueryMap in project apiman-plugins by apiman.
the class JsonpPolicyTest method shouldNotSaveCallbackFunctionNameInContextWhenNotPresent.
@Test
public void shouldNotSaveCallbackFunctionNameInContextWhenNotPresent() throws Exception {
// given
JsonpConfigBean config = new JsonpConfigBean();
config.setCallbackParamName("testParam");
QueryMap queryParams = new QueryMap();
ApiRequest request = new ApiRequest();
request.setQueryParams(queryParams);
IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
// when
jsonpPolicy.doApply(request, sContext, config, chain);
// then
assertNull(sContext.getAttribute("callbackFunctionName", null));
verify(chain).doApply(request);
}
use of io.apiman.gateway.engine.beans.util.QueryMap in project apiman by apiman.
the class GatewayServlet method parseApiRequestQueryParams.
/**
* Parses the query string into a map.
* @param queryString
*/
protected static final QueryMap parseApiRequestQueryParams(String queryString) {
QueryMap rval = new QueryMap();
if (queryString != null) {
try {
// $NON-NLS-1$
String[] pairSplit = queryString.split("&");
for (String paramPair : pairSplit) {
// $NON-NLS-1$
int idx = paramPair.indexOf("=");
String key, value;
if (idx != -1) {
// $NON-NLS-1$
key = URLDecoder.decode(paramPair.substring(0, idx), "UTF-8");
// $NON-NLS-1$
value = URLDecoder.decode(paramPair.substring(idx + 1), "UTF-8");
} else {
// $NON-NLS-1$
key = URLDecoder.decode(paramPair, "UTF-8");
value = null;
}
rval.add(key, value);
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
return rval;
}
use of io.apiman.gateway.engine.beans.util.QueryMap in project apiman by apiman.
the class GatewayServlet method readRequest.
/**
* Reads a {@link ApiRequest} from information found in the inbound
* portion of the http request.
* @param request the undertow http server request
* @return a valid {@link ApiRequest}
* @throws IOException
*/
protected ApiRequest readRequest(HttpServletRequest request) throws Exception {
// parseApiRequestPath(request);
ApiRequestPathInfo pathInfo = getEngine().getApiRequestPathParser().parseEndpoint(request.getPathInfo(), wrapMultiMap(request));
if (pathInfo.orgId == null) {
// $NON-NLS-1$
throw new Exception(Messages.i18n.format("GatewayServlet.InvalidApiEndpoint"));
}
QueryMap queryParams = parseApiRequestQueryParams(request.getQueryString());
String apiKey = getApiKey(request, queryParams);
ApiRequest srequest = GatewayThreadContext.getApiRequest();
srequest.setApiKey(apiKey);
srequest.setApiOrgId(pathInfo.orgId);
srequest.setApiId(pathInfo.apiId);
srequest.setApiVersion(pathInfo.apiVersion);
srequest.setUrl(request.getRequestURL().toString());
srequest.setDestination(pathInfo.resource);
srequest.setQueryParams(queryParams);
readHeaders(srequest, request);
srequest.setRawRequest(request);
srequest.setRemoteAddr(request.getRemoteAddr());
srequest.setTransportSecure(request.isSecure());
return srequest;
}
use of io.apiman.gateway.engine.beans.util.QueryMap in project apiman by apiman.
the class GatewayServletTest method testParseApiRequestQueryParams.
/**
* Test method for {@link io.apiman.gateway.platforms.servlet.GatewayServlet#parseApiRequestQueryParams(String)}
*/
@Test
public void testParseApiRequestQueryParams() {
QueryMap paramMap = GatewayServlet.parseApiRequestQueryParams(null);
Assert.assertNotNull(paramMap);
paramMap = GatewayServlet.parseApiRequestQueryParams("param1");
Assert.assertNull(paramMap.get("param1"));
paramMap = GatewayServlet.parseApiRequestQueryParams("param1=value1");
Assert.assertEquals("value1", paramMap.get("param1"));
paramMap = GatewayServlet.parseApiRequestQueryParams("param1=value1¶m2");
Assert.assertEquals("value1", paramMap.get("param1"));
Assert.assertNull(paramMap.get("param2"));
paramMap = GatewayServlet.parseApiRequestQueryParams("param1=value1¶m2=value2");
Assert.assertEquals("value1", paramMap.get("param1"));
Assert.assertEquals("value2", paramMap.get("param2"));
paramMap = GatewayServlet.parseApiRequestQueryParams("param1=value1¶m2=value2¶m3=value3");
Assert.assertEquals("value1", paramMap.get("param1"));
Assert.assertEquals("value2", paramMap.get("param2"));
Assert.assertEquals("value3", paramMap.get("param3"));
paramMap = GatewayServlet.parseApiRequestQueryParams("param1=hello%20world¶m2=hello+world¶m3=hello%20world&strangekeywith%3D%2B%26%3F=strangevaluewith%3D%2B%26%3F");
Assert.assertEquals("hello world", paramMap.get("param1"));
Assert.assertEquals("hello world", paramMap.get("param2"));
Assert.assertEquals("hello world", paramMap.get("param3"));
Assert.assertEquals("strangevaluewith=+&?", paramMap.get("strangekeywith=+&?"));
}
use of io.apiman.gateway.engine.beans.util.QueryMap in project apiman-plugins by apiman.
the class JsonpPolicyTest method shouldRemoveCallbackParamNameFromRequest.
@Test
public void shouldRemoveCallbackParamNameFromRequest() throws Exception {
// given
JsonpConfigBean config = new JsonpConfigBean();
config.setCallbackParamName("testParam");
QueryMap queryParams = new QueryMap();
queryParams.put("testParam", "testFunction");
ApiRequest request = new ApiRequest();
request.setQueryParams(queryParams);
IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
// when
jsonpPolicy.doApply(request, sContext, config, chain);
// then
assertNull(request.getQueryParams().get("testParam"));
verify(chain).doApply(request);
}
Aggregations