if( elements.length < 3 ) {
LOG.warning("Request line has " + elements.length
+ " elements, expected 3. Value is "
+ lexerCurretToken.Value.toString() );
throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
}
Http.Method method = Http.Method.valueOf(elements[0]);
context.request.setMethod(method);
URI uri = new URI(elements[1]);
context.request.setRequestURI(uri);
LOG.finer("New request on " + uri.getPath() + " of type " + method.name());
Http.Version version = Http.Version.valueOf(
elements[2].replace('/', '_').replace('.', '_'));
context.request.setVersion( version);
} else {
// it does not start with a potential request line, not valid http request
LOG.warning("Unable to understand request it is of type " + lexerCurretToken.Type.name()
+ " and value starts with " + lexerCurretToken.Value.toString());
throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
}
}
// we've got the request line now we need to find the EOL so we can move to the headers
if( httpLexer.hasNext() ) {
lexerCurretToken = httpLexer.next();
if( HttpLexer.TokenType.EOL.equals( lexerCurretToken.Type) ) {
context.requestHandler.setCurrentStateHandler(new ProcessingHeadersStateHandler());
context.requestHandler.getCurrentStateHandler().handleState(context);
} else {
LOG.warning("Unable to understand request it does not end properly, expecting EOL found "
+ lexerCurretToken.Value.toString());
throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad request");
}
return;
}
inputBuffer.clear(); // make buffer empty
count = context.inputChannel.read( inputBuffer);
}
} catch (IOException ex) {
LOG.log(Level.SEVERE, "Unable to process request input", ex);
} catch (URISyntaxException e) {
LOG.log(Level.SEVERE, "Unable to process request input", e);
throw new ServerRuntimeException( HttpResponse.SC_BAD_REQUEST, "Bad Request");
}
}