@Test public void handleRedirectWoContextPath() throws Exception { ODataServlet servlet = new ODataServlet(); prepareServlet(servlet); prepareRequest(reqMock, null, "/servlet-path"); servlet.service(reqMock, respMock); Mockito.verify(respMock).setStatus(HttpStatusCodes.TEMPORARY_REDIRECT.getStatusCode()); Mockito.verify(respMock).setHeader(HttpHeaders.LOCATION, "/servlet-path/"); }
@Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { ODataServiceFactory serviceFactory = getServiceFactory(req); if(serviceFactory == null) { throw new ODataRuntimeException("Unable to get Service Factory. Check either '" + ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config."); } String xHttpMethod = req.getHeader("X-HTTP-Method"); String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override"); if (xHttpMethod != null && xHttpMethodOverride != null) { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory); createResponse(resp, wrapper.wrapInExceptionResponse( new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD))); return; } } if (req.getPathInfo() != null) { handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory); } else { handleRedirect(req, resp, serviceFactory); } }
ODataServlet extends HttpServlet { @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { ODataServiceFactory serviceFactory = getServiceFactory(req); if(serviceFactory == null) { throw new ODataRuntimeException("Unable to get Service Factory. Check either '" + ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config."); } String xHttpMethod = req.getHeader("X-HTTP-Method"); String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override"); if (xHttpMethod != null && xHttpMethodOverride != null) { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory); createResponse(resp, wrapper.wrapInExceptionResponse( new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD))); return; } } if (req.getPathInfo() != null) { handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory); } else { handleRedirect(req, resp, serviceFactory); } } }
ODataServlet extends HttpServlet { @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { ODataServiceFactory serviceFactory = getServiceFactory(req); if(serviceFactory == null) { throw new ODataRuntimeException("Unable to get Service Factory. Check either '" + ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config."); } String xHttpMethod = req.getHeader("X-HTTP-Method"); String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override"); if (xHttpMethod != null && xHttpMethodOverride != null) { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory); createResponse(resp, wrapper.wrapInExceptionResponse( new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD))); return; } } if (req.getPathInfo() != null) { handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory); } else { handleRedirect(req, resp, serviceFactory); } }  }
ODataServlet extends HttpServlet { @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { ODataServiceFactory serviceFactory = getServiceFactory(req); if(serviceFactory == null) { throw new ODataRuntimeException("Unable to get Service Factory. Check either '" + ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config."); } String xHttpMethod = req.getHeader("X-HTTP-Method"); String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override"); if (xHttpMethod != null && xHttpMethodOverride != null) { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory); createResponse(resp, wrapper.wrapInExceptionResponse( new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD))); return; } } if (req.getPathInfo() != null) { handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory); } else { handleRedirect(req, resp, serviceFactory); } }   }
ODataServlet extends HttpServlet { @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { ODataServiceFactory serviceFactory = getServiceFactory(req); if(serviceFactory == null) { throw new ODataRuntimeException("Unable to get Service Factory. Check either '" + ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config."); } String xHttpMethod = req.getHeader("X-HTTP-Method"); String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override"); if (xHttpMethod != null && xHttpMethodOverride != null) { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory); createResponse(resp, wrapper.wrapInExceptionResponse( new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD))); return; } } if (req.getPathInfo() != null) { handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory); } else { handleRedirect(req, resp, serviceFactory); } }    }