---

# (DD05) Business Logic — Example.proxy() [14 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.proxy()

This method demonstrates how the application performs an outbound HTTP request through a configured proxy server. It constructs an `HttpClient` with a fixed proxy endpoint at `127.0.0.1:1080`, creates a GET request to `https://www.google.com`, sends the request, and writes both the HTTP status code and response body to the console. In business terms, it is a network connectivity example used to validate proxy-based access to external web resources rather than to transform or persist domain data.

The method follows a simple routing and delegation pattern: the proxy configuration is applied at client construction time, then the client delegates the actual transport work to the Java HTTP runtime. There are no conditional branches, loops, or alternate service types in this method. Its role in the larger system is instructional and diagnostic, serving as a reusable example for how to reach an external site through a local proxy endpoint.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["proxy()"])
    BUILD_CLIENT["Create HttpClient builder"]
    SET_PROXY["Configure proxy 127.0.0.1:1080"]
    BUILD_REQUEST["Create GET request for https://www.google.com"]
    SEND_REQUEST["Send request with HttpClient"]
    PRINT_STATUS["Print response status code"]
    PRINT_BODY["Print response body"]
    END_NODE(["Return"])

    START --> BUILD_CLIENT
    BUILD_CLIENT --> SET_PROXY
    SET_PROXY --> BUILD_REQUEST
    BUILD_REQUEST --> SEND_REQUEST
    SEND_REQUEST --> PRINT_STATUS
    PRINT_STATUS --> PRINT_BODY
    PRINT_BODY --> END_NODE
```

**CRITICAL — Constant Resolution:**
This method does not reference named constants. The proxy host, proxy port, and target URI are provided as inline literal values: `127.0.0.1`, `1080`, and `https://www.google.com`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

This method has no parameters. It depends only on local literals and the `HttpClient`/`HttpRequest` objects it creates internally. It reads no instance fields and does not consume external mutable state from the `Example` class.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Example.proxy` | Example | - | Calls `proxy` in `Example` |

Analyze all method calls within this method and classify each as a CRUD operation.
Use the pre-computed evidence above. If SC Code or Entity/DB is missing, try to infer from:
- The **SC Code** (Service Component code, e.g., `EKK0361A010SC`, `EKK1081D010CBS`) — look at the class name of the called method or its containing class.
- The **Entity/DB tables** — search for table name constants (often `KK_T_*` pattern), SQL references, or entity names in the called method's source code.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `HttpClient.newBuilder()` | JDK HttpClient | - | Creates an HTTP client builder for outbound communication |
| U | `proxy(ProxySelector.of(new InetSocketAddress("127.0.0.1", 1080)))` | JDK HttpClient | - | Applies a proxy route for all requests sent by the client |
| C | `build()` | JDK HttpClient | - | Builds the configured HTTP client instance |
| R | `HttpRequest.newBuilder()` | JDK HttpRequest | - | Creates a request builder for an outbound GET call |
| U | `uri(new URI("https://www.google.com"))` | JDK HttpRequest | - | Sets the target endpoint for the outgoing request |
| U | `GET()` | JDK HttpRequest | - | Sets the HTTP method to GET |
| C | `build()` | JDK HttpRequest | - | Builds the immutable request object |
| R | `client.send(request, HttpResponse.BodyHandlers.ofString())` | JDK HttpClient | - | Sends the request through the proxy and retrieves the response body as text |
| R | `response.statusCode()` | JDK HttpResponse | - | Reads the returned HTTP status code |
| R | `response.body()` | JDK HttpResponse | - | Reads the returned response payload |
| R | `System.out.println(...)` | JDK Console | - | Outputs the status code and body for inspection |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `Example.proxy` | `Example.proxy` | `client.send(request, HttpResponse.BodyHandlers.ofString()) [R] -` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENTIAL] `(method entry)` (L117)

> Builds an HTTP client configured to use a local proxy, then prepares and sends a GET request to an external site.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpClient client = HttpClient.newBuilder()` |
| 2 | EXEC | `.proxy(ProxySelector.of(new InetSocketAddress("127.0.0.1", 1080)))` // configure proxy endpoint |
| 3 | CALL | `.build()` // finalize configured `HttpClient` |

**Block 2** — [SEQUENTIAL] `(request construction)` (L121)

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpRequest request = HttpRequest.newBuilder()` |
| 2 | EXEC | `.uri(new URI("https://www.google.com"))` // set outbound target URL |
| 3 | EXEC | `.GET()` // set HTTP verb to GET |
| 4 | CALL | `.build()` // finalize immutable `HttpRequest` |

**Block 3** — [SEQUENTIAL] `(request execution and console output)` (L126)

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString())` |
| 2 | EXEC | `System.out.println(response.statusCode())` // print status code |
| 3 | EXEC | `System.out.println(response.body())` // print response body |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `HttpClient` | Technical term | Java HTTP client used to send outbound network requests |
| `HttpRequest` | Technical term | Immutable HTTP request definition for the outbound call |
| `HttpResponse` | Technical term | Container for the remote server response |
| `ProxySelector` | Technical term | Java proxy routing component that directs traffic through a proxy server |
| `InetSocketAddress` | Technical term | Network address object identifying proxy host and port |
| `127.0.0.1` | Technical term | Localhost address representing the machine running the code |
| `1080` | Technical term | Proxy listening port used by the example |
| `https://www.google.com` | Business term | Target external web endpoint used to verify proxy-based access |
| GET | Acronym | HTTP GET method used to retrieve data without submitting payload |
| body | Field/Property | Response payload returned by the remote endpoint |
| statusCode | Field/Property | Numeric HTTP result code indicating request outcome |
| proxy | Technical term | Network routing configuration that sends requests through an intermediary server |
| outbound request | Business term | Client-initiated call to an external service or website |
| console output | Technical term | Standard output stream used to display diagnostic results |
