# Com / Fujitsu / Futurity / Web

## Overview

The `com.fujitsu.futurity.web` package represents the web-layer entry point for the Fujitsu Futurity application. It provides the servlet-tier infrastructure that bridges HTTP requests from a web container to the application's internal services and business logic. This package is responsible for request handling, character encoding setup, and application lifecycle management -- essentially, the surface-area through which the Futurity system interacts with external clients over HTTP.

The web layer follows standard Java EE conventions: servlet filters intercept and preprocess incoming requests, while context listeners manage startup and teardown of application-scoped resources. Components are wired through a deployment descriptor (`web-full.xml`) rather than framework-specific annotations, keeping the layer framework-agnostic and container-managed.

At the time of this documentation, the web module is in a scaffolding state. The sub-modules that exist are structural placeholders wired into the deployment configuration but not yet populated with operational logic. This indicates a greenfield feature area where integration points have been identified but implementation is still pending.

## Sub-module Guide

The web module currently contains one sub-module:

### x33 -- X33 Feature Web Layer

**Package:** `com.fujitsu.futurity.web.x33`

The X33 sub-module establishes the first concrete web-layer touchpoints for a new feature area. It provides two container-managed components:

1. **`X33JVRequestEncodingSjisFilter`** -- A servlet filter positioned at the front of the X33 request pipeline. Its name indicates an intent to handle Shift-JIS (SJIS/CP932) character encoding for Japanese-language input. Currently a no-op, the filter delegates all requests to the downstream chain without transformation.

2. **`X33AppContextListener`** -- A planned application context listener intended to manage X33-specific initialization and cleanup during servlet container startup and shutdown. Currently a stub class with no methods implemented.

These two components operate at different stages of the application lifecycle but are conceptually unified as the X33 module's web-layer facade. The listener prepares resources at startup; the filter processes requests at runtime; the listener releases resources at shutdown.

### Relationship Between Sub-modules

Within the web package, X33 is the sole sub-module. Its two internal components (filter and listener) work in concert with the servlet container to establish a complete lifecycle envelope for the X33 feature:

- During **deployment**, `web-full.xml` registers both components, telling the container to instantiate them.
- During **startup**, the `X33AppContextListener` (once implemented) will initialize X33-specific services, caches, or configuration.
- During **runtime**, every incoming HTTP request matching the filter's URL pattern passes through `X33JVRequestEncodingSjisFilter`, which (once implemented) will set character encoding before delegating downstream.
- During **shutdown**, the listener's `contextDestroyed` method will clean up X33 resources.

The filter and listener are independent container-managed components with no direct communication between them. Their coordination happens through shared application-scoped state in the `ServletContext` -- a standard Java EE pattern for cross-component communication.

```mermaid
flowchart TD
    WC["Web Container"] -->|startup| L["X33AppContextListener
.contextInitialized()"]
    L -->|prepares| RES["X33 resources /
services in ServletContext"]
    WC -->|HTTP request| FM["web-full.xml
filter mapping"]
    FM -->|dispatches| F["X33JVRequestEncodingSjisFilter
.doFilter()"]
    F -->|passes through| FC["FilterChain /
downstream servlet"]
    WC -->|shutdown| LS["X33AppContextListener
.contextDestroyed()"]
    LS -->|releases| RES
```

## Key Patterns and Architecture

### Container-Managed Component Pattern

All components in this web package follow the standard Java EE servlet lifecycle pattern. Classes are instantiated and managed entirely by the servlet container -- no application framework (e.g., Spring) mediates their creation or lifecycle. The container:

1. Instantiates the filter and listener once per deployment.
2. Invokes `init()` on the filter and `contextInitialized()` on the listener during startup.
3. Dispatches each matching HTTP request through `doFilter()`.
4. Invokes `destroy()` on the filter and `contextDestroyed()` on the listener during shutdown.

This pattern is lightweight and framework-agnostic but demands careful thread safety discipline, since the container reuses the same instance across all requests.

### No-op / Stub Architecture

Both classes in the X33 sub-module are currently no-ops. They exist as structural placeholders in the deployment descriptor, indicating that the X33 feature was designed with its web-layer touchpoints identified upfront, even though implementation is pending. This is a reasonable greenfield approach: define integration points, wire them into the container, then fill in the logic.

### Filter Chain Positioning

The X33 filter's position in `web-full.xml` determines when it executes relative to other filters. Since the filter's name implies encoding setup (Shift-JIS for Japanese input), it must be positioned early in the chain -- before any filter or servlet that reads request parameters, form data, or JSON bodies. Encoding must be set before the body is consumed, making filter ordering a critical configuration concern.

```mermaid
flowchart LR
    WC["Web Container"] -->|reads| WM["web-full.xml"]
    WM -->|registers| SF["X33JVRequestEncodingSjisFilter"]
    WM -->|registers| CL["X33AppContextListener"]
    SF -->|implements| FI["javax.servlet.Filter"]
    CL -->|will implement| SL["javax.servlet.ServletContextListener"]
    SF -->|passes through| CH["downstream
filter chain"]
    CL -->|contextInitialized| IC["app startup hooks"]
    CL -->|contextDestroyed| DC["app shutdown hooks"]
```

## Dependencies and Integration

### External Dependencies

| Dependency | Purpose |
|------------|---------|
| `javax.servlet.Filter` | Implemented by `X33JVRequestEncodingSjisFilter` for request processing |
| `javax.servlet.ServletContextListener` (expected) | To be implemented by `X33AppContextListener` for lifecycle management |
| `web-full.xml` | Deployment descriptor registering both components in the servlet container |

### Internal Dependencies

No inbound callers have been detected -- no other Java packages in the codebase import or reference classes from `com.fujitsu.futurity.web` or its sub-packages. This confirms that the web module is either newly introduced or operating in isolation from other parts of the system. The filter is invoked purely through XML-based servlet container configuration rather than Java-level references.

### Integration with the Broader System

When fully implemented, the web module will integrate with the rest of the Futurity application through standard servlet mechanisms:

- **Filter chain:** The filter delegates to the downstream chain, eventually reaching X33's servlets, controllers, or other web components (not yet present).
- **ServletContext:** The listener will have access to the application's `ServletContext`, the standard mechanism for sharing application-scoped attributes and resources across components.
- **Deployment descriptor:** Both components are wired through `web-full.xml`, the canonical configuration point for servlet container components.

## Notes for Developers

1. **Both classes are stubs.** Neither the filter nor the listener contains operational logic. This is not a bug -- it is a scaffolded module awaiting implementation.

2. **Implementing the filter:** When adding encoding logic, cast the `ServletRequest` to `HttpServletRequest`, call `setCharacterEncoding("SJIS")` (or `"CP932"`) before `chain.doFilter()`, and consider making the encoding configurable via a servlet init-param or context-param rather than hardcoding it.

3. **Implementing the listener:** Add `javax.servlet.ServletContextListener` as an implemented interface and provide `contextInitialized` and `contextDestroyed` methods. Coordinate with the X33 team on initialization ordering and resource lifecycle to avoid conflicts with other application components.

4. **Filter ordering is critical.** If the filter is used for encoding, it must appear early in the `<filter-mapping>` order in `web-full.xml`, before any component that reads request parameters.

5. **Thread safety.** As singleton container-managed components, both classes are instantiated once and handle all requests/lifecycle events on shared instances. Any future state must be read-only after initialization, or protected by synchronization.

6. **No other module depends on this package.** Changes to these classes have limited blast radius within the existing codebase, but any future X33 web components that reference the listener's initialization output will need to be considered.

7. **Encoding choice matters for Japanese locales.** If this filter is intended to handle Japanese input, verify whether the application requires Shift-JIS (`"SJIS"` / `"CP932"`) or has migrated to UTF-8. Modern applications typically use UTF-8, but legacy Japanese enterprise systems often require Shift-JIS for form data compatibility.

8. **This is a greenfield module.** The absence of indexed source files and classes in the module index suggests the source files are either not yet committed or are very small stubs. Developers working in this area should expect to build functionality from the scaffolding upward.
