MCPcopy Create free account
hub / github.com/apache/tomcat / doGet

Method doGet

test/org/apache/coyote/http2/TestAsync.java:215–273  ·  view source on GitHub ↗
(HttpServletRequest request, HttpServletResponse response)

Source from the content-addressed store, hash-verified

213 * Not thread-safe. OK for this test. NOt OK for use in the real world.
214 */
215 @Override
216 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
217
218 final AsyncContext asyncContext = request.startAsync();
219
220 response.setStatus(HttpServletResponse.SC_OK);
221 response.setContentType("application/binary");
222
223 final ServletOutputStream output = response.getOutputStream();
224 output.setWriteListener(new WriteListener() {
225
226 // Intermittent CI errors were observed where the response body
227 // was exactly one block too small. Use an AtomicInteger to be
228 // sure blockCount is thread-safe.
229 final AtomicInteger blockCount = new AtomicInteger(0);
230 byte[] bytes = new byte[BLOCK_SIZE];
231
232
233 @Override
234 public void onWritePossible() throws IOException {
235 if (useNonContainerThreadForWrite) {
236 future = scheduler.schedule(new Runnable() {
237
238 @Override
239 public void run() {
240 try {
241 write();
242 } catch (IOException ioe) {
243 throw new IllegalStateException(ioe);
244 }
245 }
246 }, 200, TimeUnit.MILLISECONDS);
247 } else {
248 write();
249 }
250 }
251
252
253 private void write() throws IOException {
254 while (output.isReady()) {
255 blockCount.incrementAndGet();
256 output.write(bytes);
257 if (blockCount.get() == blockLimit) {
258 asyncContext.complete();
259 scheduler.shutdown();
260 return;
261 }
262 }
263 }
264
265 @Override
266 public void onError(Throwable t) {
267 if (future != null) {
268 future.cancel(false);
269 }
270 t.printStackTrace();
271 }
272 });

Callers

nothing calls this directly

Calls 5

setWriteListenerMethod · 0.95
startAsyncMethod · 0.65
setStatusMethod · 0.65
setContentTypeMethod · 0.65
getOutputStreamMethod · 0.65

Tested by

no test coverage detected