org.apache.coyote.ErrorState Java Examples
The following examples show how to use
org.apache.coyote.ErrorState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AjpProcessor.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * @deprecated Unused. Will be removed in Tomcat 9. Use * {@link #doWrite(ByteBuffer)} */ @Deprecated @Override public int doWrite(ByteChunk chunk) throws IOException { if (!response.isCommitted()) { // Validate and write response headers try { prepareResponse(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, e); } } if (!swallowResponse) { writeData(chunk); } return chunk.getLength(); }
Example #2
Source File: AjpProcessor.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public int doWrite(ByteBuffer chunk) throws IOException { if (!response.isCommitted()) { // Validate and write response headers try { prepareResponse(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, e); } } int len = 0; if (!swallowResponse) { try { len = chunk.remaining(); writeData(chunk); len -= chunk.remaining(); } catch (IOException ioe) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe); // Re-throw throw ioe; } } return len; }
Example #3
Source File: Http11Processor.java From Tomcat8-Source-Read with MIT License | 6 votes |
private boolean handleIncompleteRequestLineRead() { // Haven't finished reading the request so keep the socket // open openSocket = true; // Check to see if we have read any of the request line yet if (inputBuffer.getParsingRequestLinePhase() > 1) { // Started to read request line. if (endpoint.isPaused()) { // Partially processed the request so need to respond response.setStatus(503); setErrorState(ErrorState.CLOSE_CLEAN, null); return false; } else { // Need to keep processor associated with socket readComplete = false; } } return true; }
Example #4
Source File: Http11NioProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override protected boolean breakKeepAliveLoop(SocketWrapper<NioChannel> socketWrapper) { openSocket = keepAlive; // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !getErrorState().isError()) { ((KeyAttachment) socketWrapper).setSendfileData(sendfileData); sendfileData.keepAlive = keepAlive; SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor( socketWrapper.getSocket().getPoller().getSelector()); //do the first write on this thread, might as well if (socketWrapper.getSocket().getPoller().processSendfile(key, (KeyAttachment) socketWrapper, true)) { sendfileInProgress = true; } else { // Write failed if (log.isDebugEnabled()) { log.debug(sm.getString("http11processor.sendfile.error")); } setErrorState(ErrorState.CLOSE_NOW, null); } return true; } return false; }
Example #5
Source File: Http11NioProcessor.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override protected boolean breakKeepAliveLoop(SocketWrapper<NioChannel> socketWrapper) { openSocket = keepAlive; // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !getErrorState().isError()) { ((KeyAttachment) socketWrapper).setSendfileData(sendfileData); sendfileData.keepAlive = keepAlive; SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor( socketWrapper.getSocket().getPoller().getSelector()); //do the first write on this thread, might as well switch (socketWrapper.getSocket().getPoller().processSendfile( key, (KeyAttachment) socketWrapper, true)) { case DONE: // If sendfile is complete, no need to break keep-alive loop sendfileData = null; return false; case PENDING: sendfileInProgress = true; return true; case ERROR: // Write failed if (log.isDebugEnabled()) { log.debug(sm.getString("http11processor.sendfile.error")); } setErrorState(ErrorState.CLOSE_NOW, null); return true; } } return false; }
Example #6
Source File: AjpProcessor.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * {@inheritDoc} * <p> * This implementation populates the server name from the local name * provided by the AJP message. */ @Override protected void populateHost() { try { request.serverName().duplicate(request.localName()); } catch (IOException e) { response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, e); } }
Example #7
Source File: Http11NioProcessor.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override protected boolean handleIncompleteRequestLineRead() { // Haven't finished reading the request so keep the socket // open openSocket = true; // Check to see if we have read any of the request line yet if (inputBuffer.getParsingRequestLinePhase() < 2) { if (socketWrapper.getLastAccess() > -1 || keptAlive) { // Haven't read the request line and have previously processed a // request. Must be keep-alive. Make sure poller uses keepAlive. socketWrapper.setTimeout(endpoint.getKeepAliveTimeout()); } } else { if (endpoint.isPaused()) { // Partially processed the request so need to respond response.setStatus(503); setErrorState(ErrorState.CLOSE_CLEAN, null); getAdapter().log(request, response, 0); return false; } else { // Need to keep processor associated with socket readComplete = false; // Make sure poller uses soTimeout from here onwards socketWrapper.setTimeout(endpoint.getSoTimeout()); } } return true; }
Example #8
Source File: Http11AprProcessor.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override protected boolean breakKeepAliveLoop(SocketWrapper<Long> socketWrapper) { openSocket = keepAlive; // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !getErrorState().isError()) { sendfileData.socket = socketWrapper.getSocket().longValue(); sendfileData.keepAlive = keepAlive; if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) { // Didn't send all of the data to sendfile. if (sendfileData.socket == 0) { // The socket is no longer set. Something went wrong. // Close the connection. Too late to set status code. if (log.isDebugEnabled()) { log.debug(sm.getString( "http11processor.sendfile.error")); } setErrorState(ErrorState.CLOSE_NOW, null); } else { // The sendfile Poller will add the socket to the main // Poller once sendfile processing is complete sendfileInProgress = true; } return true; } } return false; }
Example #9
Source File: Http11AprProcessor.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Process pipelined HTTP requests using the specified input and output * streams. * * @throws IOException error during an I/O operation */ @Override public SocketState event(SocketStatus status) throws IOException { RequestInfo rp = request.getRequestProcessor(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if (!getAdapter().event(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // 500 - Internal Server Error response.setStatus(500); setErrorState(ErrorState.CLOSE_NOW, t); getAdapter().log(request, response, 0); log.error(sm.getString("http11processor.request.process"), t); } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (getErrorState().isError() || status==SocketStatus.STOP) { return SocketState.CLOSED; } else if (!comet) { inputBuffer.nextRequest(); outputBuffer.nextRequest(); return SocketState.OPEN; } else { return SocketState.LONG; } }
Example #10
Source File: AbstractAjpProcessor.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Finish AJP response. */ protected void finish() throws IOException { if (!response.isCommitted()) { // Validate and write response headers try { prepareResponse(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_NOW, e); return; } } if (finished) return; finished = true; // Swallow the unread body packet if present if (first && request.getContentLengthLong() > 0) { receive(); } // Add the end message if (getErrorState().isError()) { output(endAndCloseMessageArray, 0, endAndCloseMessageArray.length); } else { output(endMessageArray, 0, endMessageArray.length); } }
Example #11
Source File: Http11NioProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override protected boolean handleIncompleteRequestLineRead() { // Haven't finished reading the request so keep the socket // open openSocket = true; // Check to see if we have read any of the request line yet if (inputBuffer.getParsingRequestLinePhase() < 2) { if (socketWrapper.getLastAccess() > -1 || keptAlive) { // Haven't read the request line and have previously processed a // request. Must be keep-alive. Make sure poller uses keepAlive. socketWrapper.setTimeout(endpoint.getKeepAliveTimeout()); } } else { if (endpoint.isPaused()) { // Partially processed the request so need to respond response.setStatus(503); setErrorState(ErrorState.CLOSE_CLEAN, null); getAdapter().log(request, response, 0); return false; } else { // Need to keep processor associated with socket readComplete = false; // Make sure poller uses soTimeout from here onwards socketWrapper.setTimeout(endpoint.getSoTimeout()); } } return true; }
Example #12
Source File: Http11AprProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override protected boolean breakKeepAliveLoop(SocketWrapper<Long> socketWrapper) { openSocket = keepAlive; // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !getErrorState().isError()) { sendfileData.socket = socketWrapper.getSocket().longValue(); sendfileData.keepAlive = keepAlive; if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) { // Didn't send all of the data to sendfile. if (sendfileData.socket == 0) { // The socket is no longer set. Something went wrong. // Close the connection. Too late to set status code. if (log.isDebugEnabled()) { log.debug(sm.getString( "http11processor.sendfile.error")); } setErrorState(ErrorState.CLOSE_NOW, null); } else { // The sendfile Poller will add the socket to the main // Poller once sendfile processing is complete sendfileInProgress = true; } return true; } } return false; }
Example #13
Source File: Http11AprProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Process pipelined HTTP requests using the specified input and output * streams. * * @throws IOException error during an I/O operation */ @Override public SocketState event(SocketStatus status) throws IOException { RequestInfo rp = request.getRequestProcessor(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if (!getAdapter().event(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // 500 - Internal Server Error response.setStatus(500); setErrorState(ErrorState.CLOSE_NOW, t); getAdapter().log(request, response, 0); log.error(sm.getString("http11processor.request.process"), t); } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (getErrorState().isError() || status==SocketStatus.STOP) { return SocketState.CLOSED; } else if (!comet) { inputBuffer.nextRequest(); outputBuffer.nextRequest(); return SocketState.OPEN; } else { return SocketState.LONG; } }
Example #14
Source File: AbstractHttp11Processor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public SocketState asyncDispatch(SocketStatus status) { RequestInfo rp = request.getRequestProcessor(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if (!getAdapter().asyncDispatch(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } resetTimeouts(); } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); setErrorState(ErrorState.CLOSE_NOW, t); getLog().error(sm.getString("http11processor.request.process"), t); } finally { if (getErrorState().isError()) { // 500 - Internal Server Error response.setStatus(500); adapter.log(request, response, 0); } } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (getErrorState().isError()) { return SocketState.CLOSED; } else if (isAsync()) { return SocketState.LONG; } else { if (!keepAlive) { return SocketState.CLOSED; } else { getInputBuffer().nextRequest(); getOutputBuffer().nextRequest(); return SocketState.OPEN; } } }
Example #15
Source File: AbstractHttp11Processor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Add an input filter to the current request. If the encoding is not * supported, a 501 response will be returned to the client. */ private void addInputFilter(InputFilter[] inputFilters, String encodingName) { // Trim provided encoding name and convert to lower case since transfer // encoding names are case insensitive. (RFC2616, section 3.6) encodingName = encodingName.trim().toLowerCase(Locale.ENGLISH); if (encodingName.equals("identity")) { // Skip } else if (encodingName.equals("chunked")) { getInputBuffer().addActiveFilter (inputFilters[Constants.CHUNKED_FILTER]); contentDelimitation = true; } else { for (int i = pluggableFilterIndex; i < inputFilters.length; i++) { if (inputFilters[i].getEncodingName().toString().equals(encodingName)) { getInputBuffer().addActiveFilter(inputFilters[i]); return; } } // Unsupported transfer encoding // 501 - Unimplemented response.setStatus(501); setErrorState(ErrorState.CLOSE_CLEAN, null); if (getLog().isDebugEnabled()) { getLog().debug(sm.getString("http11processor.request.prepare") + " Unsupported transfer encoding [" + encodingName + "]"); } } }
Example #16
Source File: StreamProcessor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override protected final void ack() { if (!response.isCommitted() && request.hasExpectation()) { try { stream.writeAck(); } catch (IOException ioe) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe); } } }
Example #17
Source File: AbstractAjpProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Finish AJP response. */ protected void finish() throws IOException { if (!response.isCommitted()) { // Validate and write response headers try { prepareResponse(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_NOW, e); return; } } if (finished) return; finished = true; // Swallow the unread body packet if present if (first && request.getContentLengthLong() > 0) { receive(); } // Add the end message if (getErrorState().isError()) { output(endAndCloseMessageArray, 0, endAndCloseMessageArray.length); } else { output(endMessageArray, 0, endMessageArray.length); } }
Example #18
Source File: StreamProcessor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override protected final void doPush(Request pushTarget) { try { stream.push(pushTarget); } catch (IOException ioe) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe); response.setErrorException(ioe); } }
Example #19
Source File: StreamProcessor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public SocketState service(SocketWrapperBase<?> socket) throws IOException { try { adapter.service(request, response); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug(sm.getString("streamProcessor.service.error"), e); } response.setStatus(500); setErrorState(ErrorState.CLOSE_NOW, e); } if (!isAsync()) { // If this is an async request then the request ends when it has // been completed. The AsyncContext is responsible for calling // endRequest() in that case. endRequest(); } if (getErrorState().isError()) { action(ActionCode.CLOSE, null); request.updateCounters(); return SocketState.CLOSED; } else if (isAsync()) { return SocketState.LONG; } else { action(ActionCode.CLOSE, null); request.updateCounters(); return SocketState.CLOSED; } }
Example #20
Source File: Http11Processor.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Trigger sendfile processing if required. * * @return The state of send file processing */ private SendfileState processSendfile(SocketWrapperBase<?> socketWrapper) { openSocket = keepAlive; // Done is equivalent to sendfile not being used SendfileState result = SendfileState.DONE; // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !getErrorState().isError()) { if (keepAlive) { if (available(false) == 0) { sendfileData.keepAliveState = SendfileKeepAliveState.OPEN; } else { sendfileData.keepAliveState = SendfileKeepAliveState.PIPELINED; } } else { sendfileData.keepAliveState = SendfileKeepAliveState.NONE; } result = socketWrapper.processSendfile(sendfileData); switch (result) { case ERROR: // Write failed if (log.isDebugEnabled()) { log.debug(sm.getString("http11processor.sendfile.error")); } setErrorState(ErrorState.CLOSE_CONNECTION_NOW, null); //$FALL-THROUGH$ default: sendfileData = null; } } return result; }
Example #21
Source File: Http11Processor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override protected final void ack() { // Acknowledge request // Send a 100 status back if it makes sense (response not committed // yet, and client specified an expectation for 100-continue) if (!response.isCommitted() && request.hasExpectation()) { inputBuffer.setSwallowInput(true); try { outputBuffer.sendAck(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, e); } } }
Example #22
Source File: AbstractAjpProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Write chunk. */ @Override public int doWrite(ByteChunk chunk, Response res) throws IOException { if (!response.isCommitted()) { // Validate and write response headers try { prepareResponse(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } } if (!swallowResponse) { int len = chunk.getLength(); // 4 - hardcoded, byte[] marshaling overhead // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE) int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE; int off = 0; while (len > 0) { int thisTime = len; if (thisTime > chunkSize) { thisTime = chunkSize; } len -= thisTime; responseMessage.reset(); responseMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK); responseMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime); responseMessage.end(); output(responseMessage.getBuffer(), 0, responseMessage.getLen()); off += thisTime; } bytesWritten += chunk.getLength(); } return chunk.getLength(); }
Example #23
Source File: Http11Processor.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Add an input filter to the current request. If the encoding is not * supported, a 501 response will be returned to the client. */ private void addInputFilter(InputFilter[] inputFilters, String encodingName) { // Parsing trims and converts to lower case. if (encodingName.equals("identity")) { // Skip } else if (encodingName.equals("chunked")) { inputBuffer.addActiveFilter (inputFilters[Constants.CHUNKED_FILTER]); contentDelimitation = true; } else { for (int i = pluggableFilterIndex; i < inputFilters.length; i++) { if (inputFilters[i].getEncodingName().toString().equals(encodingName)) { inputBuffer.addActiveFilter(inputFilters[i]); return; } } // Unsupported transfer encoding // 501 - Unimplemented response.setStatus(501); setErrorState(ErrorState.CLOSE_CLEAN, null); if (log.isDebugEnabled()) { log.debug(sm.getString("http11processor.request.prepare") + " Unsupported transfer encoding [" + encodingName + "]"); } } }
Example #24
Source File: Http11Processor.java From Tomcat8-Source-Read with MIT License | 5 votes |
private void badRequest(String errorKey) { response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, null); if (log.isDebugEnabled()) { log.debug(sm.getString(errorKey)); } }
Example #25
Source File: AbstractAjpProcessor.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public SocketState asyncDispatch(SocketStatus status) { RequestInfo rp = request.getRequestProcessor(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if(!getAdapter().asyncDispatch(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } resetTimeouts(); } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); setErrorState(ErrorState.CLOSE_NOW, t); getLog().error(sm.getString("http11processor.request.process"), t); } finally { if (getErrorState().isError()) { // 500 - Internal Server Error response.setStatus(500); adapter.log(request, response, 0); } } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (isAsync()) { if (getErrorState().isError()) { request.updateCounters(); return SocketState.CLOSED; } else { return SocketState.LONG; } } else { request.updateCounters(); if (getErrorState().isError()) { return SocketState.CLOSED; } else { recycle(false); return SocketState.OPEN; } } }
Example #26
Source File: Http11NioProcessor.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Process pipelined HTTP requests using the specified input and output * streams. * * @throws IOException error during an I/O operation */ @Override public SocketState event(SocketStatus status) throws IOException { long soTimeout = endpoint.getSoTimeout(); RequestInfo rp = request.getRequestProcessor(); final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socketWrapper.getSocket().getAttachment(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if (!getAdapter().event(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } if (!getErrorState().isError()) { if (attach != null) { attach.setComet(comet); if (comet) { Integer comettimeout = (Integer) request.getAttribute( org.apache.coyote.Constants.COMET_TIMEOUT_ATTR); if (comettimeout != null) { attach.setTimeout(comettimeout.longValue()); } } else { //reset the timeout if (keepAlive) { attach.setTimeout(keepAliveTimeout); } else { attach.setTimeout(soTimeout); } } } } } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // 500 - Internal Server Error response.setStatus(500); setErrorState(ErrorState.CLOSE_NOW, t); log.error(sm.getString("http11processor.request.process"), t); getAdapter().log(request, response, 0); } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (getErrorState().isError() || status==SocketStatus.STOP) { return SocketState.CLOSED; } else if (!comet) { if (keepAlive) { inputBuffer.nextRequest(); outputBuffer.nextRequest(); return SocketState.OPEN; } else { return SocketState.CLOSED; } } else { return SocketState.LONG; } }
Example #27
Source File: AbstractAjpProcessor.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Write chunk. */ @Override public int doWrite(ByteChunk chunk, Response res) throws IOException { if (!response.isCommitted()) { // Validate and write response headers try { prepareResponse(); } catch (IOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } } if (!swallowResponse) { try { int len = chunk.getLength(); // 4 - hardcoded, byte[] marshaling overhead // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE) int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE; int off = 0; while (len > 0) { int thisTime = len; if (thisTime > chunkSize) { thisTime = chunkSize; } len -= thisTime; responseMessage.reset(); responseMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK); responseMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime); responseMessage.end(); output(responseMessage.getBuffer(), 0, responseMessage.getLen()); off += thisTime; } bytesWritten += chunk.getLength(); } catch (IOException ioe) { response.action(ActionCode.CLOSE_NOW, ioe); // Re-throw throw ioe; } } return chunk.getLength(); }
Example #28
Source File: AbstractAjpProcessor.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Parse host. */ protected void parseHost(MessageBytes valueMB) { if (valueMB == null || valueMB.isNull()) { // HTTP/1.0 request.setServerPort(request.getLocalPort()); try { request.serverName().duplicate(request.localName()); } catch (IOException e) { response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, e); } return; } ByteChunk valueBC = valueMB.getByteChunk(); byte[] valueB = valueBC.getBytes(); int valueL = valueBC.getLength(); int valueS = valueBC.getStart(); int colonPos = -1; if (hostNameC.length < valueL) { hostNameC = new char[valueL]; } boolean ipv6 = (valueB[valueS] == '['); boolean bracketClosed = false; for (int i = 0; i < valueL; i++) { char b = (char) valueB[i + valueS]; hostNameC[i] = b; if (b == ']') { bracketClosed = true; } else if (b == ':') { if (!ipv6 || bracketClosed) { colonPos = i; break; } } } if (colonPos < 0) { if (request.scheme().equalsIgnoreCase("https")) { // 443 - Default HTTPS port request.setServerPort(443); } else { // 80 - Default HTTTP port request.setServerPort(80); } request.serverName().setChars(hostNameC, 0, valueL); } else { request.serverName().setChars(hostNameC, 0, colonPos); int port = 0; int mult = 1; for (int i = valueL - 1; i > colonPos; i--) { int charValue = HexUtils.getDec(valueB[i + valueS]); if (charValue == -1) { // Invalid character // 400 - Bad request response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, null); break; } port = port + (charValue * mult); mult = 10 * mult; } request.setServerPort(port); } }
Example #29
Source File: Http11NioProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Process pipelined HTTP requests using the specified input and output * streams. * * @throws IOException error during an I/O operation */ @Override public SocketState event(SocketStatus status) throws IOException { long soTimeout = endpoint.getSoTimeout(); RequestInfo rp = request.getRequestProcessor(); final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socketWrapper.getSocket().getAttachment(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if (!getAdapter().event(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } if (!getErrorState().isError()) { if (attach != null) { attach.setComet(comet); if (comet) { Integer comettimeout = (Integer) request.getAttribute( org.apache.coyote.Constants.COMET_TIMEOUT_ATTR); if (comettimeout != null) { attach.setTimeout(comettimeout.longValue()); } } else { //reset the timeout if (keepAlive) { attach.setTimeout(keepAliveTimeout); } else { attach.setTimeout(soTimeout); } } } } } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // 500 - Internal Server Error response.setStatus(500); setErrorState(ErrorState.CLOSE_NOW, t); log.error(sm.getString("http11processor.request.process"), t); getAdapter().log(request, response, 0); } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (getErrorState().isError() || status==SocketStatus.STOP) { return SocketState.CLOSED; } else if (!comet) { if (keepAlive) { inputBuffer.nextRequest(); outputBuffer.nextRequest(); return SocketState.OPEN; } else { return SocketState.CLOSED; } } else { return SocketState.LONG; } }
Example #30
Source File: AbstractAjpProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public SocketState asyncDispatch(SocketStatus status) { RequestInfo rp = request.getRequestProcessor(); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); if(!getAdapter().asyncDispatch(request, response, status)) { setErrorState(ErrorState.CLOSE_NOW, null); } resetTimeouts(); } catch (InterruptedIOException e) { setErrorState(ErrorState.CLOSE_NOW, e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); setErrorState(ErrorState.CLOSE_NOW, t); getLog().error(sm.getString("http11processor.request.process"), t); } finally { if (getErrorState().isError()) { // 500 - Internal Server Error response.setStatus(500); adapter.log(request, response, 0); } } rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); if (isAsync()) { if (getErrorState().isError()) { request.updateCounters(); return SocketState.CLOSED; } else { return SocketState.LONG; } } else { request.updateCounters(); if (getErrorState().isError()) { return SocketState.CLOSED; } else { return SocketState.OPEN; } } }