Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to java events #657

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

mbfreder
Copy link
Contributor

@mbfreder mbfreder commented Oct 18, 2023

Issue #, if available:

Description of changes:
Migrated to Java-events lib.
The build fails because the V4 of Java-events is not released yet.

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

@mbfreder
Copy link
Contributor Author

The build fails because the V4 of Java-events is not released yet.

@sapessi
Copy link
Collaborator

sapessi commented Oct 18, 2023

We identified new issues on unchanged lines of code. Navigate to the Amazon CodeGuru Reviewer console to view the recommendations to fix them.

import static com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest.cleanUri;
import static com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest.decodeRequestPath;

public class AwsHttpServletRequestHelper {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

This class references 44 other classes. By comparison, 98% of the classes in the CodeGuru reference dataset reference fewer. This indicates that this class is highly coupled with other classes. A class that is highly coupled with other classes is difficult to understand and its behavior might change unexpectedly when one of its referenced classes is updated. High coupling could also increase the integration test complexity, maintenance cost and technical debt. We recommend that you simplify this class or break it into multiple classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

* @param valueSeparator The separator to be used for parsing header values
* @return A list of SimpleMapEntry objects with all of the possible values for the header.
*/
protected static List<AwsHttpServletRequest.HeaderValue> parseHeaderValue(String headerValue, String valueSeparator, String qualifierSeparator) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

The cyclomatic complexity of this method is 13. By comparison, 98% of the methods in the CodeGuru reference dataset have a lower cyclomatic complexity. This indicates the method has a high number of decisions and it can make the logic difficult to understand and test.

We recommend that you simplify this method or break it into multiple methods. For example, consider extracting the code block on lines 438-446 into a separate method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AwsAlbHttpServletRequest extends AwsHttpServletRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

This class references 45 other classes. By comparison, 98% of the classes in the CodeGuru reference dataset reference fewer. This indicates that this class is highly coupled with other classes. A class that is highly coupled with other classes is difficult to understand and its behavior might change unexpectedly when one of its referenced classes is updated. High coupling could also increase the integration test complexity, maintenance cost and technical debt. We recommend that you simplify this class or break it into multiple classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think breaking this class into multiple classes will increase complexity, making the code very hard to understand.

@mbfreder mbfreder force-pushed the migrate-java-events branch 2 times, most recently from 3b4a0ae to 3e3965a Compare October 18, 2023 23:48
@mbfreder mbfreder requested a review from deki October 19, 2023 00:11
@deki
Copy link
Collaborator

deki commented Oct 19, 2023

Thanks for all the work you put into it @mbfreder! Could you please rebase on main to resolve the conflicts? I will go through it in detail afterwards...

@mbfreder
Copy link
Contributor Author

mbfreder commented Oct 19, 2023

Rebased.

@deki deki added this to the Release 2.0 milestone Oct 23, 2023
Copy link
Collaborator

@deki deki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are almost there :-)

Looking at the code it would be helpful to have not just com.amazonaws.services.lambda.runtime.events.apigateway.HttpRequestEvent but also something like a V1Payload that bundles some properties of ApplicationLoadBalancerRequestEvent and APIGatewayProxyRequestEvent. Just an idea to reduce copy/ paste, not sure if the team would be open for it...

import java.util.List;
import java.util.Map;

public class AwsAlbExceptionHandler implements ExceptionHandler<AwsProxyResponseEvent>{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need that class? Can't we use AwsProxyExceptionHandler? Unittests ran fine without it.

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AwsAlbHttpServletRequest extends AwsHttpServletRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a Javadoc comment to the class


@Override
public String getProtocol() {
return "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that a valid return value?

}
}

return new StringBuilder().append("null")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks wrong, see also #647


if (request.getMultiValueHeaders() != null && request.getMultiValueHeaders().containsKey(HOST_HEADER_NAME)) {
String hostHeader = getFirst(request.getMultiValueHeaders(), HOST_HEADER_NAME);
if (SecurityUtils.isValidHost(hostHeader, "null", region)) { // ALB doesn't have apiId.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null instead of "null"?


@Override
public String getRequestId() {
return "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that empty?

public HttpServletRequest readRequest(ApplicationLoadBalancerRequestEvent request, SecurityContext securityContext, Context lambdaContext, ContainerConfig config) throws InvalidRequestEventException {
// Expect the HTTP method and context to be populated. If they are not, we are handling an
// unsupported event type.
if (request.getHttpMethod() == null || request.getHttpMethod().equals("") || request.getRequestContext() == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace equals("") with isEmpty()

import java.util.HashMap;
import java.util.Map;

public class AwsAlbHttpServletResponseWriter extends ResponseWriter<AwsHttpServletResponse, AwsProxyResponseEvent> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create a Javadoc comment on class level

@@ -35,36 +35,38 @@ public class AwsProxySecurityContext
// Constants - Package
//-------------------------------------------------------------

static final String AUTH_SCHEME_CUSTOM = "CUSTOM_AUTHORIZER";
public static final String AUTH_SCHEME_CUSTOM = "CUSTOM_AUTHORIZER";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of making in public you may wanted to use the identical constant from AwsAlbSecurityContext. either that or have the constants just once (in a base class?).

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 17

@deki deki modified the milestones: Release 2.0, Release 3.0 Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants