Share E-Book

Java Web Internals Unlock the secrets of Java web servers, frameworks, and application architecture (Francisco Isidro Massetto)(Z-Library)

Author Francisco Isidro Massetto

framework
Language English

Key benefits • Build a multithreaded HTTP server and application container using Java sockets • Understand and replicate the internal mechanics of Tomcat and Jakarta EE, and Spring features • Develop a modular Java framework with annotation-based routing and dependency injection Ever wondered how web servers like Tomcat process requests, or what really happens behind frameworks such as Spring? This book takes you beneath the surface of Java web development to uncover the why behind the tools you use every day. Rather than focusing solely on coding recipes, this book emphasizes the underlying concepts and design principles that govern how web servers and frameworks operate. Starting with low-level socket programming, you’ll build a multithreaded HTTP server from the ground up and extend it into a lightweight application server capable of handling dynamic content. Along the way, you’ll master HTTP request parsing, response generation, servlet-like request handling, and Java reflection and annotations for metaprogramming. As you progress, you’ll evolve this infrastructure into your own Java framework with embedded Tomcat, annotation-driven routing, object serialization with Jackson, and basic dependency injection modeled on Jakarta CDI. By the end of this journey, you’ll understand the principles behind them, enabling you to reason about system design, troubleshoot complex issues, and apply these concepts across frameworks and programming languages. Who is this book for? Java developers, computer science students, and educators seeking a deep, hands-on understanding of web server internals and application framework design. Prior knowledge of Java and basic networking concepts is recommended.

Format PDF
Size 8.9 MB
7
Views
0
Downloads
0.00
Total Donations
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
Java Web Internals Unlock the secrets of Java web servers, frameworks, and application architecture Francisco Isidro Massetto
Page 3
Java Web Internals Copyright © 2026 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Portfolio Director: Kunal Chaudhari Relationship Lead: Rithika Shetty Project Manager: Ankit Anilkumar Maroli Content Engineer: Deepayan Bhattacharjee Technical Editor: Irfa Ansari Indexer: Hemangini Bari Production Designer: Aparna Bhagat Growth Lead: Vinishka Kalra First published: April 2026 Production reference: 1140426 Published by Packt Publishing Ltd. Grosvenor House 11 St Paul's Square Birmingham B3 1RB, UK. ISBN 978-1-83588-148-4 www.packtpub.com
Page 4
To my loved wife Luana and my children Nicolas, Luca, and Enrico Daddy loves you all Thanks for being by my side during this journey
Page 5
Foreword You're debugging a performance issue in production. Your AI assistant suggests three different solutions. Each one looks reasonable. Now… Which one do you choose? AI doesn't know your system's architecture constraints. It can't see the memory footprint implications. It has no context about your team's deployment pipeline or the technical debt accumulating in your legacy modules. You do. This is the new reality of software development. AI will generate more code than ever. Yet, developers are the ones that carry the responsibility for the critical decisions: system architecture, performance trade-offs, scalability patterns, and technical direction. Now, you can only make those decisions when you understand how things work under the hood. That's exactly why I'm so impressed by Francisco Isidro Massetto's Java Web Internals. That reminds me of the first time I met Isidro… I'm driving through São Paulo. Sitting beside me, in the passenger seat, is one of the most influential leaders of the Java ecosystem. Patrick Curran, chair of the Java Community Process (JCP), is visiting Brazil. Over two hours in traffic, we are on our way to meet a university professor known for his passionate teaching style. Patrick is excited about this visit. As part of a joint effort from the JCP and SouJava (one of the world's largest Java User Groups), we are connecting with educators who share our vision for Java development.
Page 6
The drive feels endless. We go through neighborhoods I'd never seen before, following GPS directions that lead us further into the city's maze. Patrick is restless – I'm secretly hoping this won't be a disaster. Our destination: a classroom where this professor was building something special. Professor Isidro, as he was widely known, is an online sensation. Developers everywhere talk about his energetic approach to teaching fundamental concepts. His reputation for making complex topics accessible grows rapidly. Still, nothing prepared us for meeting Professor Isidro in person. Isidro wasn't your typical academic. Energy radiated from him. His excitement was infectious. Students hung on every word as he explained the importance of Java. The normally serious Patrick is laughing and enjoying the visit. He is completely captivated. I'm impressed. The event exceeded every expectation. That was many years ago… Patrick has since passed away and is deeply missed in our community. Yet the impact of that encounter continues to this day. Isidro became one of my closest friends. His online influence has grown tremendously. He's now a Java Champion and successful entrepreneur. He has built and deployed real systems with his students. Thousands of developers rely on his insights for their daily work. This book you are holding now, brings back all that energy I witnessed that day in São Paulo. Refined through years of teaching and real-world application. Starting with web fundamentals, you'll first understand the basic concepts of client server applications and then build your own web server. Then you'll implement a mini application server (think of it as your personal Tomcat). Finally, you'll create your own web framework (let's say, your own mini-Spring). By the end, you'll understand the architectural decisions and trade-offs behind every major server and framework in the market. And more – you'll become a powerful developer. When AI suggests a caching strategy, you'll know the memory implications. When it recommends a threading model, you'll understand the concurrency trade-offs. When it proposes a framework pattern, you'll recognize the performance characteristics. This deep knowledge isn't just helpful in an AI-driven world. It's essential.
Page 7
Isidro brings the same passion and energy I witnessed firsthand, distilled into practical knowledge you can apply immediately. The future belongs to developers who understand the power of AI for sure. Yet, the best developers of the future have a deep appreciation for the fundamentals that make great software possible, and also deeply enjoy the development craft. This book, built on of Professor Isidro's beliefs of the importance of fundamentals and on having fun developing software, gives you both. Bruno Souza Java Champion Founder of SouJava Mentor at Code4.Life
Page 8
Contributors About the author Francisco Isidro Massetto, a.k.a. Professor Isidro, is Java Champion with a PhD in Computer Engineering. He works as a professor, lecturer, and entrepreneur, bringing in-depth technical knowledge to computer science students through both in-person classes and his YouTube channel. With over 25 years of teaching and industry experience, he has always sought to create links between academia and the job market. He is never content with just using the technology itself and always tries to study in depth how technologies are built – to learn more and understand how to use them better. I would like to express my heartfelt gratitude to my beloved family. My wife and children, in addition to supporting me in writing this book, were extremely understanding when I was working during times when we should have been together.
Page 9
About the reviewer Harish Padmanaban is a Senior IEEE Member and Chair of the IEEE Houston Section with over 13 years of experience in Java & Python application development, web servers, distributed systems, and enterprise architecture. His expertise spans servlet containers, application frameworks, request lifecycle management, and scalable backend design. He has authored multiple technical books and holds four global patents in software architecture and automation-driven systems. Harish actively contributes to the global engineering community as a reviewer for IEEE and peer-reviewed journals, combining strong theoretical foundations with hands-on system design experience. "Understanding the internals is what transforms a developer into an architect." — Harish Padmanaban I would like to sincerely thank the Packt team for entrusting me with the technical review of this book. It was rewarding to engage deeply with the architectural concepts and implementation details, and I appreciate the openness to incorporating review feedback to strengthen technical precision and clarity. My thanks also go to my family for their continued encouragement and support throughout the review process.
Page 10
Table of Contents Preface xv Free benefits with your book .............................................................................. xix Chapter 1: Networks, Protocols, and Packets 1 Technical requirements ........................................................................................ 2 Exploring the TCP/IP stack with an example ......................................................... 2 The need for application layer protocols ................................................................ 7 Defining a very simple application protocol ........................................................... 8 Understanding sockets ....................................................................................... 10 Setting up projects with an Eclipse IDE • 15 Setting up a project manually • 16 Step 1: Generate a JAR file for your protocol • 17 Step 2: Compiling and Running your Server project • 17 Step 3: Compiling and Running your Client project • 17 Summary ............................................................................................................ 19 Chapter 2: Workings of a Web Server – A Case Study 21 Understanding an HTTP request ......................................................................... 23 Understanding an HTTP response ....................................................................... 27 See in action ........................................................................................................ 31 A quick reflection on performance ...................................................................... 32 Summary ........................................................................................................... 33 Chapter 3: Implementing a Simple Web Server 35 Technical requirements ...................................................................................... 36 Starting our project ............................................................................................ 36 Handling HTTP requests ..................................................................................... 40
Page 11
Handling HTTP responses ................................................................................... 42 Performance issues ............................................................................................. 50 Summary ........................................................................................................... 52 Chapter 4: Web Servers vs Application Servers 55 SimpleWebContainer architecture ...................................................................... 57 Handling business rules via HTTP ....................................................................... 59 Implementation issues ....................................................................................... 62 Summary ........................................................................................................... 63 Chapter 5: Deep Dive into Simple Web Container Implementation 65 Creating WebContainerLib classes ...................................................................... 67 Exploring classes on SimpleWebContainer .......................................................... 70 A small example ................................................................................................. 75 Testing • 80 Further implementation issues ........................................................................... 81 Summary ........................................................................................................... 81 Chapter 6: Simple Web Container Improvements and Expansions 83 Simple application server review ........................................................................ 84 Improvements and expansions ........................................................................... 84 Support for multithreading, or even virtual threads • 84 Session maintenance • 85 Support for multiple applications or contexts • 87 Monitoring and logging • 88 Tools for administration and deployment • 89 Potential uses of simple application server .......................................................... 89 Educational purposes in educational environments • 90 Embedded server • 90 Use in test environments • 91 Low-performance devices • 92 Summary ........................................................................................................... 92 Table of Contents x
Page 12
Subscribe to Deep Engineering ........................................................................... 94 Chapter 7: Why Create a Web Framework 95 Why use Tomcat instead of SAS ........................................................................... 95 Understanding servlet: The Tomcat foundation • 96 Web frameworks: Abstracting infrastructure with Spring and Quarkus • 97 Understanding internally how a request works in the Spring framework ............. 99 Request Interception and Handler Mapping • 99 Request Dispatching and Handler Adapters • 100 Invoking Controller Logic and Generating the Response • 101 Lifecycle and extensibility • 102 Building our own web framework ...................................................................... 103 Use of embedded Tomcat • 103 Handling GET and POST Methods • 103 Object Serialization and Deserialization • 104 Dependency injection (DI) based on the Jakarta specification • 105 Summary .......................................................................................................... 105 Chapter 8: Web Frameworks – The Necessary Abstraction for Professional Development 107 So, what is a framework? .................................................................................. 108 Web frameworks • 108 What do Spring and Quarkus abstract from the developer? ................................ 109 The role of the Spring Framework • 109 And Quarkus? • 110 Why create our own web framework? ................................................................ 110 More than writing code: understanding the invisible • 110 A journey guided by three fundamental questions • 111 But first: why leave SAS aside and use Tomcat • 111 The SimpleWebFramework architecture: a new look at the request-response cycle ... 112 Browser to HTTP request • 112 xi Table of Contents
Page 13
Embedded Tomcat: Robust infrastructure, under our control • 112 DispatcherServlet: The heart of the framework • 113 The metadata extraction module: Understanding the application from annotations . 113 @SimpleController: Identifying controllers • 114 @SimpleGetRequest and @SimplePostRequest: Mapping the service methods • 115 @SimpleBody: Interpreting the request body • 115 @SimpleService: Organizing reusable components • 116 @SimpleInject: The magic of dependency injection • 116 Summary .......................................................................................................... 117 Chapter 9: Detailing the SimpleWebFramework Implementation 119 The main class: SimpleWebFrameworkApplication ........................................... 120 The embedded tomcat dependency • 121 Framework initialization • 121 Explaining the code step by step • 122 The framework initialization cycle • 124 Benefits of embedded tomcat • 124 The ClassExplorer class: locating the Application's controllers ........................... 124 The role of ClassExplorer in initialization • 125 Class scanning with the Depth-First search (DFS) algorithm • 125 Using reflection to identify annotations • 127 Directory structure and search behavior • 127 Registering the found controllers • 128 The importance of automated discovery • 128 The SimpleDispatcherServlet: dynamic routing and On-Demand instantiation ... 129 The relationship between ClassExplorer and DispatcherServlet • 129 ControllersMap and RequestControllerData structure • 130 Internals of the SimpleDispatcherServlet • 131 The role of data structures in routing • 134 On-Demand creation of controller instances • 134 Handling HTTP GET and POST methods • 135 Table of Contents xii
Page 14
Reading the request body with @SimpleBody • 135 Consolidated flow • 136 Summary .......................................................................................................... 136 Chapter 10: The Emergence of Dependency Injection and Its Application in SimpleWebFramework 139 Brief history: the challenge of dependencies in enterprise applications ............... 139 The birth of enterprise JavaBeans (EJB) • 140 The types of enterprise JavaBeans • 141 Session beans • 141 Message-Driven beans (MDBs) • 141 Entity beans • 141 The role of the EJB container and XML configuration • 142 From XML configuration to annotation: the maturation of IoC • 143 Dependency injection: the power of specification ............................................... 144 Bean types and structural decoupling • 144 Implementations and compatibility: spring and quarkus • 146 Spring framework • 147 Quarkus • 147 A common base, multiple expressions • 148 Implementing dependency injection in SimpleWebFramework .......................... 149 CDI as a conceptual base and inspiration • 149 The @SimpleService annotation: defining managed beans • 150 The role of ClassExplorer in service discovery • 151 The @SimpleInjected annotation: the injection point • 152 The DependencyInjectionMap and the instance lifecycle • 153 Instantiation strategies • 154 Instantiation on demand • 154 Instantiation at startup • 154 Integration with the DispatcherServlet lifecycle • 155 The role of decoupling and modular architecture • 156 Summary .......................................................................................................... 157 xiii Table of Contents
Page 15
Chapter 11: Creating the First Application with SimpleWebFramework 159 Creating the MyWebTestApplication project ..................................................... 160 The main class: MyWebTestApplication.java ...................................................... 161 Controllers and route mapping in SimpleWebFramework ................................... 163 Services and dependency injection in SimpleWebFramework ............................ 168 The service interface: defining the contract • 168 The service implementation: linking the business logic • 169 On-demand injection • 170 Understanding the didactic role of DI in SimpleWebFramework • 172 Field injection vs. constructor injection • 173 Paths for SimpleWebFramework expansion ....................................................... 173 Chapter 12: Unlock Your Exclusive Benefits 177 Unlock this Book's Free Benefits in 3 Easy Steps .................................................. 178 Other Books You May Enjoy 182 Subscribe to Deep Engineering .......................................................................... 185 Index 187 Table of Contents xiv
Page 16
Preface This book is born with a clear, yet challenging, proposition: to guide you through a complete journey of building a web framework from its most basic fundamentals. In a scenario where modern frameworks abstract almost all the complexity of web development, many developers end up using powerful tools without understanding what really happens behind the layers of abstraction. Here, we will take the opposite approach. Instead of starting at a high level, we will build this knowledge from the ground up, understanding each piece that makes up the web ecosystem. Throughout my career as a university professor, I have always dedicated myself to teaching the fundamentals of Computer Science to my students. This has sparked in me, and in my students, a fascination with understanding technology beyond the surface. And this subject was no different. Web development is currently much easier thanks to the frameworks available, especially considering the Java ecosystem. However, web frameworks are nothing more than abstractions of something that has always existed in web specifications since their earliest versions. Today, when we use a framework like Spring or Quakus, for example, much of what we use is the result of abstraction layers that, in the past, we did almost manually. Throughout this journey, you will be guided from the most fundamental concepts of network communication, through the use of sockets, to the implementation of a functional web server. This approach not only strengthens technical understanding but also allows you to develop a critical view of how distributed applications actually work. After all, every web application depends on clear rules of communication between client and server, based on well-defined protocols, as discussed throughout the book. With this foundation established, we will move on to building an application server, significantly expanding our capabilities. Unlike a traditional web server, which only delivers static content, an application server is capable of executing business logic and generating dynamic responses based on received requests. This transition represents one of the most important moments in the book, as it's where we move from simply serving files to actually processing information and building complete applications. To make this possible, a deep understanding of how the HTTP protocol works will be essential. Throughout the chapters, you will see how requests are structured, how responses are assembled, and how every detail – from headers to the message body – influences the
Page 17
application's behavior. More than just using HTTP, you will implement it in practice, understanding its nuances and limitations, which provides a much more solid mastery of web development. All this construction will be done using Java, exploring everything from its most basic concepts to more advanced features. We will start with fundamental language structures and essential APIs, such as sockets and I/O, gradually evolving to the use of reflection, annotations, and architectural patterns that allow the creation of more sophisticated solutions. This progression was carefully planned to ensure that each new concept builds upon the previous one, creating a consistent and natural learning curve. By the end of the journey, you will not only have built a functional web framework, but you will also have developed a deep understanding of how real frameworks operate internally. This means that when using tools like Spring, Quarkus, or any other modern framework, you will be able to see beyond the abstraction, understanding their design decisions, their strengths, and their limitations. This book, therefore, is not just about writing code. It's about training a developer with a systemic vision, capable of understanding, building, and evolving solutions with autonomy and confidence. If you want to move beyond the superficial level and truly master the inner workings of web development, this journey is for you – and I hope you enjoy it! Who this book is for This book is for computer science students and Java Web developers at all levels (junior to senior) who want to know more about Web fundamentals and explore framework internals. The main purpose of this book is to uncover some aspects of how a framework can abstract many communication issues and HTTP protocol manipulation, giving autonomy to developers to focus on business rules implementation. What this book covers Chapter 1, Networks, Protocols and Packets, introduces the fundamental concepts of network-based communication with a simple client/server calculator implementation. Chapter 2, Workings of a Web Server – A Case Study, concerns the main aspects of web server internals, including how it handles the HTTP protocol, decodes requests, and generates responses in different media types. Chapter 3, Implementing a Simple Web Server, shows, step by step, how to implement the full web server delivering static content. Preface xvi
Page 18
Chapter 4, Web Servers vs Application Servers, discusses the main differences between static and dynamic content generation, and which aspects to evolve in the web server to create an application server. Chapter 5, Deep dive into Simple Web Container implementation, explores not only the Application Server implementation, but also a minimal library to create an application that uses this Application Server as communication infrastructure. Chapter 6, Simple Web Container improvements and expansions, creates a roadmap for expansions and improvements of our Web Container, including multithreading, logs, and so on. Chapter 7, Why Create a Web Framework, discusses the motivation to develop a framework, which abstractions we can achieve with a framework, and how complex it is. Chapter 8, Web Frameworks – The Necessary Abstraction for Professional Development, explains the whole framework architecture and needed components. Chapter 9, Detailing the SimpleWebFramework Implementation, explores implementation details and project decisions to make a simple but functional web framework. Chapter 10, The Emergence of Dependency Injection and its Application in SimpleWebFramework, discovers how a specification can be applied to our framework. Chapter 11, Creating the First Application with SimpleWebFramework, explains how to create your web application using the developed web framework with all dependencies and make it functional. To get the most out of this book You need knowledge of the Java programming language, object-oriented programming, and some network concepts. This book is for educational purposes, but it doesn't mean it's restricted to an academic scope. You can use this knowledge in your professional projects. Download the example code files The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/ Java-Web-Internals. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out! Download the color images We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781835881484. • • xvii Preface
Page 19
Conventions used There are a number of text conventions used throughout this book. CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: " Let us explore the definition of our Request class in this code snippet:" A block of code is set as follows: Class Request.java public record Request(Double op1, Double op2, String oper) { } Any command-line input or output is written as follows: javac -d bin *.java Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: " To answer these questions, we will initially consider a "classical model" in the literature: the client-server communication model." Get in touch Feedback from our readers is always welcome. General feedback: If you have questions about any aspect of this book or have any general feedback, please email us at customercare@packt.com and mention the book's title in the subject of your message. Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit http://www.packt.com/submit-errata, click Submit Errata, and fill in the form. Warnings or important notes appear like this. Note Tips and tricks appear like this. Tip Preface xviii
Page 20
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material. If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http:// authors.packt.com/. Free benefits with your book This book comes with free benefits to support your learning. Activate them now for instant access (see the "How to Unlock" section for instructions). Here's a quick overview of what you can instantly unlock with your purchase: xix Preface
The above is a preview of the first 20 pages. Register to read the complete e-book.

Support Author

0.00
Total Amount (¥)
0
Donation Count
Please enter an amount Minimum ¥1

You will be redirected to Alipay to complete payment, then return here.

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List