Skip to main content
Coming soon. The org.fdtech.prism:prism-servlet artifact is not yet published to Maven Central. This page describes the planned API.

Overview

The prism-servlet package provides a generic Servlet Filter for payment-protecting Java web applications using the x402 protocol. It works with any servlet-based framework (Tomcat, Jetty, Spring Boot, Jakarta EE, etc.).

Framework Agnostic

Works with any Servlet 3.0+ container

Response Buffering

Captures output before settlement validation

Standard Filter

Standard javax.servlet.Filter interface

Installation


The canonical SDK config is identifyToken (PRISM_IDENTIFY_TOKEN env var) — formerly apiKey / PRISM_API_KEY. SDKs accept the legacy names as fallback during the migration window; new code should use the canonical names.

Quick Start

Configuration via web.xml

Servlet Implementation


Configuration

PrismConfig

Programmatic Configuration


Route Configuration Format

In web.xml

Routes are configured as colon-separated values, one per line:
Format: path:price:description
  • path: Exact path or wildcard (/api/*)
  • price: USD amount (0.01 = 0.01USD,or0.01 USD, or `0.001` string format)
  • description: Human-readable description

Programmatic Configuration


Accessing Payment Information

Payment info is stored as request attributes:

Safe Access Helper


Settlement Validation

The Java Servlet filter uses HttpServletResponseWrapper to capture servlet output before settlement validation:
Key Points:
  • Servlet writes to wrapper, not real response
  • Output is buffered in memory
  • After settlement check, either send buffered data or error
  • Works with all response types (JSON, HTML, binary, etc.)
See Stablecoin Settlement for details.

Error Handling

Payment Errors

When payment is missing or invalid:

Custom Error Handling


Spring Boot Integration

Configuration Class

Spring Boot Controller


Testing

JUnit 5 Tests


Mock Servlet Testing


Production Deployment

Environment Configuration

Configuration Class


Logging & Monitoring


Examples

AI Agent API


REST API with JAX-RS


Troubleshooting

Check filter mapping in web.xml:
Verify filter order: Prism filter should execute BEFORE authentication filters.
Debug with logging:
Check: Route matches filter URL pattern, payment header present and valid.
Common causes: 1. Insufficient balance 2. Invalid signature 3. Nonce reuse 4. Network timeout Check logs: Enable debug mode in PrismConfig.
If you see encoding problems:
  • Make sure to set Content-Type before writing
  • Use getWriter() for text, getOutputStream() for binary
  • Don’t mix getWriter() and getOutputStream()
Last modified on May 15, 2026