Skip to content

Commit

Permalink
jetty-9 removed HttpException
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed May 17, 2012
1 parent 6502370 commit b9a2661
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 202 deletions.
88 changes: 0 additions & 88 deletions jetty-http/src/main/java/org/eclipse/jetty/http/HttpException.java

This file was deleted.

78 changes: 43 additions & 35 deletions jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private String takeLengthString()
/* ------------------------------------------------------------------------------- */
/* Parse a request or response line
*/
private boolean parseLine(ByteBuffer buffer) throws IOException
private boolean parseLine(ByteBuffer buffer)
{
boolean return_from_parse=false;

Expand Down Expand Up @@ -311,7 +311,8 @@ private boolean parseLine(ByteBuffer buffer) throws IOException
}
else if (ch < HttpTokens.SPACE && ch>=0)
{
throw new HttpException(HttpStatus.BAD_REQUEST_400);
badMessage(buffer, "No URI");
return true;
}
else
_string.append((char)ch);
Expand All @@ -323,13 +324,17 @@ else if (ch < HttpTokens.SPACE && ch>=0)
String version=takeString();
_version=HttpVersion.CACHE.get(version);
if (_version==null)
throw new HttpException(HttpStatus.BAD_REQUEST_400);
{
badMessage(buffer, "Unknown Version");
return true;
}
_persistent=HttpVersion.HTTP_1_1==_version;
_state=State.SPACE1;
}
else if (ch < HttpTokens.SPACE && ch>=0)
{
throw new HttpException(HttpStatus.BAD_REQUEST_400);
badMessage(buffer, "No Status");
return true;
}
else
_string.append((char)ch);
Expand All @@ -352,7 +357,8 @@ else if (ch < HttpTokens.SPACE && ch>=0)
}
else if (ch < HttpTokens.SPACE)
{
throw new HttpException(HttpStatus.BAD_REQUEST_400);
badMessage(buffer, _requestHandler!=null?"No URI":"No Status");
return true;
}
break;

Expand Down Expand Up @@ -455,7 +461,10 @@ else if (ch < HttpTokens.SPACE)
String version = takeString();
_version=HttpVersion.CACHE.get(version);
if (_version==null)
throw new HttpException(HttpStatus.BAD_REQUEST_400);
{
badMessage(buffer, "Unknown Version");
return true;
}

_eol=ch;
_persistent=HttpVersion.HTTP_1_1==_version;
Expand Down Expand Up @@ -499,7 +508,7 @@ else if (ch < HttpTokens.SPACE)
/*
* Parse the message headers and return true if the handler has signaled for a return
*/
private boolean parseHeaders(ByteBuffer buffer) throws IOException
private boolean parseHeaders(ByteBuffer buffer)
{
boolean return_from_parse=false;

Expand Down Expand Up @@ -552,7 +561,8 @@ private boolean parseHeaders(ByteBuffer buffer) throws IOException
catch(NumberFormatException e)
{
LOG.ignore(e);
throw new HttpException(HttpStatus.BAD_REQUEST_400);
badMessage(buffer, "Bad Content-Length");
return true;
}
if (_contentLength <= 0)
_endOfContent=EndOfContent.NO_CONTENT;
Expand All @@ -569,7 +579,10 @@ private boolean parseHeaders(ByteBuffer buffer) throws IOException
if (_valueString.endsWith(HttpHeaderValue.CHUNKED.toString()))
_endOfContent=EndOfContent.CHUNKED_CONTENT;
else if (_valueString.indexOf(HttpHeaderValue.CHUNKED.toString()) >= 0)
throw new HttpException(400,null);
{
badMessage(buffer, "Bad chunking");
return true;
}
}
break;

Expand Down Expand Up @@ -852,9 +865,6 @@ else if (HttpHeaderValue.hasKnownValues(_header))
*/
public boolean parseNext(ByteBuffer buffer) throws IOException
{
int start=-1;
State startState=null;

try
{
// process end states
Expand Down Expand Up @@ -1056,23 +1066,22 @@ else if (ch >= 'A' && ch <= 'F')

return false;
}
catch(HttpException e)
{
_persistent=false;
_state=State.SEEKING_EOF;
throw e;
}
finally
catch(Exception e)
{
if (start>=0)
{
_string.setLength(0);
buffer.position(start);
_state=startState;
}

LOG.debug(e);
_handler.badMessage(e.toString());
return true;
}
}

/* ------------------------------------------------------------------------------- */
private void badMessage(ByteBuffer buffer, String reason)
{
BufferUtil.clear(buffer);
_persistent=false;
_state=State.SEEKING_EOF;
_handler.badMessage(reason);
}

/* ------------------------------------------------------------------------------- */
public boolean inputShutdown() throws IOException
Expand Down Expand Up @@ -1142,41 +1151,40 @@ public String toString()
*/
public interface HttpHandler
{
public boolean content(ByteBuffer ref) throws IOException;
public boolean content(ByteBuffer ref);

public boolean headerComplete(boolean hasBody,boolean persistent) throws IOException;
public boolean headerComplete(boolean hasBody,boolean persistent);

public boolean messageComplete(long contentLength) throws IOException;
public boolean messageComplete(long contentLength);

/**
* This is the method called by parser when a HTTP Header name and value is found
* @param header The HttpHeader value if there is a match
* @param name The String value of the header name
* @param value The String value of the header
* @return
* @throws IOException
*/
public boolean parsedHeader(HttpHeader header, String name, String value) throws IOException;
public boolean parsedHeader(HttpHeader header, String name, String value);

public boolean earlyEOF();

public void badMessage(String reason);
}

public interface RequestHandler extends HttpHandler
{
/**
* This is the method called by parser when the HTTP request line is parsed
*/
public abstract boolean startRequest(HttpMethod method, String methodString, String uri, HttpVersion version)
throws IOException;
public abstract boolean startRequest(HttpMethod method, String methodString, String uri, HttpVersion version);
}

public interface ResponseHandler extends HttpHandler
{
/**
* This is the method called by parser when the HTTP request line is parsed
*/
public abstract boolean startResponse(HttpVersion version, int status, String reason)
throws IOException;
public abstract boolean startResponse(HttpVersion version, int status, String reason);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class HttpGeneratorServerTest
private class Handler implements HttpParser.ResponseHandler
{
@Override
public boolean content(ByteBuffer ref) throws IOException
public boolean content(ByteBuffer ref)
{
if (_content==null)
_content="";
Expand All @@ -59,34 +59,41 @@ public boolean earlyEOF()
}

@Override
public boolean headerComplete(boolean hasBody,boolean persistent) throws IOException
public boolean headerComplete(boolean hasBody,boolean persistent)
{
_content= null;
return false;
}

@Override
public boolean messageComplete(long contentLength) throws IOException
public boolean messageComplete(long contentLength)
{
return true;
}

@Override
public boolean parsedHeader(HttpHeader header, String name, String value) throws IOException
public boolean parsedHeader(HttpHeader header, String name, String value)
{
_hdr.add(name);
_val.add(value);
return false;
}

@Override
public boolean startResponse(HttpVersion version, int status, String reason) throws IOException
public boolean startResponse(HttpVersion version, int status, String reason)
{
_version=version;
_status=status;
_reason=reason;
return false;
}

@Override
public void badMessage(String reason)
{
throw new IllegalStateException(reason);
}

}


Expand Down

0 comments on commit b9a2661

Please sign in to comment.