Java Code Examples for org.apache.olingo.server.api.ODataRequest#addHeader()
The following examples show how to use
org.apache.olingo.server.api.ODataRequest#addHeader() .
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: 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 3
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 4
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 5
Source File: ODataNettyHandlerImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
/** * Copy the headers part of Netty Request to OData Request * @param odRequest * @param req */ static void copyHeaders(ODataRequest odRequest, final HttpRequest req) { final Set<String> headers = req.headers().names(); Iterator<String> headerNames = headers.iterator(); while (headerNames.hasNext()) { final String headerName = headerNames.next(); final List<String> headerValues = req.headers().getAll(headerName); odRequest.addHeader(headerName, headerValues); } }
Example 6
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 7
Source File: ODataHttpHandlerImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
static void copyHeaders(ODataRequest odRequest, final HttpServletRequest req) { for (final Enumeration<?> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) { final String headerName = (String) headerNames.nextElement(); @SuppressWarnings("unchecked") // getHeaders() says it returns an Enumeration of String. final List<String> headerValues = Collections.list(req.getHeaders(headerName)); odRequest.addHeader(headerName, headerValues); } }
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: ContentNegotiatorTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void testContentNegotiation(final String[] useCase, final RepresentationType representationType) throws Exception { FormatOption formatOption = null; if (useCase[1] != null) { formatOption = mock(FormatOption.class); when(formatOption.getFormat()).thenReturn(useCase[1]); } ODataRequest request = new ODataRequest(); if (useCase[2] != null) { request.addHeader(HttpHeader.ACCEPT, Arrays.asList(useCase[2])); } if (useCase.length > 4) { if (useCase[4] != null) { request.addHeader(HttpHeader.ACCEPT_CHARSET, Arrays.asList(useCase[4])); } } final CustomContentTypeSupport customContentTypeSupport = useCase[3] == null ? null : createCustomContentTypeSupport(useCase[3]); final ContentType requestedContentType = ContentNegotiator.doContentNegotiation( formatOption, request, customContentTypeSupport, representationType); assertNotNull(requestedContentType); if (useCase[0] != null) { assertEquals(ContentType.create(useCase[0]), requestedContentType); } }