Skip to content
Permalink
Browse files

Code Cleanup

  • Loading branch information...
Ghost-Programmer committed Apr 6, 2019
1 parent d776e9c commit 703d24c3b12abccb2726b0f1c13c51d938c72f2d
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2018 MyMiller Consulting LLC.
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -18,76 +18,75 @@
/**
* @author jmiller Constants used by the HTTP Server
*/
public class HttpConstants
{
public class HttpConstants {
/**
*
*/
public static final int DELAY_TIME = 10;

/* HTTP Request Types */
public static final String DELETE_REQUEST = "DELETE";
public static final String GET_REQUEST = "GET";
public static final String HEAD_REQUEST = "HEAD";
public static final String POST_REQUEST = "POST";
public static final String PUT_REQUEST = "PUT";
public static final String DELETE_REQUEST = "DELETE";
public static final String GET_REQUEST = "GET";
public static final String HEAD_REQUEST = "HEAD";
public static final String POST_REQUEST = "POST";
public static final String PUT_REQUEST = "PUT";

/* HTTP Response Codes */

public final static int HTTP_CONTINUE_STATUS = 100;
public final static int HTTP_SWITCHING_PROTOCOLS_STATUS = 101;
public final static int HTTP_PROCESSING_STATUS = 102;
public final static int HTTP_CONTINUE_STATUS = 100;
public final static int HTTP_SWITCHING_PROTOCOLS_STATUS = 101;
public final static int HTTP_PROCESSING_STATUS = 102;

public static final int HTTP_OK_STATUS = 200;
public final static int HTTP_CREATED_STATUS = 201;
public final static int HTTP_ACCEPTED_STATUS = 202;
public final static int HTTP_NON_AUTHORITATIVE_INFORMATION_STATUS = 203;
public final static int HTTP_NO_CONTENT_STATUS = 204;
public final static int HTTP_RESET_CONTENT_STATUS = 205;
public final static int HTTP_PARTIAL_CONTENT_STATUS = 206;
public final static int HTTP_MULTI_STATUS_STATUS = 207;
public static final int HTTP_OK_STATUS = 200;
public final static int HTTP_CREATED_STATUS = 201;
public final static int HTTP_ACCEPTED_STATUS = 202;
public final static int HTTP_NON_AUTHORITATIVE_INFORMATION_STATUS = 203;
public final static int HTTP_NO_CONTENT_STATUS = 204;
public final static int HTTP_RESET_CONTENT_STATUS = 205;
public final static int HTTP_PARTIAL_CONTENT_STATUS = 206;
public final static int HTTP_MULTI_STATUS_STATUS = 207;

public final static int HTTP_MULTIPLE_CHOICES_STATUS = 300;
public final static int HTTP_MOVED_PERMANENTLY_STATUS = 301;
public final static int HTTP_MOVED_TEMPORARILY_STATUS = 302;
public final static int HTTP_FOUND_STATUS = 302;
public final static int HTTP_SEE_OTHER_STATUS = 303;
public final static int HTTP_NOT_MODIFIED_STATUS = 304;
public final static int HTTP_USE_PROXY_STATUS = 305;
public final static int HTTP_TEMPORARY_REDIRECT_STATUS = 307;
public final static int HTTP_MULTIPLE_CHOICES_STATUS = 300;
public final static int HTTP_MOVED_PERMANENTLY_STATUS = 301;
public final static int HTTP_MOVED_TEMPORARILY_STATUS = 302;
public final static int HTTP_FOUND_STATUS = 302;
public final static int HTTP_SEE_OTHER_STATUS = 303;
public final static int HTTP_NOT_MODIFIED_STATUS = 304;
public final static int HTTP_USE_PROXY_STATUS = 305;
public final static int HTTP_TEMPORARY_REDIRECT_STATUS = 307;

public final static int HTTP_BAD_REQUEST_STATUS = 400;
public final static int HTTP_UNAUTHORIZED_STATUS = 401;
public final static int HTTP_PAYMENT_REQUIRED_STATUS = 402;
public final static int HTTP_FORBIDDEN_STATUS = 403;
public final static int HTTP_NOT_FOUND_STATUS = 404;
public final static int HTTP_METHOD_NOT_ALLOWED_STATUS = 405;
public final static int HTTP_NOT_ACCEPTABLE_STATUS = 406;
public final static int HTTP_PROXY_AUTHENTICATION_REQUIRED_STATUS = 407;
public final static int HTTP_REQUEST_TIMEOUT_STATUS = 408;
public final static int HTTP_CONFLICT_STATUS = 409;
public final static int HTTP_GONE_STATUS = 410;
public final static int HTTP_LENGTH_REQUIRED_STATUS = 411;
public final static int HTTP_PRECONDITION_FAILED_STATUS = 412;
public final static int HTTP_REQUEST_ENTITY_TOO_LARGE_STATUS = 413;
public final static int HTTP_REQUEST_URI_TOO_LONG_STATUS = 414;
public final static int HTTP_UNSUPPORTED_MEDIA_TYPE_STATUS = 415;
public final static int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE_STATUS = 416;
public final static int HTTP_EXPECTATION_FAILED_STATUS = 417;
public final static int HTTP_UNPROCESSABLE_ENTITY_STATUS = 422;
public final static int HTTP_LOCKED_STATUS = 423;
public final static int HTTP_FAILED_DEPENDENCY_STATUS = 424;
public final static int HTTP_BAD_REQUEST_STATUS = 400;
public final static int HTTP_UNAUTHORIZED_STATUS = 401;
public final static int HTTP_PAYMENT_REQUIRED_STATUS = 402;
public final static int HTTP_FORBIDDEN_STATUS = 403;
public final static int HTTP_NOT_FOUND_STATUS = 404;
public final static int HTTP_METHOD_NOT_ALLOWED_STATUS = 405;
public final static int HTTP_NOT_ACCEPTABLE_STATUS = 406;
public final static int HTTP_PROXY_AUTHENTICATION_REQUIRED_STATUS = 407;
public final static int HTTP_REQUEST_TIMEOUT_STATUS = 408;
public final static int HTTP_CONFLICT_STATUS = 409;
public final static int HTTP_GONE_STATUS = 410;
public final static int HTTP_LENGTH_REQUIRED_STATUS = 411;
public final static int HTTP_PRECONDITION_FAILED_STATUS = 412;
public final static int HTTP_REQUEST_ENTITY_TOO_LARGE_STATUS = 413;
public final static int HTTP_REQUEST_URI_TOO_LONG_STATUS = 414;
public final static int HTTP_UNSUPPORTED_MEDIA_TYPE_STATUS = 415;
public final static int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE_STATUS = 416;
public final static int HTTP_EXPECTATION_FAILED_STATUS = 417;
public final static int HTTP_UNPROCESSABLE_ENTITY_STATUS = 422;
public final static int HTTP_LOCKED_STATUS = 423;
public final static int HTTP_FAILED_DEPENDENCY_STATUS = 424;

public final static int HTTP_INTERNAL_SERVER_ERROR_STATUS = 500;
public final static int HTTP_NOT_IMPLEMENTED_STATUS = 501;
public final static int HTTP_BAD_GATEWAY_STATUS = 502;
public final static int HTTP_SERVICE_UNAVAILABLE_STATUS = 503;
public final static int HTTP_GATEWAY_TIMEOUT_STATUS = 504;
public final static int HTTP_HTTP_VERSION_NOT_SUPPORTED_STATUS = 505;
public final static int HTTP_INSUFFICIENT_STORAGE_STATUS = 507;
public final static int HTTP_INTERNAL_SERVER_ERROR_STATUS = 500;
public final static int HTTP_NOT_IMPLEMENTED_STATUS = 501;
public final static int HTTP_BAD_GATEWAY_STATUS = 502;
public final static int HTTP_SERVICE_UNAVAILABLE_STATUS = 503;
public final static int HTTP_GATEWAY_TIMEOUT_STATUS = 504;
public final static int HTTP_HTTP_VERSION_NOT_SUPPORTED_STATUS = 505;
public final static int HTTP_INSUFFICIENT_STORAGE_STATUS = 507;

/* HTTP DELIMITERS */
public static final String AND_DELIMITER = "&";
public static final String EQUAL_DELIMITER = "=";
public static final String AND_DELIMITER = "&";
public static final String EQUAL_DELIMITER = "=";

}
@@ -39,15 +39,15 @@
/**
* Thread Pool size for handling requests
*/
private static int POOL_SIZE = 10;
private static int POOL_SIZE = 10;
/**
* Max Thread Pool size
*/
private static int MAX_POOL_SIZE = 25;
private static int MAX_POOL_SIZE = 25;
/**
* Thread Keep Alive Time
*/
private static int KEEP_ALIVE_TIME = 30;
private static int KEEP_ALIVE_TIME = 30;

/**
* Global Instance for the HTTP System
@@ -102,15 +102,15 @@ public static void setMaxPoolSize(int maxPoolSize) {
/**
* HTTP Server reference
*/
private HttpServer httpServer = null;
private HttpServer httpServer = null;
/**
* Queue to hold incoming requests
*/
private ArrayBlockingQueue<Runnable> queue = null;
private ArrayBlockingQueue<Runnable> queue = null;
/**
* Thread Pool Executor for the HTTP Serever
*/
private ThreadPoolExecutor threadPool = null;
private ThreadPoolExecutor threadPool = null;

/**
* Instantiates a new simple http server.
@@ -204,7 +204,7 @@ public void start() {

/**
* Start method accpeing handlers to use for this HTTP Server.
*
*
* @param handlers
*/
public void start(ContextHandlerInterface[] handlers) {
@@ -253,8 +253,8 @@ public void start(ContextHandlerInterface[] handlers) {
/**
* Force a stop of the server
*
* @param delay
* the maximum time in seconds to wait until exchanges have finished.
* @param delay the maximum time in seconds to wait until exchanges have
* finished.
*/
@Override
protected void stop(final int delay) {
@@ -41,8 +41,7 @@
/**
* Retrieve the Parameters Attribute from the Exchange
*
* @param exchange
* HTTPExchange containing the Parameters Attribute
* @param exchange HTTPExchange containing the Parameters Attribute
* @return Map&lt;String, Object&gt; containing the parameters
*/
@SuppressWarnings("unchecked")
@@ -53,12 +52,9 @@
/**
* Method to add a parameter to the HttpExchange.
*
* @param exchange
* HttpExchange to add the parameter to.
* @param key
* Key for the parameter
* @param value
* Value of the parameter
* @param exchange HttpExchange to add the parameter to.
* @param key Key for the parameter
* @param value Value of the parameter
*/
private void addParameter(final HttpExchange exchange, final String key, final String value) {
final Map<String, Object> parameters = ParameterFilter.getParametersFromExchange(exchange);
@@ -90,8 +86,7 @@ private void addParameter(final HttpExchange exchange, final String key, final S
/**
* Create a Parameters attribute on the HTTP Exchange.
*
* @param exchange
* HttpExchange to contain the attribute
* @param exchange HttpExchange to contain the attribute
* @return copy of the attribute.
*/
private Map<String, Object> createParametersOnExchange(final HttpExchange exchange) {
@@ -102,11 +97,9 @@ private void addParameter(final HttpExchange exchange, final String key, final S
/**
* Decode the Key Parameter from the URL
*
* @param param
* Array of parameters from the Key/Value Pair
* @param param Array of parameters from the Key/Value Pair
* @return Key
* @throws UnsupportedEncodingException
* Parameter 0 not in standard encoding.
* @throws UnsupportedEncodingException Parameter 0 not in standard encoding.
*/
private String decodeKey(final String[] param) throws UnsupportedEncodingException {
String key = null;
@@ -119,11 +112,9 @@ private String decodeKey(final String[] param) throws UnsupportedEncodingExcepti
/**
* Decode the Value Parameter from the URL
*
* @param param
* Array of parameters from the Key/Value Pair
* @param param Array of parameters from the Key/Value Pair
* @return Value
* @throws UnsupportedEncodingException
* Parameter 1 not in standard encoding.
* @throws UnsupportedEncodingException Parameter 1 not in standard encoding.
*/
private String decodeValue(final String[] param) throws UnsupportedEncodingException {
String value = null;
@@ -150,10 +141,8 @@ public void doFilter(final HttpExchange exchange, final Chain chain) throws IOEx
* parse the Get Parameters and add them to the HttpExchange as attribute
* parameters
*
* @param exchange
* HTTPExchange for this URI request
* @throws UnsupportedEncodingException
* Unable to decode
* @param exchange HTTPExchange for this URI request
* @throws UnsupportedEncodingException Unable to decode
*/
private void parseGetParameters(final HttpExchange exchange) throws UnsupportedEncodingException {
final URI requestedUri = exchange.getRequestURI();
@@ -165,10 +154,8 @@ private void parseGetParameters(final HttpExchange exchange) throws UnsupportedE
* Parse the Post Parameter and add them to the HttpExcahnge as attribute
* parameters
*
* @param exchange
* HTTPExchange for this URI request
* @throws IOException
* Unable to parse request body
* @param exchange HTTPExchange for this URI request
* @throws IOException Unable to parse request body
*/
private void parsePostParameters(final HttpExchange exchange) throws IOException {

@@ -183,12 +170,9 @@ private void parsePostParameters(final HttpExchange exchange) throws IOException
/**
* Splits out the parameters from the URI
*
* @param query
* URI Query for this request
* @param exchange
* HttpExchange containing the information on this request
* @throws UnsupportedEncodingException
* Unable to decode
* @param query URI Query for this request
* @param exchange HttpExchange containing the information on this request
* @throws UnsupportedEncodingException Unable to decode
*/
private void parseQuery(final String query, final HttpExchange exchange) throws UnsupportedEncodingException {
if (query != null) {
@@ -203,12 +187,9 @@ private void parseQuery(final String query, final HttpExchange exchange) throws
/**
* Takes a Key / Value Pair from the Query for parsing.
*
* @param exchange
* HttpExchange containing this query
* @param pair
* String for the Key/Value Pair
* @throws UnsupportedEncodingException
* Pair encoded incorrectly.
* @param exchange HttpExchange containing this query
* @param pair String for the Key/Value Pair
* @throws UnsupportedEncodingException Pair encoded incorrectly.
*/
private void parseQueryPair(final HttpExchange exchange, final String pair) throws UnsupportedEncodingException {
final String param[] = pair.split("[" + HttpConstants.EQUAL_DELIMITER + "]");
Oops, something went wrong.

0 comments on commit 703d24c

Please sign in to comment.
You can’t perform that action at this time.