Java Code Examples for org.apache.olingo.server.api.ODataRequest#setRawRequestUri()
The following examples show how to use
org.apache.olingo.server.api.ODataRequest#setRawRequestUri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
static ODataRequest copyRequest(ODataRequest request) { ODataRequest req = new ODataRequest(); req.setBody(copyRequestBody(request)); req.setMethod(request.getMethod()); req.setRawBaseUri(request.getRawBaseUri()); req.setRawODataPath(request.getRawODataPath()); req.setRawQueryPath(request.getRawQueryPath()); req.setRawRequestUri(request.getRawRequestUri()); req.setRawServiceResolutionUri(request.getRawServiceResolutionUri()); for (Map.Entry<String, List<String>> header : request.getAllHeaders().entrySet()) { if (!HttpHeader.PREFER.toLowerCase().equals( header.getKey().toLowerCase())) { req.addHeader(header.getKey(), header.getValue()); } } return req; }
Example 2
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void dispatchEmptyContentWithoutContentType() { final String path = "ESAllPrim"; final EntityCollectionProcessor processor = mock(EntityCollectionProcessor.class); ODataRequest request = new ODataRequest(); request.setMethod(HttpMethod.POST); request.setRawBaseUri(BASE_URI); request.setRawRequestUri(BASE_URI); request.setRawODataPath(path); request.setBody(new ByteArrayInputStream(new byte[0])); final OData odata = OData.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata( new EdmTechProvider(), Collections.<EdmxReference> emptyList()); ODataHandlerImpl handler = new ODataHandlerImpl(odata, metadata, new ServerCoreDebugger(odata)); if (processor != null) { handler.register(processor); } final ODataResponse response = handler.process(request); assertNotNull(response); }
Example 3
Source File: DebugTabRequestTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void onlyProtocolNotSet() throws Exception { String expectedJson = "{\"method\":\"GET\",\"uri\":\"def&\",\"protocol\":\"unkown\"}"; String expectedHtml = "<h2>Request Method</h2>\n" + "<p>GET</p>\n" + "<h2>Request URI</h2>\n" + "<p>def&</p>\n" + "<h2>Request Protocol</h2>\n" + "<p>unkown</p>\n" + "<h2>Request Headers</h2>\n" + "<table>\n" + "<thead>\n" + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n" + "</thead>\n" + "<tbody>\n" + "</tbody>\n" + "</table>\n"; ODataRequest oDataRequest = new ODataRequest(); oDataRequest.setMethod(HttpMethod.GET); oDataRequest.setRawRequestUri("def&"); DebugTabRequest requestTab = new DebugTabRequest(oDataRequest); assertEquals(expectedJson, createJson(requestTab)); assertEquals(expectedHtml, createHtml(requestTab)); }
Example 4
Source File: MockedBatchHandlerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private ODataRequest buildODataRequest(final String content, final Map<String, List<String>> header) throws Exception { final ODataRequest request = new ODataRequest(); for (final String key : header.keySet()) { request.addHeader(key, header.get(key)); } request.setMethod(HttpMethod.POST); request.setRawBaseUri(BASE_URI); request.setRawODataPath(BATCH_ODATA_PATH); request.setRawQueryPath(""); request.setRawRequestUri(BATCH_REQUEST_URI); request.setRawServiceResolutionUri(""); request.setBody(new ByteArrayInputStream(content.getBytes("UTF-8"))); return request; }
Example 5
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ODataResponse dispatch(final HttpMethod method, final String path, final String query, final String headerName, final String headerValue, final Processor processor) { ODataRequest request = new ODataRequest(); request.setMethod(method); request.setRawBaseUri(BASE_URI); if (path.isEmpty()) { request.setRawRequestUri(BASE_URI); } request.setRawODataPath(path); request.setRawQueryPath(query); if (headerName != null) { request.addHeader(headerName, Collections.singletonList(headerValue)); } if (headerName != HttpHeader.CONTENT_TYPE) { request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList( ContentType.JSON.toContentTypeString())); } final OData odata = OData.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata( new EdmTechProvider(), Collections.<EdmxReference> emptyList()); ODataHandlerImpl handler = new ODataHandlerImpl(odata, metadata, new ServerCoreDebugger(odata)); if (processor != null) { handler.register(processor); } final ODataResponse response = handler.process(request); assertNotNull(response); return response; }
Example 6
Source File: ODataHandlerImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ODataResponse dispatchToValidateHeaders(final HttpMethod method, final String path, final String query, final Map<String, String> headers, final Processor processor) throws ODataHandlerException { ODataRequest request = new ODataRequest(); request.setMethod(method); request.setRawBaseUri(BASE_URI); for (Entry<String, String> header : headers.entrySet()) { request.addHeader(header.getKey(), header.getValue()); } if (path.isEmpty()) { request.setRawRequestUri(BASE_URI); } request.setRawODataPath(path); request.setRawQueryPath(query); final OData odata = OData.newInstance(); final ServiceMetadata metadata = odata.createServiceMetadata( new EdmTechProvider(), Collections.<EdmxReference> emptyList()); ODataHandlerImpl handler = new ODataHandlerImpl(odata, metadata, new ServerCoreDebugger(odata)); if (processor != null) { handler.register(processor); } final ODataResponse response = handler.process(request); return response; }
Example 7
Source File: BatchRequestTransformator.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ODataRequest createRequest(final BatchQueryOperation operation, final String baseUri, final boolean isChangeSet) throws BatchDeserializerException { final HttpRequestStatusLine statusLine = new HttpRequestStatusLine(operation.getHttpStatusLine(), baseUri, rawServiceResolutionUri); statusLine.validateHttpMethod(isChangeSet); BatchTransformatorCommon.validateHost(operation.getHeaders(), baseUri); validateBody(statusLine, operation); Charset charset = getCharset(operation); InputStream bodyStream = getBodyStream(operation, statusLine, charset); validateForbiddenHeader(operation); final ODataRequest request = new ODataRequest(); request.setBody(bodyStream); request.setMethod(statusLine.getMethod()); request.setRawBaseUri(statusLine.getRawBaseUri()); request.setRawODataPath(statusLine.getRawODataPath()); request.setRawQueryPath(statusLine.getRawQueryPath()); request.setRawRequestUri(statusLine.getRawRequestUri()); request.setRawServiceResolutionUri(statusLine.getRawServiceResolutionUri()); for (final HeaderField field : operation.getHeaders()) { request.addHeader(field.getFieldName(), field.getValues()); } return request; }
Example 8
Source File: DebugTabRequestTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void singleHeaderValue() throws Exception { String expectedJson = "{\"method\":\"GET\",\"uri\":\"def&\",\"protocol\":\"def&\",\"headers\":{\"HeaderName\":\"Value1\"}}"; String expectedHtml = "<h2>Request Method</h2>\n" + "<p>GET</p>\n" + "<h2>Request URI</h2>\n" + "<p>def&</p>\n" + "<h2>Request Protocol</h2>\n" + "<p>def&</p>\n" + "<h2>Request Headers</h2>\n" + "<table>\n" + "<thead>\n" + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n" + "</thead>\n" + "<tbody>\n" + "<tr><td class=\"name\">HeaderName</td><td class=\"value\">Value1</td></tr>\n" + "</tbody>\n" + "</table>\n"; ODataRequest oDataRequest = new ODataRequest(); oDataRequest.setMethod(HttpMethod.GET); oDataRequest.setRawRequestUri("def&"); oDataRequest.setProtocol("def&"); List<String> headerValues = new ArrayList<String>(); headerValues.add("Value1"); oDataRequest.addHeader("HeaderName", headerValues); DebugTabRequest requestTab = new DebugTabRequest(oDataRequest); assertEquals(expectedJson, createJson(requestTab)); assertEquals(expectedHtml, createHtml(requestTab)); }
Example 9
Source File: DebugTabRequestTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void multiHeaderValueResultsInMap() throws Exception { String expectedJson = "{\"method\":\"GET\",\"uri\":\"def&\",\"protocol\":\"def&\"," + "\"headers\":{\"HeaderName\":[\"Value1\",\"Value2\"]}}"; String expectedHtml = "<h2>Request Method</h2>\n" + "<p>GET</p>\n" + "<h2>Request URI</h2>\n" + "<p>def&</p>\n" + "<h2>Request Protocol</h2>\n" + "<p>def&</p>\n" + "<h2>Request Headers</h2>\n" + "<table>\n" + "<thead>\n" + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n" + "</thead>\n" + "<tbody>\n" + "<tr><td class=\"name\">HeaderName</td><td class=\"value\">Value1</td></tr>\n" + "<tr><td class=\"name\">HeaderName</td><td class=\"value\">Value2</td></tr>\n" + "</tbody>\n" + "</table>\n"; ODataRequest oDataRequest = new ODataRequest(); oDataRequest.setMethod(HttpMethod.GET); oDataRequest.setRawRequestUri("def&"); oDataRequest.setProtocol("def&"); List<String> headerValues = new ArrayList<String>(); headerValues.add("Value1"); headerValues.add("Value2"); oDataRequest.addHeader("HeaderName", headerValues); DebugTabRequest requestTab = new DebugTabRequest(oDataRequest); assertEquals(expectedJson, createJson(requestTab)); assertEquals(expectedHtml, createHtml(requestTab)); }
Example 10
Source File: BatchReferenceRewriter.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void replaceContentIdReference(final ODataRequest request, final String contentId, final String resourceUri) { final String newUri = request.getRawODataPath().replace("/$" + contentId, resourceUri); request.setRawODataPath(newUri); request.setRawRequestUri(request.getRawBaseUri() + "/" + newUri); }