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

AwsLambdaServletContainerHandler(line:100)- Could not forward request #269

Closed
1103036128 opened this issue Jul 13, 2019 · 21 comments
Closed
Assignees
Labels
Milestone

Comments

@1103036128
Copy link

1103036128 commented Jul 13, 2019

Spring Boot ErrorController
image

2019-07-13 07:37:40,629 [main] DEBUG org.springframework.web.servlet.DispatcherServlet(line:1100)- Failed to complete request: org.springframework.http.InvalidMediaTypeException: Invalid mime type "; charset=utf-8": 'mimeType' must not be empty

07:37:40
2019-07-13 07:37:40,631 [main] ERROR com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler(line:100)- Could not forward request

07:37:40
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.http.InvalidMediaTypeException: Invalid mime type "; charset=utf-8": 'mimeType' must not be empty

07:37:40
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)

07:37:40
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)

07:37:40
at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)

07:37:40
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)

07:37:40
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:351)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:209)

07:37:40
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)

07:37:40
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)

07:37:40
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)

07:37:40
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)

07:37:40
at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:123)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)

07:37:40
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:206)

07:37:40
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.handleRequest(SpringBootLambdaContainerHandler.java:154)

07:37:40
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.handleRequest(SpringBootLambdaContainerHandler.java:52)
@1103036128
Copy link
Author

Failed to complete request: org.springframework.http.InvalidMediaTypeException: Invalid mime type "; charset=utf-8": 'mimeType' must not be empty

@sapessi
Copy link
Collaborator

sapessi commented Jul 15, 2019

Thanks for reporting this @1103036128. Do you have an example of the incoming request (event dump)? Also, make sure you are using the latest version of the framework: 1.3.2

@1103036128
Copy link
Author

I found this problem: the aws lambda serverless container does not need to set the filter - response.SetCharacterEncoding (" utf-8 "), you can close this problem, thank you

@1103036128
Copy link
Author

But I want to set the character encoding to utf-8,
where do I need to set this character encoding, am I using springboot configuration, or am I reporting an error.
#encoding
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
server.tomcat.uri-encoding=UTF-8

@1103036128 1103036128 reopened this Jul 18, 2019
@1103036128
Copy link
Author

The error is:
Failed to complete request: org.springframework.http.InvalidMediaTypeException: Invalid mime type "; charset=utf-8": 'mimeType' must not be empty

@1103036128
Copy link
Author

My dependency is :

com.amazonaws.serverless
aws-serverless-java-container-spring
1.3.1

@1103036128
Copy link
Author

The 1.3.2 version is the same error:
Invalid mime type "; charset=utf-8": 'mimeType' must not be empty

@1103036128
Copy link
Author

1103036128 commented Jul 18, 2019

My example:

@RestController
@RequestMapping("/ordr/v1")
public class OrderController {
	private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);

	@RequestMapping(value="/health",method=RequestMethod.GET)
	public Object health(String name,HttpServletResponse response){
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("code", 200);
		model.put("message", "health心跳测试完成。可正常使用");
		LOGGER.debug("test /health RESTful api.");
		return model;
	}
}

@1103036128
Copy link
Author

ERROR com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler(line:100)- Could not forward request

@1103036128
Copy link
Author

@sapessi I hope you can help me with this problem. Thank you very much

@1103036128
Copy link
Author

My springboot version is 2.1.4

@sapessi
Copy link
Collaborator

sapessi commented Jul 18, 2019

Thanks @1103036128 - I'll work to replicate today. This is the character encoding of the response correct?

@1103036128
Copy link
Author

If I don't set the springboot configuration of utf-8, it will respond normally, but Chinese characters will be scrambled.So I want to set it to utf-8, but it will cause abnormal response

@sapessi
Copy link
Collaborator

sapessi commented Jul 19, 2019

Hi @1103036128, I figured out what is going on. Seems to be a bug but I'm not 100% sure what the appropriate behavior should be. There are two things going on here.

  1. The framework treats all text content as ISO-8859-1 because that is the HTTP standard. Just like you used the server.tomcat.uri-encoding=UTF-8 configuration in your properties file, you can change the framework's default encoding using the ContainerConfig object. Simply add this line to the constructor of your Lambda handler class - or wherever you initialize the framework:
LambdaContainerHandler.getContainerConfig().setDefaultContentCharset("UTF-8");
  1. The next issue is the potential bug I'm trying to figure out how to handle. When you configure Spring to automatically set to force the character encoding (spring.http.encoding.force=true), the framework makes a call to the setCharacterEncoding method of the response object before having set a content type. The bug in the class is that we try to set the header value right away and if there is no content type set we default it to "". This is what's causing the "; charset=UTF-8" value in the header. I'll keep digging to address this as soon as possible. Meanwhile, I would try to not to force the encoding.

@sapessi
Copy link
Collaborator

sapessi commented Jul 19, 2019

I'm committing a fix to this that conforms to the behavior described in the servlet specs. Once you see the commit appear in this issue you can test yourself by cloning the core branch of this repository, running mvn install on your local machine, and setting your dependency to 1.4-SNAPSHOT. Maven should be smart enough to find the pre-release version in your local repo.

@sapessi sapessi self-assigned this Jul 19, 2019
@sapessi sapessi added the bug label Jul 19, 2019
@sapessi sapessi added this to the Release 1.4 milestone Jul 19, 2019
sapessi added a commit that referenced this issue Jul 19, 2019
…ing in the response overwrites whatever is passed in with the content type header
@1103036128
Copy link
Author

1103036128 commented Jul 20, 2019

image

@1103036128
Copy link
Author

mvn install:install-file -Dfile=aws-serverless-java-container-core-1.4-SNAPSHOT.jar -DgroupId=com.amazonaws.serverless -DartifactId=aws-serverless-java-container-core -Dversion=1.4-SNAPSHOT -Dpackaging=jar

@1103036128
Copy link
Author

Is my above operation correct?

@1103036128
Copy link
Author

When will you release it to Maven Repository?

@sapessi
Copy link
Collaborator

sapessi commented Jul 20, 2019

You could simply:

# clone the repo to your local machine
$ git clone https://github.com/awslabs/aws-serverless-java-container.git
$ cd aws-serverless-java-container

# switch to the core branch
$ git checkout core

# install the latest version in local
$ mvn install

Once it's installed, you can just change the dependency version in your project's pom.xml to use the 1.4-SNAPSHOT version. I have quite a few other features to address for the 1.4 release so it could be a few weeks. I'll try to pull it forward as much as possible.

@1103036128
Copy link
Author

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants