@Test public void queryString_generateQueryString_validQuery() { AwsProxyHttpServletRequest request = new AwsProxyHttpServletRequest(queryString, mockContext, null, config); String parsedString = null; try { parsedString = request.generateQueryString(request.getAwsProxyRequest().getMultiValueQueryStringParameters(), true, config.getUriEncoding()); } catch (ServletException e) { e.printStackTrace(); fail("Could not generate query string"); } assertTrue(parsedString.contains("one=two")); assertTrue(parsedString.contains("three=four")); assertTrue(parsedString.contains("&") && parsedString.indexOf("&") > 0 && parsedString.indexOf("&") < parsedString.length()); }
protected String generateQueryString(MultiValuedTreeMap<String, String> parameters, boolean encode, String encodeCharset) throws ServletException { if (parameters == null || parameters.size() == 0) { return null; } if (queryString != null) { return queryString; } StringBuilder queryStringBuilder = new StringBuilder(); try { for (String key : parameters.keySet()) { for (String val : parameters.get(key)) { queryStringBuilder.append("&"); if (encode) { queryStringBuilder.append(URLEncoder.encode(key, encodeCharset)); } else { queryStringBuilder.append(key); } queryStringBuilder.append("="); if (val != null) { if (encode) { queryStringBuilder.append(URLEncoder.encode(val, encodeCharset)); } else { queryStringBuilder.append(val); } } } } } catch (UnsupportedEncodingException e) { throw new ServletException("Invalid charset passed for query string encoding", e); } queryString = queryStringBuilder.toString(); queryString = queryString.substring(1); return queryString; }
AwsHttpServletRequest implements HttpServletRequest { protected String generateQueryString(MultiValuedTreeMap<String, String> parameters, boolean encode, String encodeCharset) throws ServletException { if (parameters == null || parameters.size() == 0) { return null; } if (queryString != null) { return queryString; } StringBuilder queryStringBuilder = new StringBuilder(); try { for (String key : parameters.keySet()) { for (String val : parameters.get(key)) { queryStringBuilder.append("&"); if (encode) { queryStringBuilder.append(URLEncoder.encode(key, encodeCharset)); } else { queryStringBuilder.append(key); } queryStringBuilder.append("="); if (val != null) { if (encode) { queryStringBuilder.append(URLEncoder.encode(val, encodeCharset)); } else { queryStringBuilder.append(val); } } } } } catch (UnsupportedEncodingException e) { throw new ServletException("Invalid charset passed for query string encoding", e); } queryString = queryStringBuilder.toString(); queryString = queryString.substring(1); return queryString; } }
AwsHttpServletRequest implements HttpServletRequest { protected String generateQueryString(MultiValuedTreeMap<String, String> parameters, boolean encode, String encodeCharset) throws ServletException { if (parameters == null || parameters.size() == 0) { return null; } if (queryString != null) { return queryString; } StringBuilder queryStringBuilder = new StringBuilder(); try { for (String key : parameters.keySet()) { for (String val : parameters.get(key)) { queryStringBuilder.append("&"); if (encode) { queryStringBuilder.append(URLEncoder.encode(key, encodeCharset)); } else { queryStringBuilder.append(key); } queryStringBuilder.append("="); if (val != null) { if (encode) { queryStringBuilder.append(URLEncoder.encode(val, encodeCharset)); } else { queryStringBuilder.append(val); } } } } } catch (UnsupportedEncodingException e) { throw new ServletException("Invalid charset passed for query string encoding", e); } queryString = queryStringBuilder.toString(); queryString = queryString.substring(1); return queryString; } AwsHttpServletRequest(Context lambdaContext); }
AwsHttpServletRequest implements HttpServletRequest { protected String generateQueryString(MultiValuedTreeMap<String, String> parameters, boolean encode, String encodeCharset) throws ServletException { if (parameters == null || parameters.size() == 0) { return null; } if (queryString != null) { return queryString; } StringBuilder queryStringBuilder = new StringBuilder(); try { for (String key : parameters.keySet()) { for (String val : parameters.get(key)) { queryStringBuilder.append("&"); if (encode) { queryStringBuilder.append(URLEncoder.encode(key, encodeCharset)); } else { queryStringBuilder.append(key); } queryStringBuilder.append("="); if (val != null) { if (encode) { queryStringBuilder.append(URLEncoder.encode(val, encodeCharset)); } else { queryStringBuilder.append(val); } } } } } catch (UnsupportedEncodingException e) { throw new ServletException("Invalid charset passed for query string encoding", e); } queryString = queryStringBuilder.toString(); queryString = queryString.substring(1); return queryString; } AwsHttpServletRequest(Context lambdaContext); AwsHttpServletResponse getResponse(); void setResponse(AwsHttpServletResponse response); void setContainerHandler(AwsLambdaServletContainerHandler containerHandler); @Override String getRequestedSessionId(); @Override HttpSession getSession(boolean b); @Override HttpSession getSession(); @Override String changeSessionId(); @Override boolean isRequestedSessionIdValid(); @Override boolean isRequestedSessionIdFromCookie(); @Override boolean isRequestedSessionIdFromURL(); @Override @Deprecated boolean isRequestedSessionIdFromUrl(); @Override Object getAttribute(String s); @Override Enumeration<String> getAttributeNames(); @Override String getServerName(); @Override int getServerPort(); @Override void setAttribute(String s, Object o); @Override void removeAttribute(String s); @Override String getLocalName(); @Override String getLocalAddr(); @Override int getLocalPort(); @Override ServletContext getServletContext(); @Override boolean isAsyncStarted(); @Override boolean isAsyncSupported(); @Override DispatcherType getDispatcherType(); @Override String getServletPath(); void setServletContext(ServletContext context); }
AwsHttpServletRequest implements HttpServletRequest { protected String generateQueryString(MultiValuedTreeMap<String, String> parameters, boolean encode, String encodeCharset) throws ServletException { if (parameters == null || parameters.size() == 0) { return null; } if (queryString != null) { return queryString; } StringBuilder queryStringBuilder = new StringBuilder(); try { for (String key : parameters.keySet()) { for (String val : parameters.get(key)) { queryStringBuilder.append("&"); if (encode) { queryStringBuilder.append(URLEncoder.encode(key, encodeCharset)); } else { queryStringBuilder.append(key); } queryStringBuilder.append("="); if (val != null) { if (encode) { queryStringBuilder.append(URLEncoder.encode(val, encodeCharset)); } else { queryStringBuilder.append(val); } } } } } catch (UnsupportedEncodingException e) { throw new ServletException("Invalid charset passed for query string encoding", e); } queryString = queryStringBuilder.toString(); queryString = queryString.substring(1); return queryString; } AwsHttpServletRequest(Context lambdaContext); AwsHttpServletResponse getResponse(); void setResponse(AwsHttpServletResponse response); void setContainerHandler(AwsLambdaServletContainerHandler containerHandler); @Override String getRequestedSessionId(); @Override HttpSession getSession(boolean b); @Override HttpSession getSession(); @Override String changeSessionId(); @Override boolean isRequestedSessionIdValid(); @Override boolean isRequestedSessionIdFromCookie(); @Override boolean isRequestedSessionIdFromURL(); @Override @Deprecated boolean isRequestedSessionIdFromUrl(); @Override Object getAttribute(String s); @Override Enumeration<String> getAttributeNames(); @Override String getServerName(); @Override int getServerPort(); @Override void setAttribute(String s, Object o); @Override void removeAttribute(String s); @Override String getLocalName(); @Override String getLocalAddr(); @Override int getLocalPort(); @Override ServletContext getServletContext(); @Override boolean isAsyncStarted(); @Override boolean isAsyncSupported(); @Override DispatcherType getDispatcherType(); @Override String getServletPath(); void setServletContext(ServletContext context);  }