Add HTTP server example using Netty and PerlOnJava#659
Merged
Conversation
This example demonstrates how to create a web server where HTTP request handlers are written in Perl, with Netty handling the networking layer. Features: - Complete working HTTP server with Netty - Request handlers written in Perl (handler.pl) - Multiple endpoints: home, API, forms, time, env, echo - Thread-safe implementation using single event loop - Comprehensive documentation with architecture diagrams - Makefile with automatic dependency download - Automated test script - Proper separation between Java (HTTP) and Perl (business logic) Technical implementation: - Uses RuntimeHash.createHashRef() for proper hash reference passing - Demonstrates calling Perl subroutines from Java - Shows how to bridge between Java objects and Perl data structures - Documents thread safety considerations for PerlOnJava Files: - HttpServerExample.java: Netty server that calls Perl handlers - handler.pl: Perl request handlers with routing logic - Makefile: Build system with deps, compile, run, test targets - README.md: Comprehensive documentation and debugging tips - test.sh: Automated endpoint testing - .gitignore: Excludes compiled files and downloaded libraries Usage: cd examples/http_server make run Then visit http://localhost:8080 in a browser or: curl http://localhost:8080/ curl http://localhost:8080/api/users make test Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a complete HTTP server example that demonstrates how to implement web pages in Perl using Netty/Jetty with PerlOnJava.
What's New
A new example at
examples/http_server/showing:RuntimeHash.createHashRef()Files Added
HttpServerExample.java- Netty-based HTTP serverhandler.pl- Perl request handlers with routingMakefile- Complete build system (auto-downloads Netty JARs)README.md- Full documentation with debugging tipstest.sh- Automated endpoint tests.gitignore- Ignores compiled/downloaded filesQuick Start
cd examples/http_server make runThen visit http://localhost:8080 or test with:
curl http://localhost:8080/ curl http://localhost:8080/api/users make testTechnical Highlights
Thread Safety
PerlOnJava is currently not thread-safe (global state in static fields). This example uses a single-threaded event loop to safely handle concurrent requests via async I/O. This approach is:
Future: When multiplicity is implemented (see
dev/design/concurrency.md), a runtime pool can be used for true parallel request handling.Proper Perl API Usage
Uses
--disassembleto understand internal APIs:This revealed that hash references should be created using:
This matches how PerlOnJava compiles
{ key => value }syntax internally.Testing
All endpoints tested and working:
Documentation
The README includes:
--disassembleRelated Issues
Addresses the question: "Is there a way to implement web pages in Perl using netty/jetty?"
Answer: Yes! This example shows exactly how to do it.
Checklist
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com