MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / run

Method run

src/test/java/org/htmlunit/util/MiniServer.java:99–202  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

97 }
98
99 @Override
100 public void run() {
101 try {
102 final long maxWait = System.currentTimeMillis() + WebServerTestCase.BIND_TIMEOUT;
103 while (true) {
104 try {
105 serverSocket_ = new ServerSocket(port_);
106 break;
107 }
108 catch (final BindException e) {
109 if (System.currentTimeMillis() > maxWait) {
110 throw (BindException) new BindException("Port " + port_ + " is already in use").initCause(e);
111 }
112 try {
113 Thread.sleep(200);
114 }
115 catch (final InterruptedException ex) {
116 LOG.error(ex.getMessage(), ex);
117 }
118 }
119 }
120
121 started_.set(true);
122 LOG.info("Starting listening on port " + port_);
123 while (!shutdown_) {
124 try (Socket s = serverSocket_.accept()) {
125 try (BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()))) {
126
127 final CharBuffer cb = CharBuffer.allocate(5000);
128 br.read(cb);
129 cb.flip();
130 final String in = cb.toString();
131 cb.rewind();
132
133 RawResponseData responseData = null;
134 final WebRequest request = parseRequest(in);
135
136 // try to get the data to count the request
137 try {
138 if (request != null) {
139 responseData = mockWebConnection_.getRawResponse(request);
140 }
141 }
142 catch (final IllegalStateException e) {
143 LOG.error(e);
144 }
145
146 if (request == null
147 || (DROP_REQUESTS.contains(request.getUrl())
148 || (request.getHttpMethod() == HttpMethod.GET
149 && DROP_GET_REQUESTS.contains(request.getUrl())))) {
150 responseData = null;
151 }
152
153 if (responseData == null) {
154 LOG.info("Closing impolitely in & output streams");
155 s.getOutputStream().close();
156 }

Callers

nothing calls this directly

Calls 15

parseRequestMethod · 0.95
getUrlMethod · 0.95
getHttpMethodMethod · 0.95
getByteContentMethod · 0.95
getStatusCodeMethod · 0.95
getStatusMessageMethod · 0.95
getHeadersMethod · 0.95
getStringContentMethod · 0.95
sleepMethod · 0.80
getMessageMethod · 0.80
getRawResponseMethod · 0.80
getOutputStreamMethod · 0.80

Tested by

no test coverage detected