1
2
3
4
5
6
7
8
9
10
11
12
13 package org.eclipse.jetty.server;
14
15 import java.io.IOException;
16
17 import org.eclipse.jetty.http.Generator;
18 import org.eclipse.jetty.http.HttpException;
19 import org.eclipse.jetty.http.HttpStatus;
20 import org.eclipse.jetty.http.Parser;
21 import org.eclipse.jetty.io.Connection;
22 import org.eclipse.jetty.io.EndPoint;
23 import org.eclipse.jetty.util.log.Log;
24 import org.eclipse.jetty.util.log.Logger;
25
26
27
28
29
30 public class BlockingHttpConnection extends AbstractHttpConnection
31 {
32 private static final Logger LOG = Log.getLogger(BlockingHttpConnection.class);
33
34 public BlockingHttpConnection(Connector connector, EndPoint endpoint, Server server)
35 {
36 super(connector,endpoint,server);
37 }
38
39 public BlockingHttpConnection(Connector connector, EndPoint endpoint, Server server, Parser parser, Generator generator, Request request)
40 {
41 super(connector,endpoint,server,parser,generator,request);
42 }
43
44 @Override
45 protected void handleRequest() throws IOException
46 {
47 super.handleRequest();
48 }
49
50 public Connection handle() throws IOException
51 {
52 Connection connection = this;
53
54 try
55 {
56 setCurrentConnection(this);
57
58
59
60 while (_endp.isOpen() && connection==this)
61 {
62 try
63 {
64
65 if (!_parser.isComplete() && !_endp.isInputShutdown())
66 _parser.parseAvailable();
67
68
69
70
71
72 if (_generator.isCommitted() && !_generator.isComplete() && !_endp.isOutputShutdown())
73 _generator.flushBuffer();
74
75
76 _endp.flush();
77 }
78 catch (HttpException e)
79 {
80 if (LOG.isDebugEnabled())
81 {
82 LOG.debug("uri="+_uri);
83 LOG.debug("fields="+_requestFields);
84 LOG.debug(e);
85 }
86 _generator.sendError(e.getStatus(), e.getReason(), null, true);
87 _parser.reset();
88 _endp.shutdownOutput();
89 }
90 finally
91 {
92
93 if (_parser.isComplete() && _generator.isComplete())
94 {
95
96 reset();
97
98
99 if (_response.getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
100 {
101 Connection switched=(Connection)_request.getAttribute("org.eclipse.jetty.io.Connection");
102 if (switched!=null)
103 connection=switched;
104 }
105
106
107 if (!_generator.isPersistent() && !_endp.isOutputShutdown())
108 {
109 LOG.warn("Safety net oshut!!! Please open a bugzilla");
110 _endp.shutdownOutput();
111 }
112 }
113 }
114 }
115
116 return connection;
117 }
118 finally
119 {
120 setCurrentConnection(null);
121 _parser.returnBuffers();
122 _generator.returnBuffers();
123 }
124 }
125 }