---

# (DD07) Business Logic — Example.syncGet() [12 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.http.Example` |
| Layer | Utility |
| Module | `http` (Package: `io.github.biezhi.java11.http`) |

## 1. Role

### Example.syncGet()

The `syncGet()` method performs a **synchronous HTTP GET request** to a remote server specified by the given URI. It is a convenience utility method that encapsulates the full lifecycle of an HTTP GET call — from client creation, request building, network transmission, response receipt, to output — using the Java 11 `java.net.http.HttpClient` API.

This method implements the **Builder pattern** for constructing `HttpRequest` objects via `HttpRequest.newBuilder()`, and follows the **Facade pattern** by wrapping the multi-step HTTP client operations into a single call. It serves as a **demo entry point** or reusable utility within the `java11-http` project, which demonstrates Java 11 standard library features (JEP 321 — HTTP Client).

The method blocks the calling thread until the full HTTP response is received. Upon completion, it prints both the HTTP status code and the response body to standard output (`System.out`). There are no conditional branches — the control flow is strictly linear from start to finish. The `throws Exception` signature indicates that checked exceptions from the HTTP client (e.g., `IOException`, `InterruptedException`) propagate to the caller, who is responsible for handling network-level errors.

The Japanese comment `// 同期呼び出し GET` translates to "Synchronous call GET", confirming this method is intended as a synchronous counterpart to the async `asyncGet()` method in the same class.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["syncGet(uri)"])
    START --> A["Create HttpClient: HttpClient.newHttpClient()"]
    A --> B["Build HttpRequest: HttpRequest.newBuilder().uri(URI.create(uri)).build()"]
    B --> C["Send request: client.send(request, HttpResponse.BodyHandlers.ofString())"]
    C --> D["Print status code: System.out.println(response.statusCode())"]
    D --> E["Print response body: System.out.println(response.body())"]
    E --> END_NODE(["Return / Next"])
```

**Processing Summary:**

| Step | Description |
|------|-------------|
| 1 | Create a new `HttpClient` instance using the factory method `HttpClient.newHttpClient()`. This creates a default client with default configuration (no proxy, plain HTTP/HTTPS). |
| 2 | Construct an HTTP GET request using the Builder pattern. The `URI.create(uri)` converts the string URI into a `java.net.URI` object. The `build()` finalizes the immutable `HttpRequest`. |
| 3 | Send the request synchronously via `client.send()`, specifying `HttpResponse.BodyHandlers.ofString()` which buffers the entire response body into a `String`. This call blocks until the complete response is received. |
| 4 | Extract and print the HTTP response status code (e.g., 200, 404, 500). |
| 5 | Extract and print the response body content as a string. |

No constants are referenced in this method. No conditional branches exist. The flow is purely sequential.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `uri` | `String` | The uniform resource identifier of the target HTTP endpoint. Specifies the full URL to send the GET request to (e.g., `"https://api.example.com/data"`). The string is parsed into a `java.net.URI` by `URI.create()`; an invalid URI will throw `IllegalArgumentException`. |

**External State / Instance Fields:**

This method is `static` and does not read any instance fields. It creates all objects locally within the method body.

## 4. CRUD Operations / Called Services

This method does not perform any CRUD operations against databases or enterprise services. It interacts solely with external HTTP endpoints via the `java.net.http.HttpClient` API.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R (HTTP GET) | `client.send()` | N/A | N/A (remote HTTP endpoint) | Sends a synchronous HTTP GET request to the remote URI and reads the response body as a string. This is a network-level read operation, not a database query. |

**Note:** No SC Codes, CBS procedures, or database entities are involved. The `client.send()` method is a Java standard library API (`java.net.http.HttpClient.send()`), not an enterprise service component.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | N/A | — | — |

**Analysis:** No callers were found in the codebase. This is a static utility/demo method in the `Example` class, intended to be called directly by demonstration code or test entry points (e.g., `main()` methods in other files). No screens, batches, or CBS procedures reference this method.

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC] `(HttpClient creation) (L29)`

> Creates a new default HTTP client instance. This is a factory call that configures the client with default settings (follow redirects, HTTP/2 support, no custom proxy).

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpClient client = HttpClient.newHttpClient();` // Creates default HTTP client for synchronous requests |

**Block 2** — [EXEC] `[HttpRequest Builder pattern] (L30–32)`

> Constructs an immutable HTTP GET request using the builder pattern. The `uri(URI.create(uri))` call parses the input string into a URI object and sets it as the request target.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpRequest request = HttpRequest.newBuilder()` // Start building request |
| 2 | SET | `.uri(URI.create(uri))` // Parse string to URI and set request target |
| 3 | SET | `.build()` // Finalize and return immutable HttpRequest |

**Block 3** — [EXEC] `[Synchronous HTTP transmission] (L34–35)`

> Sends the request synchronously and blocks the calling thread until the full HTTP response is received. The response body is buffered into a String via `BodyHandlers.ofString()`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());` // Block until response received |

**Block 4** — [EXEC] `[Output status code] (L37)`

> Extracts and prints the HTTP status code from the response. Common codes include 200 (OK), 404 (Not Found), 500 (Internal Server Error).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `System.out.println(response.statusCode());` // Print HTTP status code (e.g., 200, 404) |

**Block 5** — [EXEC] `[Output response body] (L38)`

> Extracts and prints the full response body content as a string. The body content depends on the remote server's response (JSON, HTML, plain text, etc.).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `System.out.println(response.body());` // Print response body content as string |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `uri` | Field | Uniform Resource Identifier — the full URL of the HTTP endpoint to request (e.g., `https://api.example.com/resource`) |
| `HttpClient` | Type | Java 11 HTTP Client — a class from `java.net.http` package that handles HTTP/HTTPS requests synchronously and asynchronously |
| `HttpRequest` | Type | Java 11 HTTP Request — an immutable request object built using the Builder pattern (`HttpRequest.newBuilder()`) |
| `HttpResponse` | Type | Java 11 HTTP Response — the response object containing status code, headers, and body from an HTTP request |
| `BodyHandlers.ofString()` | Type | Java 11 body handler — instructs the HTTP client to buffer the response body into a `String` |
| `syncGet` | Method | Synchronous GET — performs a blocking HTTP GET; the caller thread is blocked until the full response is received |
| `asyncGet` | Method | Asynchronous GET — the counterpart method in the same class that performs non-blocking HTTP GET using `CompletableFuture` |
| Java 11 HTTP Client | Technology | Introduced in JEP 321 (Java 11), provides a modern, fluent, and extensible API for HTTP/1.1 and HTTP/2 clients |
