@Test public void extractMethodFailForNettyRequest() throws Exception { String[][] mm = { { "POST", "bla", null }, { "POST", "PUT", "PATCH" }, { "OPTIONS", null, null } }; for (String[] m : mm) { HttpRequest hr = mock(HttpRequest.class); io.netty.handler.codec.http.HttpMethod hm = mock(io.netty.handler.codec.http.HttpMethod.class); when(hr.method()).thenReturn(hm); when(hm.name()).thenReturn(m[0]); HttpHeaders hh = mock(HttpHeaders.class); when(hr.headers()).thenReturn(hh); when(hh.get("X-HTTP-Method")).thenReturn(m[1]); when(hh.get("X-HTTP-Method-Override")).thenReturn(m[2]); try { ODataNettyHandlerImpl.extractMethod(hr); fail(); } catch (ODataLibraryException e) { } } }
static HttpMethod extractMethod(final HttpRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.method().name()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.method().name(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.method().name()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.headers(). get(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.headers(). get(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.method().name(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.method().name()); } }
ODataNettyHandlerImpl implements ODataNettyHandler { static HttpMethod extractMethod(final HttpRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.method().name()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.method().name(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.method().name()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.headers(). get(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.headers(). get(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.method().name(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.method().name()); } } }
ODataNettyHandlerImpl implements ODataNettyHandler { static HttpMethod extractMethod(final HttpRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.method().name()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.method().name(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.method().name()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.headers(). get(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.headers(). get(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.method().name(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.method().name()); } } ODataNettyHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata); }
ODataNettyHandlerImpl implements ODataNettyHandler { static HttpMethod extractMethod(final HttpRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.method().name()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.method().name(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.method().name()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.headers(). get(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.headers(). get(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.method().name(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.method().name()); } } ODataNettyHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata); @SuppressWarnings("unused") @Override void processNettyRequest(HttpRequest request, HttpResponse response, 
		Map<String, String> requestParameters); ODataResponse process(ODataRequest request); @Override void register(Processor processor); }
ODataNettyHandlerImpl implements ODataNettyHandler { static HttpMethod extractMethod(final HttpRequest httpRequest) throws ODataLibraryException { final HttpMethod httpRequestMethod; try { httpRequestMethod = HttpMethod.valueOf(httpRequest.method().name()); } catch (IllegalArgumentException e) { throw new ODataHandlerException("HTTP method not allowed" + httpRequest.method().name(), e, ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.method().name()); } try { if (httpRequestMethod == HttpMethod.POST) { String xHttpMethod = httpRequest.headers(). get(HttpHeader.X_HTTP_METHOD); String xHttpMethodOverride = httpRequest.headers(). get(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.method().name(), e, ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.method().name()); } } ODataNettyHandlerImpl(final OData odata, final ServiceMetadata serviceMetadata); @SuppressWarnings("unused") @Override void processNettyRequest(HttpRequest request, HttpResponse response, 
		Map<String, String> requestParameters); ODataResponse process(ODataRequest request); @Override void register(Processor processor); static final int COPY_BUFFER_SIZE; }