Getting 502 error when using spring integration provided by aws-serverless-java-container

Viewed 495

Below is my handler class. I expect simple string body as response. But i am getting 502 errors. Is this issue with Spring not returning string responses or serveless container emulation issue. I have gone through the code, its executes dispatcher service method directly after creating http request object from aws lambda invoke context.

{ "statusCode": 502, "headers": { "Content-Type": "application/json" }, "body": "{\"message\":\"Gateway timeout\"}", "base64Encoded": false }

public class MyHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {

public static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;


public MyHandler() throws ContainerInitializationException {
        handler = SpringLambdaContainerHandler.getAwsProxyHandler(SpringConfig.class);
}

public AwsProxyResponse handleRequest(AwsProxyRequest input, Context context) {
    System.out.println("Servlet context Before = " + handler.getServletContext());
    AwsProxyResponse resp = null;
    try {
       resp  =  handler.proxy(input, context);
    } catch (Exception e) {
        e.printStackTrace();
       context.getLogger().log("Error " + e.getMessage());
    }
    System.out.println("Servlet context After = " + handler.getServletContext());
    System.out.println("Response = " + resp.getBody() + " statusCode=" + resp.getStatusCode()
    + " resp=" + resp.getHeaders());
    return resp;
}

}

Here is my controller

@Controller

public class MyController {

@Autowired
private ServletContext servletContext;

@RequestMapping(value="/sampleApp.jnlp")
public String home(HttpServletRequest request){
    System.out.println("ServletContext " + servletContext);
    System.out.println("Ctr : Request : " +request);
    //System.out.println("Ctr : response : " +response);
    return "\"key1\":\"value1\"";
}

}

0 Answers
Related