Skip to content

Context injection in ExceptionMapper #90

@rvangala936

Description

@rvangala936

Hi,
HttpServletRequest injection into the ExceptionMapper is not working for an application using AWS JerseyLambdaContainerHandler.

Is there a way that I can get hold of request in the ExceptionMapper ?

import java.util.Arrays;
import java.util.NoSuchElementException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Provider
public class NoSuchElementMapper implements ExceptionMapper {
@context private HttpServletRequest request;

@Override
public Response toResponse(NoSuchElementException exception) {
    LOG.debug("request:" + (request != null));
    Response.Status statusCode = Response.Status.NOT_FOUND;
     return Response.status(statusCode).entity(exception.getMessage())
            .type(MediaType.TEXT_PLAIN)
            .build();
}

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions