{"id":1906,"date":"2025-11-24T10:00:02","date_gmt":"2025-11-24T15:00:02","guid":{"rendered":"http:\/\/www.mymiller.name\/wordpress\/?p=1906"},"modified":"2025-11-24T10:00:02","modified_gmt":"2025-11-24T15:00:02","slug":"http-server-command-handler-in-a-jar","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/java_http\/http-server-command-handler-in-a-jar\/","title":{"rendered":"HTTP Server Command Handler in a Jar"},"content":{"rendered":"\n<p>Today, I&#8217;m going to share with you a command handler for the <a href=\"http:\/\/www.mymiller.name\/wordpress\/?p=1901\">HTTP Server<\/a> I presented previously. &nbsp;This is a handler to extend the abilities of that HTTP Server in a Jar to provide you the ability to stop, restart and get status of it, if needed.<\/p>\n\n\n\n<p><span style=\"color: #ff0000;\"><strong>WARNING<\/strong>: This is NOT a robust, secure HTTP Server, this is a simple HTTP Server, for when you need one, without the hassle of installing one. &nbsp;If you need robust, and secure, then go install Apache HTTP, Apache Tomcat or something else!<\/span><\/p>\n\n\n\n<p>This provides a rest API to perform a few tasks quickly and easily. &nbsp;Here are the commands implemented<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Path<\/td><td>Type<\/td><td>Description<\/td><\/tr><tr><td>\/status<\/td><td>GET<\/td><td>Gets the current status of the HTTP Server, providing back a text based response.<\/td><\/tr><tr><td>\/stop<\/td><td>POST<\/td><td>Instructs the HTTP Server to shutdown, once all processing is complete.<\/td><\/tr><tr><td>\/restart<\/td><td>POST<\/td><td>Instructs the HTTP Server to restart once all processing is complete.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>These are pretty commands and you easily see how to add additional commands to these as needed. &nbsp; Stay tuned for my next on this series of posts!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package name.mymiller.httpserver.handlers;\n\nimport java.io.IOException;\nimport java.util.List;\nimport java.util.Map;\n\nimport com.sun.net.httpserver.Filter;\nimport com.sun.net.httpserver.HttpExchange;\n\nimport name.mymiller.extensions.log.LogManager;\nimport name.mymiller.httpserver.HttpConstants;\nimport name.mymiller.httpserver.HttpSystem;\n\n\/**\n * @author jmiller\n *\n *\/\n@SuppressWarnings(\"restriction\")\n@HttpHandlerAnnotation(context = \"\/cmd\")\npublic class CmdHandler extends AbstractContextHandler\n{\n\t\/**\n\t * Error Text for unknown command\n\t *\/\n\tprivate static final String UNKOWN_COMMAND = \"Unkown Command\";\n\n\t@Override\n\tpublic void doGet(final HttpExchange exchange, final String pathInfo, final Map&lt;String, Object> parameters)\n\t\t\tthrows IOException\n\t{\n\t\tswitch (pathInfo) {\n\t\t\tcase \"\/status\":\n\t\t\t\tfinal String responseBody = \"Listen Port: \" + HttpSystem.getInstance().getAddress().getPort()\n\t\t\t\t\t\t+ \"\\nListen Address: \" + HttpSystem.getInstance().getAddress().getHostString()\n\t\t\t\t\t\t+ \"\\nActive Thread Count: \" + HttpSystem.getInstance().getActiveCount()\n\t\t\t\t\t\t+ \"\\nLargest Thread Pool Size: \" + HttpSystem.getInstance().getLargestPoolSize()\n\t\t\t\t\t\t+ \"\\nMaximum Thread Pool Size: \" + HttpSystem.getInstance().getMaximumPoolSize()\n\t\t\t\t\t\t+ \"\\nCurrent Task Count: \" + HttpSystem.getInstance().getTaskCount()\n\t\t\t\t\t\t+ \"\\nCompleted Task Count: \" + HttpSystem.getInstance().getCompletedTaskCount() + \"\\n\";\n\n\t\t\t\tLogManager.getLogger(this.getClass()).info(\"Response: \" + responseBody);\n\n\t\t\t\tthis.sendResponse(exchange, HttpConstants.HTTP_OK_STATUS, responseBody);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tLogManager.getLogger(this.getClass()).severe(\"Unknown GET Command: \" + pathInfo);\n\n\t\t\t\tthis.sendResponse(exchange, HttpConstants.HTTP_NOT_ACCEPTABLE_STATUS, CmdHandler.UNKOWN_COMMAND);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t@Override\n\tpublic void doPost(final HttpExchange exchange, final String pathInfo, final Map&lt;String, Object> parameters)\n\t\t\tthrows IOException\n\t{\n\t\tswitch (pathInfo) {\n\t\t\tcase \"\/stop\":\n\t\t\t\tfinal String stopResponse = \"Stopping Server on Port:\"\n\t\t\t\t\t\t+ HttpSystem.getInstance().getAddress().getPort();\n\t\t\t\tLogManager.getLogger(this.getClass()).info(\"Response: \" + stopResponse);\n\t\t\t\t\/\/ Set the response header status and length\n\n\t\t\t\tthis.sendResponse(exchange, HttpConstants.HTTP_OK_STATUS, stopResponse);\n\n\t\t\t\tHttpSystem.getInstance().shutdown(HttpConstants.DELAY_TIME);\n\t\t\t\tbreak;\n\t\t\tcase \"\/restart\":\n\t\t\t\tfinal String restartResponse = \"Restarting Server on Port:\"\n\t\t\t\t\t\t+ HttpSystem.getInstance().getAddress().getPort();\n\t\t\t\tLogManager.getLogger(this.getClass()).info(\"Response: \" + restartResponse);\n\n\t\t\t\tthis.sendResponse(exchange, HttpConstants.HTTP_OK_STATUS, restartResponse);\n\n\t\t\t\tHttpSystem.getInstance().setRestart(true);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tLogManager.getLogger(this.getClass()).severe(\"Unknown POST Command: \" + pathInfo);\n\n\t\t\t\tthis.sendResponse(exchange, HttpConstants.HTTP_NOT_ACCEPTABLE_STATUS, CmdHandler.UNKOWN_COMMAND);\n\t\t\t\tbreak;\n\t\t}\n\n\t}\n\n\t@Override\n\tpublic List&lt;Filter> getFilters()\n\t{\n\t\treturn null;\n\t}\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today, I&#8217;m going to share with you a command handler for the HTTP Server I presented previously. &nbsp;This is a handler to extend the abilities of that HTTP Server in a Jar to provide you the ability to stop, restart and get status of it, if needed. WARNING: This is NOT a robust, secure HTTP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1902,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[459],"tags":[69],"series":[226],"class_list":["post-1906","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java_http","tag-java-2","series-http-server-in-a-jar"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1","jetpack-related-posts":[{"id":1901,"url":"https:\/\/www.mymiller.name\/wordpress\/java_http\/http-server-jar\/","url_meta":{"origin":1906,"position":0},"title":"HTTP Server in your Jar","author":"Jeffery Miller","date":"November 20, 2025","format":false,"excerpt":"I recently had the need to be able to access a couple of files from a number of computers and didn't want to setup network shares and things. \u00a0These were a simple text files, that I was logging information into. However I was going to be moving around a number\u2026","rel":"","context":"In &quot;Java HTTP&quot;","block_context":{"text":"Java HTTP","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_http\/"},"img":{"alt_text":"filters","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3747,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_config\/secure-your-secrets-encrypting-values-with-spring-cloud-config\/","url_meta":{"origin":1906,"position":1},"title":"Secure Your Secrets: Encrypting Values with Spring Cloud Config","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In the world of microservices, Spring Cloud Config provides a centralized way to manage externalized configurations for your applications. But what about sensitive data like database passwords or API keys? That\u2019s where encryption comes in. This blog post will guide you through the process of encrypting your sensitive values using\u2026","rel":"","context":"In &quot;Spring Config&quot;","block_context":{"text":"Spring Config","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_config\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/security-5726869_1280-jpg.avif 3x"},"classes":[]},{"id":1911,"url":"https:\/\/www.mymiller.name\/wordpress\/java_http\/http-server-contexthandler-jar\/","url_meta":{"origin":1906,"position":2},"title":"HTTP Server ContextHandler in a Jar","author":"Jeffery Miller","date":"November 21, 2025","format":false,"excerpt":"Last time I showed you how to create a basic HTTP Server that you can put into a JAR easily. \u00a0Today I'm going to show you how to extend that to include a ContextHandler and AbstractContextHandler to make it easier to create Handlers for your HTTP Server. \u00a0If you remember\u2026","rel":"","context":"In &quot;Java HTTP&quot;","block_context":{"text":"Java HTTP","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_http\/"},"img":{"alt_text":"filters","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/http-875180_640.jpg?fit=640%2C452&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3671,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/spring-cloud-data-flow-orchestrating-machine-learning-pipelines\/","url_meta":{"origin":1906,"position":3},"title":"Spring Cloud Data Flow: Orchestrating Machine Learning Pipelines","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In the dynamic world of machine learning, the journey from raw data to a deployed model involves a series of intricate steps. Spring Cloud Data Flow (SCDF) emerges as a powerful ally, offering a comprehensive platform to streamline and manage these complex data pipelines. In this guide, we\u2019ll delve into\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/ai-generated-8411275_1280-jpg.avif 3x"},"classes":[]},{"id":3928,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_databases\/%f0%9f%92%a1-implementing-cqrs-with-spring-boot-and-kafka\/","url_meta":{"origin":1906,"position":4},"title":"\ud83d\udca1 Implementing CQRS with Spring Boot and Kafka","author":"Jeffery Miller","date":"November 21, 2025","format":false,"excerpt":"As a software architect, I constantly look for patterns that enhance the scalability and maintainability of microservices. The Command Query Responsibility Segregation (CQRS) pattern is a powerful tool for this, especially when coupled with event-driven architecture (EDA) using Apache Kafka. CQRS separates the application into two distinct models: one for\u2026","rel":"","context":"In &quot;Spring Databases&quot;","block_context":{"text":"Spring Databases","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_databases\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/data-2899902_1280.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/data-2899902_1280.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/data-2899902_1280.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/data-2899902_1280.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/data-2899902_1280.avif 3x"},"classes":[]},{"id":3475,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_sockets\/spring-boot-with-rsocket\/","url_meta":{"origin":1906,"position":5},"title":"Spring Boot with RSocket","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"RSocket, a powerful messaging protocol, is a perfect fit for building reactive microservices in a Spring Boot environment. This article will guide you through integrating RSocket with Spring Boot using both Maven and Gradle build systems. We'll explore adding the necessary dependencies, configuration options, and basic usage examples. Getting Started:\u2026","rel":"","context":"In &quot;Spring Sockets&quot;","block_context":{"text":"Spring Sockets","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_sockets\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/03\/technology-3374916_640.jpg?fit=640%2C261&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/03\/technology-3374916_640.jpg?fit=640%2C261&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/03\/technology-3374916_640.jpg?fit=640%2C261&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/1906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=1906"}],"version-history":[{"count":6,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/1906\/revisions"}],"predecessor-version":[{"id":2914,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/1906\/revisions\/2914"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/1902"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=1906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=1906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=1906"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=1906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}