Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Java Web Internals
  • Table Of Contents Toc
Java Web Internals

Java Web Internals

By : Francisco Isidro Massetto
5 (1)
close
close
Java Web Internals

Java Web Internals

5 (1)
By: Francisco Isidro Massetto

Overview of this book

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. *Email sign-up and proof of purchase required
Table of Contents (15 chapters)
close
close
14
Index

Defining a very simple application protocol

Let's assume we are going to implement a remote calculator, initially, with the following six arithmetic operations:

  • Sum
  • Subtraction
  • Multiplication
  • Division
  • Power
  • Square root

In this case, to simplify things, let's define the structure of our request. Of the six operations, five expect two operands, and only one (square root) expects a single operand. Let's define a standard structure:

  • Request:
  • operand1: number
  • operand2: number
  • operator: text

An example of a sum operation can be viewed in the following code snippet. In defining the protocol that will be used, we will transmit serialized Java objects. This notation is a textual notation (in this case, the JSON format); however, the communication will be done by sending and receiving serialized Java objects.

Operation 2 + 3 → Request:
{
    "operand1": 2,
    "operand2": 3,
    "operator": "+"
}

Now, as an answer, you might be thinking that just returning a number with the result of the operation is enough, right? However, let's consider some restrictions:

  • The division cannot have the second operand with the value of 0
  • The square root cannot have the first operand with a negative value
  • We will not accept any operator other than those defined (+, -, *, /, ^, and sqrt)

Therefore, if we send data that violates some of these restrictions, our protocol needs to signal that the operation cannot be performed. Also, if we send a symbol other than the supported operators, we have to signal that the operation is not recognized.

So, our answer is as follows:

Response:

  • status: text
  • value: number

We will now see a table where our protocol handles valid and invalid requests.

Operation

Request

Response

Detail

2 + 3

{
  "op1": 2,
  "op2": 3,
  "oper": "+"
}
{
  "status":"Ok",
  "value": 5
}

Successful operation.

3 / 0

{
  "op1": 3,
  "op2": 0,
  "oper": "/"
}
{
  "status":"Invalid",
  "value": null
}

Operation failed. One of the operators violates the division constraint.

5 ** 8

{
  "op1": 5,
  "op2": 8,
  "oper": "**"
}
{
  "status":"Unsupported",
  "value": null
}

Operation failed. Informed that operation is not supported.

Once we understand this concept, we can translate it into a programming language. But first, we need to understand how to make this communication possible through sockets!

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Java Web Internals
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon