Skip to content

Commit

Permalink
Merge pull request #165 from awslabs/core
Browse files Browse the repository at this point in the history
Preparing for 1.1.3 release
  • Loading branch information
sapessi authored Jun 22, 2018
2 parents dfe6e4f + 31475a7 commit 267278c
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 154 deletions.
4 changes: 2 additions & 2 deletions archetypes/jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
<artifactId>aws-serverless-jersey-archetype</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
<packaging>maven-archetype</packaging>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-jersey</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions archetypes/spark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
<artifactId>aws-serverless-spark-archetype</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
<packaging>maven-archetype</packaging>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-spark</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions archetypes/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
<artifactId>aws-serverless-spring-archetype</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
<packaging>maven-archetype</packaging>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-spring</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions archetypes/springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
<artifactId>aws-serverless-springboot-archetype</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
<packaging>maven-archetype</packaging>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-spring</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-serverless-java-container-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<name>AWS Serverless Java container support - Core</name>
<description>Allows Java applications written for a servlet container to run in AWS Lambda</description>
<url>https://aws.amazon.com/lambda</url>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>

<parent>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -288,9 +289,12 @@ protected Cookie[] parseCookieHeaderValue(String headerValue) {
* Given a map of key/values query string parameters from API Gateway, creates a query string as it would have
* been in the original url.
* @param parameters A Map&lt;String, String&gt; of query string parameters
* @param encode Whether the key and values should be URL encoded
* @param encodeCharset Charset to use for encoding the query string
* @return The generated query string for the URI
*/
protected String generateQueryString(EncodingQueryStringParameterMap parameters) {
protected String generateQueryString(Map<String, String> parameters, boolean encode, String encodeCharset)
throws ServletException {
if (parameters == null || parameters.size() == 0) {
return null;
}
Expand All @@ -300,12 +304,31 @@ protected String generateQueryString(EncodingQueryStringParameterMap parameters)

StringBuilder queryStringBuilder = new StringBuilder();

parameters.keySet().stream().forEach(k -> parameters.get(k).stream().forEach(v -> {
/*parameters.keySet().stream().forEach(k -> parameters.stream().forEach(v -> {
queryStringBuilder.append("&");
queryStringBuilder.append(k);
queryStringBuilder.append("=");
queryStringBuilder.append(v);
}));
}));*/
try {
for (Map.Entry<String, String> e : parameters.entrySet()) {
queryStringBuilder.append("&");
if (encode) {
queryStringBuilder.append(URLEncoder.encode(e.getKey(), encodeCharset));
} else {
queryStringBuilder.append(e.getKey());
}
queryStringBuilder.append("=");
if (encode) {
queryStringBuilder.append(URLEncoder.encode(e.getValue(), encodeCharset));
} else {
queryStringBuilder.append(e.getValue());
}

}
} catch (UnsupportedEncodingException e) {
throw new ServletException("Invalid charset passed for query string encoding", e);
}

queryString = queryStringBuilder.toString();
queryString = queryString.substring(1); // remove the first & - faster to do it here than adding logic in the Lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public class AwsProxyHttpServletRequest extends AwsHttpServletRequest {
private Map<String, List<String>> urlEncodedFormParameters;
private Map<String, Part> multipartFormParameters;
private Map<String, String> caseInsensitiveHeaders;
private EncodingQueryStringParameterMap queryStringParameters;
private static Logger log = LoggerFactory.getLogger(AwsProxyHttpServletRequest.class);
private ContainerConfig config;

Expand All @@ -107,9 +106,6 @@ public AwsProxyHttpServletRequest(AwsProxyRequest awsProxyRequest, Context lambd
this.securityContext = awsSecurityContext;
this.config = config;

this.queryStringParameters = new EncodingQueryStringParameterMap(config.isQueryStringCaseSensitive(), config.getUriEncoding());
this.queryStringParameters.putAllMapEncoding(request.getQueryStringParameters());

this.caseInsensitiveHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
this.caseInsensitiveHeaders.putAll(awsProxyRequest.getHeaders());
}
Expand Down Expand Up @@ -230,7 +226,12 @@ public String getContextPath() {

@Override
public String getQueryString() {
return this.generateQueryString(queryStringParameters);
try {
return this.generateQueryString(request.getQueryStringParameters(), true, config.getUriEncoding());
} catch (ServletException e) {
log.error("Could not generate query string", e);
return null;
}
}


Expand Down Expand Up @@ -441,11 +442,7 @@ public ServletInputStream getInputStream()

@Override
public String getParameter(String s) {
String paramKey = s;
if (config.isQueryStringCaseSensitive()) {
paramKey = paramKey.toLowerCase(Locale.getDefault());
}
String queryStringParameter = queryStringParameters.getFirst(paramKey);
String queryStringParameter = getQueryParamValue(s, config.isQueryStringCaseSensitive());
if (queryStringParameter != null) {
return queryStringParameter;
}
Expand All @@ -462,7 +459,9 @@ public String getParameter(String s) {
@Override
public Enumeration<String> getParameterNames() {
List<String> paramNames = new ArrayList<>();
paramNames.addAll(queryStringParameters.keySet());
if (request.getQueryStringParameters() != null) {
paramNames.addAll(request.getQueryStringParameters().keySet());
}
paramNames.addAll(getFormUrlEncodedParametersMap().keySet());
return Collections.enumeration(paramNames);
}
Expand All @@ -471,16 +470,11 @@ public Enumeration<String> getParameterNames() {
@Override
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS") // suppressing this as according to the specs we should be returning null here if we can't find params
public String[] getParameterValues(String s) {
String paramKey = s;
if (config.isQueryStringCaseSensitive()) {
paramKey = paramKey.toLowerCase(Locale.getDefault());
}
List<String> values = new ArrayList<>();
List<String> queryParamValues = queryStringParameters.get(paramKey);
if (queryParamValues != null) {
values.addAll(queryParamValues);
String queryValue = getQueryParamValue(s, config.isQueryStringCaseSensitive());
if (queryValue != null) {
values.add(queryValue);
}
//values.addAll(queryStringParameters.get(paramKey));

String[] formBodyValues = getFormBodyParameterCaseInsensitive(s);
if (formBodyValues != null) {
Expand All @@ -504,9 +498,17 @@ public Map<String, String[]> getParameterMap() {
output.put(e.getKey(), e.getValue().toArray(new String[0]));
});

queryStringParameters.keySet().stream().parallel().forEach(e -> {
output.put(e, queryStringParameters.get(e).toArray(new String[0]));
});
if (request.getQueryStringParameters() != null) {
request.getQueryStringParameters().keySet().stream().parallel().forEach(e -> {
List<String> newValues = new ArrayList<>();
if (output.containsKey(e)) {
String[] values = output.get(e);
newValues.addAll(Arrays.asList(values));
}
newValues.add(getQueryParamValue(e, config.isQueryStringCaseSensitive()));
output.put(e, newValues.toArray(new String[0]));
});
}

return output;
}
Expand Down Expand Up @@ -649,13 +651,6 @@ public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse se
return null;
}

//-------------------------------------------------------------
// Methods - Protected
//-------------------------------------------------------------

protected EncodingQueryStringParameterMap getQueryParametersMap() {
return queryStringParameters;
}

//-------------------------------------------------------------
// Methods - Private
Expand Down Expand Up @@ -816,6 +811,21 @@ public static String decodeValueIfEncoded(String value) {
}


private String getQueryParamValue(String key, boolean isCaseSensitive) {
if (isCaseSensitive) {
return request.getQueryStringParameters().get(key);
}

for (String k : request.getQueryStringParameters().keySet()) {
if (k.toLowerCase(Locale.getDefault()).equals(key.toLowerCase(Locale.getDefault()))) {
return request.getQueryStringParameters().get(k);
}
}

return null;
}


public static class AwsServletInputStream extends ServletInputStream {

private InputStream bodyStream;
Expand Down

This file was deleted.

Loading

0 comments on commit 267278c

Please sign in to comment.