@Test public void headers() throws Exception { ODataContext context = mockContext(ODataHttpMethod.GET); Map<String, List<String>> headers = new HashMap<String, List<String>>(); headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(HttpContentType.APPLICATION_JSON)); when(context.getRequestHeaders()).thenReturn(headers); final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, HttpContentType.APPLICATION_JSON); ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null, ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse(); String entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals(EXPECTED.replace("},\"response", ",\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"" + HttpContentType.APPLICATION_JSON + "\"}},\"response") .replace("}},\"server", "},\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"" + HttpContentType.APPLICATION_JSON + "\"}},\"server"), entity); response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null, ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse(); entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertTrue(entity.contains("<td class=\"name\">Content-Type</td><td class=\"value\">application/json</td>")); }
public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
      final Exception exception, final String debugValue); }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
      final Exception exception, final String debugValue); ODataResponse wrapResponse(); }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
      final Exception exception, final String debugValue); ODataResponse wrapResponse(); static final String ODATA_DEBUG_QUERY_PARAMETER; static final String ODATA_DEBUG_JSON; static final String ODATA_DEBUG_HTML; static final String ODATA_DEBUG_DOWNLOAD; }