@Test public void testResultsNotSentWhenRequestOrResponseNotAvailable() { Configuration configuration = mock(Configuration.class); when(configuration.getResponseCode(any(SearchResultsOutcome.class))).thenReturn(200); AsyncContext userResponse = getAsyncContext(null,null); SearchResponseContext responseHolder = new AsyncServletSearchResponseContext(userResponse,System.nanoTime()); SearchResponseContextHandler handler = getHandler(configuration); handler.sendResults("results","appplication/json",null,responseHolder); verify(configuration,times(0)).getResponseCode(any(SearchResultsOutcome.class)); responseHolder.close(); verify(userResponse,times(1)).complete(); }
@Override public void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx) { AsyncContext ctx = sctx.getSearchResponseContext(); HttpServletResponse r = null; try { ServletRequest request = ctx.getRequest(); if(request==null) { return; } r = (HttpServletResponse)ctx.getResponse(); if(r!=null) { int statusCode = configuration.getResponseCode(results.getOutcomeType()); r.setStatus(statusCode); r.setContentType(mediaType); r.getWriter().write(resultsAsString); } } catch (IOException e) { if(r!=null) { r.setStatus(500); } } catch (IllegalStateException e) { log.warn("Async Context not available",e); } }
HttpAsyncSearchResponseContextHandler implements SearchResponseContextHandler<AsyncContext> { @Override public void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx) { AsyncContext ctx = sctx.getSearchResponseContext(); HttpServletResponse r = null; try { ServletRequest request = ctx.getRequest(); if(request==null) { return; } r = (HttpServletResponse)ctx.getResponse(); if(r!=null) { int statusCode = configuration.getResponseCode(results.getOutcomeType()); r.setStatus(statusCode); r.setContentType(mediaType); r.getWriter().write(resultsAsString); } } catch (IOException e) { if(r!=null) { r.setStatus(500); } } catch (IllegalStateException e) { log.warn("Async Context not available",e); } } }
HttpAsyncSearchResponseContextHandler implements SearchResponseContextHandler<AsyncContext> { @Override public void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx) { AsyncContext ctx = sctx.getSearchResponseContext(); HttpServletResponse r = null; try { ServletRequest request = ctx.getRequest(); if(request==null) { return; } r = (HttpServletResponse)ctx.getResponse(); if(r!=null) { int statusCode = configuration.getResponseCode(results.getOutcomeType()); r.setStatus(statusCode); r.setContentType(mediaType); r.getWriter().write(resultsAsString); } } catch (IOException e) { if(r!=null) { r.setStatus(500); } } catch (IllegalStateException e) { log.warn("Async Context not available",e); } } HttpAsyncSearchResponseContextHandler(Configuration configuration); }
HttpAsyncSearchResponseContextHandler implements SearchResponseContextHandler<AsyncContext> { @Override public void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx) { AsyncContext ctx = sctx.getSearchResponseContext(); HttpServletResponse r = null; try { ServletRequest request = ctx.getRequest(); if(request==null) { return; } r = (HttpServletResponse)ctx.getResponse(); if(r!=null) { int statusCode = configuration.getResponseCode(results.getOutcomeType()); r.setStatus(statusCode); r.setContentType(mediaType); r.getWriter().write(resultsAsString); } } catch (IOException e) { if(r!=null) { r.setStatus(500); } } catch (IllegalStateException e) { log.warn("Async Context not available",e); } } HttpAsyncSearchResponseContextHandler(Configuration configuration); @Override void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx); }
HttpAsyncSearchResponseContextHandler implements SearchResponseContextHandler<AsyncContext> { @Override public void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx) { AsyncContext ctx = sctx.getSearchResponseContext(); HttpServletResponse r = null; try { ServletRequest request = ctx.getRequest(); if(request==null) { return; } r = (HttpServletResponse)ctx.getResponse(); if(r!=null) { int statusCode = configuration.getResponseCode(results.getOutcomeType()); r.setStatus(statusCode); r.setContentType(mediaType); r.getWriter().write(resultsAsString); } } catch (IOException e) { if(r!=null) { r.setStatus(500); } } catch (IllegalStateException e) { log.warn("Async Context not available",e); } } HttpAsyncSearchResponseContextHandler(Configuration configuration); @Override void sendResults(String resultsAsString, String mediaType, SearchResultsEvent results, SearchResponseContext<AsyncContext> sctx);  }