ODataNettyHandlerImpl implements ODataNettyHandler { static void fillUriInformationFromHttpRequest(final ODataRequest odRequest, final HttpRequest httpRequest, final int split, final String contextPath) { String rawRequestUri = httpRequest.uri(); if (rawRequestUri.indexOf("?") != -1) { rawRequestUri = rawRequestUri.substring(0, rawRequestUri.indexOf("?")); } String rawODataPath; if (!"".equals(contextPath)) { int beginIndex = rawRequestUri.indexOf(contextPath) + contextPath.length(); rawODataPath = rawRequestUri.substring(beginIndex); } else { rawODataPath = rawRequestUri; } String rawServiceResolutionUri = null; if (split > 0) { rawServiceResolutionUri = rawODataPath; for (int i = 0; i < split; i++) { int index = rawODataPath.indexOf('/', 1); if (-1 == index) { rawODataPath = ""; break; } else { rawODataPath = rawODataPath.substring(index); } } int end = rawServiceResolutionUri.length() - rawODataPath.length(); rawServiceResolutionUri = rawServiceResolutionUri.substring(0, end); } String rawBaseUri = rawRequestUri.substring(0, rawRequestUri.length() - rawODataPath.length()); int index = httpRequest.uri().indexOf('?'); String queryString = null; if (index != -1) { queryString = httpRequest.uri().substring(index + 1); } odRequest.setRawQueryPath(queryString); odRequest.setRawRequestUri(rawRequestUri + (queryString == null ? "" : "?" + queryString)); odRequest.setRawODataPath(rawODataPath); odRequest.setRawBaseUri(rawBaseUri); odRequest.setRawServiceResolutionUri(rawServiceResolutionUri); } 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; }
@Test public void extractUriForNettyRequests() { String [][] uris = { { "", "", "", "", "0"}, { "", "", "/", "", "0"}, { "", "", "/od", "", "0"}, { "", "", "/od/", "", "0"}, { "/cp", "", "", "", "0"}, { "/cp", "", "/", "", "0"}, { "/cp", "", "/od", "", "0"}, { "", "/sr", "", "", "1"}, { "", "/sr", "/", "", "1"}, { "", "/sr", "/od", "", "1"}, { "", "/sr/sr", "", "", "2"}, { "", "/sr/sr", "/", "", "2"}, { "", "/sr/sr", "/od", "", "2"}, { "/cp", "/sr", "/", "", "1"}, { "/cp", "/sr", "/od", "", "1"}, { "", "", "", "qp", "0"}, { "", "", "/", "qp", "0"}, { "/cp", "/sr", "/od", "qp", "1"}, { "/c%20p", "/s%20r", "/o%20d", "p+q", "1"}, }; for (String[] p : uris) { HttpRequest hr = mock(HttpRequest.class); String requestUrl = p[0] + p[1] + p[2]; if (!p[3].equals("") || p[3].length() > 0) { requestUrl += "?$" + p[3]; } when(hr.uri()).thenReturn(requestUrl); ODataRequest odr = new ODataRequest(); ODataNettyHandlerImpl.fillUriInformationFromHttpRequest(odr, hr, Integer.parseInt(p[4]), p[0]); String rawBaseUri = p[0] + p[1]; String rawODataPath = p[2]; String rawQueryPath = "".equals(p[3]) ? null : "$" + p[3]; String rawRequestUri = p[0] + p[1] + p[2] + ("".equals(p[3]) ? "" : "?$" + p[3]); String rawServiceResolutionUri = "".equals(p[1]) ? null : p[1]; assertEquals(rawBaseUri, odr.getRawBaseUri()); assertEquals(rawODataPath, odr.getRawODataPath()); assertEquals(rawQueryPath, odr.getRawQueryPath()); assertEquals(rawRequestUri, odr.getRawRequestUri()); assertEquals(rawServiceResolutionUri, odr.getRawServiceResolutionUri()); } }