@Test public void extractMethodFail() throws Exception { String[][] mm = { { "POST", "bla", null }, { "POST", "PUT", "PATCH" }, { "OPTIONS", null, null } }; for (String[] m : mm) { HttpServletRequest hr = mock(HttpServletRequest.class); when(hr.getMethod()).thenReturn(m[0]); when(hr.getHeader("X-HTTP-Method")).thenReturn(m[1]); when(hr.getHeader("X-HTTP-Method-Override")).thenReturn(m[2]); try { ODataHttpHandlerImpl.extractMethod(hr); fail(); } catch (ODataLibraryException e) { } } }
static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE); if (xHttpMethod == null && xHttpMethodOverride == null) { return httpRequestMethod; } else if (xHttpMethod == null) { return HttpMethod.valueOf(xHttpMethodOverride); } else if (xHttpMethodOverride == null) { return HttpMethod.valueOf(xHttpMethod); } else { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { throw new ODataHandlerException("Ambiguous X-HTTP-Methods", ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride); } return HttpMethod.valueOf(xHttpMethod); } } else { return httpRequestMethod; } } catch (IllegalArgumentException e) { throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod()); } }
ODataHttpHandlerImpl implements ODataHttpHandler { static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE); if (xHttpMethod == null && xHttpMethodOverride == null) { return httpRequestMethod; } else if (xHttpMethod == null) { return HttpMethod.valueOf(xHttpMethodOverride); } else if (xHttpMethodOverride == null) { return HttpMethod.valueOf(xHttpMethod); } else { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { throw new ODataHandlerException("Ambiguous X-HTTP-Methods", ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride); } return HttpMethod.valueOf(xHttpMethod); } } else { return httpRequestMethod; } } catch (IllegalArgumentException e) { throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod()); } } }
ODataHttpHandlerImpl implements ODataHttpHandler { static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE); if (xHttpMethod == null && xHttpMethodOverride == null) { return httpRequestMethod; } else if (xHttpMethod == null) { return HttpMethod.valueOf(xHttpMethodOverride); } else if (xHttpMethodOverride == null) { return HttpMethod.valueOf(xHttpMethod); } else { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { throw new ODataHandlerException("Ambiguous X-HTTP-Methods", ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride); } return HttpMethod.valueOf(xHttpMethod); } } else { return httpRequestMethod; } } catch (IllegalArgumentException e) { throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod()); } } ODataHttpHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata); }
ODataHttpHandlerImpl implements ODataHttpHandler { static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE); if (xHttpMethod == null && xHttpMethodOverride == null) { return httpRequestMethod; } else if (xHttpMethod == null) { return HttpMethod.valueOf(xHttpMethodOverride); } else if (xHttpMethodOverride == null) { return HttpMethod.valueOf(xHttpMethod); } else { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { throw new ODataHandlerException("Ambiguous X-HTTP-Methods", ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride); } return HttpMethod.valueOf(xHttpMethod); } } else { return httpRequestMethod; } } catch (IllegalArgumentException e) { throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod()); } } ODataHttpHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata); @Override ODataResponse process(ODataRequest request); @Override void process(final HttpServletRequest request, final HttpServletResponse response); @Override void setSplit(final int split); @Override void register(final Processor processor); @Override void register(OlingoExtension extension); @Override void register(final CustomContentTypeSupport customContentTypeSupport); @Override void register(final CustomETagSupport customConcurrencyControlSupport); @Override void register(final DebugSupport debugSupport); }
ODataHttpHandlerImpl implements ODataHttpHandler { static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE); if (xHttpMethod == null && xHttpMethodOverride == null) { return httpRequestMethod; } else if (xHttpMethod == null) { return HttpMethod.valueOf(xHttpMethodOverride); } else if (xHttpMethodOverride == null) { return HttpMethod.valueOf(xHttpMethod); } else { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { throw new ODataHandlerException("Ambiguous X-HTTP-Methods", ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride); } return HttpMethod.valueOf(xHttpMethod); } } else { return httpRequestMethod; } } catch (IllegalArgumentException e) { throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod()); } } ODataHttpHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata); @Override ODataResponse process(ODataRequest request); @Override void process(final HttpServletRequest request, final HttpServletResponse response); @Override void setSplit(final int split); @Override void register(final Processor processor); @Override void register(OlingoExtension extension); @Override void register(final CustomContentTypeSupport customContentTypeSupport); @Override void register(final CustomETagSupport customConcurrencyControlSupport); @Override void register(final DebugSupport debugSupport); static final int COPY_BUFFER_SIZE; }