---

# (DD09) Business Logic — Example.getURIs() [12 LOC]

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

## 1. Role

### Example.getURIs()

This method executes **parallel HTTP requests** against a list of URI endpoints using Java 11's built-in `HttpClient` API. It accepts a list of `java.net.URI` objects and converts each into an asynchronous HTTP request, dispatching them all concurrently and waiting for every response to complete before returning. The method embodies the **CompletableFuture-based parallel dispatch pattern** — it batches multiple independent network operations into a single synchronous barrier, allowing the calling thread to remain unblocked while all requests proceed in parallel. It serves as a **demonstration utility** within the Java 11 HTTP client samples, illustrating how to leverage the modern `java.net.http` package (introduced in Java 11) for concurrent HTTP operations. The method does not branch — it uniformly processes every URI in the list through the same fire-and-wait flow. Its role in the larger system is that of a **sample/demo method** within the `java11-http-example` project, showcasing idiomatic Java 11 asynchronous HTTP usage.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getURIs(uris)"])

    START --> A1["Create HttpClient via newHttpClient()"]
    A1 --> A2["Stream over uris list"]
    A2 --> A3["Map each URI to HttpRequest.Builder via newBuilder()"]
    A3 --> A4["Map each Builder to HttpRequest via build()"]
    A4 --> A5["Collect to List<HttpRequest>"]
    A5 --> A6["Stream requests for async dispatch"]
    A6 --> A7["Send each request asynchronously via sendAsync(request, HttpResponse.BodyHandlers.ofString())"]
    A7 --> A8["Convert to CompletableFuture<?>[] array"]
    A8 --> A9["Wait for all requests via CompletableFuture.allOf().join()"]
    A9 --> END(["Return (void)"])

    START --> A1
    A1 --> A2
    A2 --> A3
    A3 --> A4
    A4 --> A5
    A5 --> A6
    A6 --> A7
    A7 --> A8
    A8 --> A9
    A9 --> END
```

**CRITICAL — Constant Resolution:** No constants are used in this method. The method contains no conditional branches, switch statements, or variable comparisons.

**Processing Summary:**
1. **HttpClient Creation**: A new `HttpClient` instance is created via `HttpClient.newHttpClient()`. This uses the default configuration (no proxy, no authentication, HTTP/2 enabled).
2. **URI-to-Request Mapping**: The input `uris` list is streamed. Each `URI` is mapped to an `HttpRequest.Builder` via `HttpRequest.newBuilder(uri)`, then built into a complete `HttpRequest` via `build()`. The default HTTP method for these requests is **GET** (since no `.method()` call is made).
3. **Collection**: All built `HttpRequest` objects are collected into a `List<HttpRequest>` via `Collectors.toList()`.
4. **Parallel Async Dispatch**: Each `HttpRequest` is sent asynchronously via `client.sendAsync(request, HttpResponse.BodyHandlers.ofString())`, which returns a `CompletableFuture<HttpResponse<String>>`.
5. **Barrier Wait**: `CompletableFuture.allOf(...)` aggregates all futures into a single composite future. `.join()` blocks the calling thread until all responses have completed (success or failure).
6. **Return**: The method returns void after all requests complete.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `uris` | `List<URI>` | A list of Uniform Resource Identifiers representing the target HTTP endpoints to request. Each URI points to a distinct web resource that the method will fetch in parallel using asynchronous HTTP/1.1 or HTTP/2 GET requests. |

**External State / Instance Fields:**
- None. This method creates its own `HttpClient` instance locally and does not read any instance fields or static state.

## 4. CRUD Operations / Called Services

This method performs **no CRUD operations**. It does not interact with any database, persistent storage, or service component (SC/CBS).

All method calls within `getURIs()` are **HTTP client operations** — not data-access operations:

| # | Method Called | Type | Description |
|---|--------------|------|-------------|
| 1 | `HttpClient.newHttpClient()` | Client Creation | Creates a new default HTTP client instance for outbound requests |
| 2 | `HttpRequest.newBuilder(uri)` | Request Builder | Creates an HTTP GET request builder for the given URI |
| 3 | `HttpRequest.Builder.build()` | Request Builder | Finalizes the builder into an immutable `HttpRequest` |
| 4 | `client.sendAsync(request, BodyHandlers.ofString())` | Async HTTP Call | Sends the request asynchronously and buffers the response body as a String |
| 5 | `CompletableFuture.allOf(...)` | Future Aggregation | Combines all request futures into a single composite future |
| 6 | `CompletableFuture.join()` | Barrier Wait | Blocks until all asynchronous requests complete |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Utility (self-contained sample) | `Example.getURIs` | N/A — no CRUD, no SC calls |

**Note:** The method `getURIs` is **not called by any other class** in the codebase. It is a standalone sample method within the `java11-http-example` project, intended to demonstrate parallel HTTP request execution with Java 11's `HttpClient`. The only reference to this method is its own declaration in `Example.java`.

## 6. Per-Branch Detail Blocks

### Block 1 — EXEC (HttpClient Creation) (L176)

> Creates a new HTTP client with default configuration for making outbound HTTP requests.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `HttpClient client = HttpClient.newHttpClient();` // Creates a default HttpClient for HTTP/2 and HTTP/1.1 requests |

### Block 2 — FOR (Stream Mapping) (L177-L180)

> Converts each URI in the input list into a complete `HttpRequest` object via a two-step stream pipeline: first mapping to `HttpRequest.Builder`, then building the final request. The default HTTP method is GET.

| # | Type | Code |
|---|------|------|
| 1 | SET | `List<HttpRequest> requests = uris.stream()...collect(toList());` // Collects all built requests into a list |
| 2 | FOR | `uris.stream()` // Iterates over each URI in the input list |
| 3 | EXEC | `.map(HttpRequest::newBuilder)` // Maps each URI to a HttpRequest.Builder instance |
| 4 | EXEC | `.map(HttpRequest.Builder::build)` // Builds each Builder into an immutable HttpRequest |
| 5 | EXEC | `.collect(toList())` // Collects all HttpRequest objects into a List |

### Block 3 — FOR (Async Parallel Dispatch) (L182-L184)

> Sends all requests asynchronously, waits for every response to complete, then returns. No response bodies are read or processed — the method only ensures all requests are dispatched and completed.

| # | Type | Code |
|---|------|------|
| 1 | FOR | `requests.stream()` // Streams over the list of HttpRequest objects |
| 2 | EXEC | `.map(request -> client.sendAsync(request, HttpResponse.BodyHandlers.ofString()))` // Sends each request asynchronously; response body is buffered as String but not consumed |
| 3 | EXEC | `.toArray(CompletableFuture<?>[]::new)` // Converts the stream of CompletableFutures to an array |
| 4 | EXEC | `CompletableFuture.allOf(...)` // Aggregates all futures into a single composite future |
| 5 | EXEC | `.join()` // Blocks the calling thread until all futures complete |
| 6 | RETURN | `(void return)` // Method exits after all requests finish |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `uris` | Parameter | A list of URIs (Uniform Resource Identifiers) — the target endpoints to which HTTP GET requests will be sent in parallel |
| `HttpClient` | Class | Java 11's built-in HTTP client (`java.net.http.HttpClient`) supporting HTTP/1.1 and HTTP/2 with both synchronous and asynchronous request modes |
| `HttpRequest` | Class | Represents an immutable HTTP request with a target URI, method (GET by default), headers, and optional body |
| `HttpRequest.Builder` | Class | Mutable builder for constructing `HttpRequest` instances, allowing configuration of method, headers, body, and other options before building |
| `CompletableFuture` | Class | Java's API for asynchronous programming; represents a future result that may be completed by another thread |
| `sendAsync` | Method | Sends an HTTP request asynchronously; returns a `CompletableFuture<HttpResponse<T>>` that completes when the response is received |
| `BodyHandlers.ofString()` | Method | A response body handler that reads the entire response body into a `String` (not consumed in this method) |
| `allOf()` | Method | Static method that returns a `CompletableFuture` that completes when all given futures complete |
| `join()` | Method | Blocks the calling thread until the future completes; rethrows any exception as an `UncheckedExecutionException` if a request failed |
| parallel requests | Concept | Multiple HTTP requests dispatched simultaneously over separate connections, leveraging non-blocking I/O for throughput |

---