GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing axis.apache.org — Apache Axis2 OpenAPI REST Services User's Guide – Apache Axis2 Apache Axis2 OpenAPI REST Services User's GuideWhat is OpenAPI? OpenAPI (formerly known as Swagger) is an industry-standard specification for describing REST APIs. It provides a machine-readable format that precisely defines your API endpoints, request/response schemas, authentication methods, and error handling. Think of it as a contract that documents exactly how your REST API behaves, enabling automatic client code generation, interactive testing, and comprehensive documentation that stays in sync with your actual implementation. Why use OpenAPI? For developers, OpenAPI eliminates the tedious manual work of writing and maintaining API documentation, reduces integration errors through precise specifications, and enables powerful tooling ecosystems. Your frontend developers get auto-generated TypeScript clients, your QA teams get interactive testing interfaces via Swagger UI, and your DevOps teams can generate monitoring configurations automatically. Most importantly, OpenAPI specifications serve as the single source of truth for your API, preventing the documentation drift that plagues many projects. This guide demonstrates how to create OpenAPI 3.0.1 documented REST services with Apache Axis2, providing a drop-in replacement solution for existing REST backends. It includes comprehensive examples for financial services, data management systems, and enterprise applications with OpenAPI specification support and interactive Swagger UI documentation! The guide shows how to build REST services that can seamlessly replace existing backends (Spring Boot, Express.js, etc.) while maintaining API compatibility for frontend applications such as Excel Add-ins, React apps, and TypeScript clients. Introduced in Axis2 2.0.1: OpenAPI 3.0.1 integration with automatic specification generation from deployed services, Swagger UI support, and an MCP tool catalog. More documentation about Axis2 REST support can be found in the Pure JSON Support documentation and JSON User Guide. For modern enterprise features including Bearer authentication, advanced security schemes, and comprehensive configuration options, see the OpenAPI Advanced User Guide. IntroductionThis user guide is written based on the Axis2 Standard Binary Distribution. The Standard Binary Distribution can be directly downloaded or built using the Source Distribution. If you choose the latter, then the Installation Guide will instruct you on how to build Axis2 Standard Binary Distribution using the source. The source code for this guide is a small sample application demonstrating an OpenAPI-documented REST authentication service. The data, calculation and Excel examples later in this guide are illustrative patterns for your own services; they are not part of the sample. Please note that Axis2 is an open-source effort. If you feel the code could use some new features or fixes, please get involved and lend us a hand! The Axis developer community welcomes your participation. Let us know what you think! Send your feedback to "[email protected]". (Subscription details are available on the Axis2 site.) Kindly prefix the subject of the mail with [Axis2]. OpenAPI Integration FeaturesSince 2.0.1, Axis2 provides OpenAPI 3.0.1 integration designed for enterprise REST services and drop-in backend replacement scenarios. The OpenAPI module generates the specification from the services deployed in Axis2, and lets you adjust the generated document programmatically. Key OpenAPI Features
Customizing the Generated SpecificationThe OpenAPI module always generates the specification from the deployed services; it does not serve a hand-written schema file in place of the generated one. To change the generated document (add servers, security schemes, descriptions or extra schemas), implement Drop-in Backend ReplacementThe Axis2 OpenAPI integration is specifically designed for backend replacement scenarios:
Getting StartedThis user guide explains how to write and deploy OpenAPI-documented REST services using Axis2, and how to replace existing backends while maintaining frontend compatibility. All the sample code mentioned in this guide is located in the "modules/samples/swagger-server" directory of Axis2 standard binary distribution. The sample provides an OpenAPI-documented authentication service, together with a reference OpenAPI contract for a larger financial API ( Testing the Sample: The swagger-server sample includes comprehensive unit tests for all service components and models. To run the tests, navigate to the sample directory and execute Creating OpenAPI REST ServicesThe guide demonstrates how to create secure, OpenAPI-documented REST services using real-world patterns commonly found in financial services and data management applications. Sample Services OverviewThe swagger-server sample contains one service:
The reference contract Authentication ServiceThe AuthenticationService demonstrates token-based authentication using OpenAPI 3.x annotations (from @Path("/bigdataservice")
@Tag(name = "authentication", description = "User authentication and token management")
public class AuthenticationService {
@POST
@Path("/login")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "User authentication",
description = "Authenticate user with email and password, returns JWT token on success")
public Response authenticateUser(LoginRequest loginRequest) {
// Token generation and validation logic
}
}
Data ServiceAn illustrative data service with authenticated endpoints (not part of the sample): @Path("/api/data")
@Tag(name = "data", description = "Data management operations")
public class DataService {
@POST
@Path("/query")
@Operation(summary = "Query dataset",
description = "Retrieve filtered data with pagination")
public QueryResponse query(
@Parameter(description = "Query parameters") QueryRequest request,
@HeaderParam("Authorization") String bearerToken) {
// Data processing logic
}
@POST
@Path("/calculate")
@Operation(summary = "Run calculation")
public CalculationResponse calculate(
CalculationRequest request,
@HeaderParam("Authorization") String bearerToken) {
// Calculation logic
}
}
Note: Axis2's OpenAPI integration uses Request/Response ModelsAxis2 supports multiple JSON libraries — Moshi, Gson, and a streaming formatter — each with standard and HTTP/2-enhanced variants. Select the library by choosing the corresponding message builder and formatter classes in axis2.xml. The examples below use Moshi's public class LoginRequest {
@Json(name = "email")
private String email;
@Json(name = "credentials")
private String credentials;
// Getters and setters
}
public class LoginResponse {
@Json(name = "data")
private LoginData data;
@Json(name = "errorMessage")
private String errorMessage;
// Compatible with existing frontend expectations
}
OpenAPI Module ConfigurationTo enable OpenAPI documentation, place the openapi module archive ( <module ref="openapi" /> The module generates the specification, but it does not register any servlet itself. The documentation endpoints are served by delegating to the module's OpenAPI Configuration ParametersConfiguration is read from an
The module.xml inside the .mar also accepts the parameters Client Usage and API CompatibilityThe OpenAPI REST services are designed for seamless integration with existing frontend applications. Here are examples showing drop-in compatibility patterns: Authentication - Custom Token PatternLogin request maintaining existing frontend patterns: curl -v -H "Content-Type: application/json" \
-X POST \
--data '{"email":"[email protected]","credentials":"demo"}' \
http://localhost:8080/axis2/services/authService/login
Response format compatible with existing frontends: {
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"userId": "user123",
"email": "[email protected]"
},
"errorMessage": null
}
Data Services - Custom Header AuthenticationData requests using a custom bigdataToken header (maintaining frontend compatibility). This and the following examples illustrate patterns for your own services; the sample does not implement them: curl -v -H "bigdataToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-X POST \
--data '{"marketId":"MKT001","includeHistory":true}' \
http://localhost:8080/axis2/services/dataService/marketSummary
Where the response maintains existing data structure: {
"data": {
"marketId": "MKT001",
"marketName": "Growth Market",
"totalValue": 1500000.00,
"performanceData": {
"ytdReturn": 12.5,
"annualizedReturn": 8.2
}
},
"errorMessage": null
}
Financial Calculation ServicesFinancial calculation requests with custom authentication: curl -v -H "bigdataToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-X POST \
--data '{"calculationType":"netPresentValue","cashFlows":[100,200,300],"discountRate":0.05}' \
http://localhost:8080/axis2/services/dataService/financialCalculation
Financial calculation response format: {
"data": {
"calculationType": "netPresentValue",
"result": 544.22,
"calculationDetails": {
"inputCashFlows": [100, 200, 300],
"discountRate": 0.05,
"periodCount": 3
}
},
"errorMessage": null
}
Excel Integration - Function MetadataExcel Add-in compatibility with function specification endpoints: curl -v -H "bigdataToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-X GET \
http://localhost:8080/axis2/services/excelService/functionSpecs
Response providing Excel function metadata: {
"data": {
"functions": [
{
"name": "MARKET_VALUE",
"description": "Get current market value",
"parameters": ["marketId", "asOfDate"],
"returnType": "number"
},
{
"name": "FINANCIAL_CALC",
"description": "Perform financial calculations",
"parameters": ["calculationType", "parameters"],
"returnType": "number"
}
]
},
"errorMessage": null
}
OpenAPI Documentation AccessOnce deployed, the OpenAPI integration provides multiple ways to access API documentation: Interactive Swagger UIAccess the interactive API documentation at the path where the OpenAPI servlet is mapped, for example: http://localhost:8080/axis2/swagger-ui The Swagger UI provides:
OpenAPI Specification EndpointsAccess the raw OpenAPI specifications: # JSON format http://localhost:8080/axis2/openapi.json # YAML format http://localhost:8080/axis2/openapi.yaml # MCP tool catalog http://localhost:8080/axis2/openapi-mcp.json The specification endpoints send CORS headers for frontend integration and can be used by:
Drop-in Replacement GuideThis section provides step-by-step guidance for replacing existing REST backends with Axis2 OpenAPI services while maintaining frontend compatibility. Migration StrategyFollow this approach for seamless backend replacement:
Common Compatibility PatternsHandle common frontend integration patterns: Custom Authentication Headers// Support existing custom headers instead of standard Authorization
@HeaderParam("bigdataToken") String customToken
@HeaderParam("apiKey") String apiKey
@HeaderParam("sessionId") String sessionId
Response Envelope Patterns// Many frontends expect data/error envelope pattern
public class StandardResponse<T> {
@Json(name = "data")
private T data;
@Json(name = "errorMessage")
private String errorMessage;
@Json(name = "success")
private boolean success = true;
}
Path Parameter Compatibility// Match existing URL patterns exactly
@Path("/api/v1/markets/{marketId}/summary")
@Path("/bigdataservice/calculate") // Legacy path support
@Path("/excel/functions/{functionName}")
Frontend Integration TestingValidate drop-in compatibility with these testing approaches:
Configuration for Different FrameworksAxis2 OpenAPI services can replace backends built with various frameworks: Spring Boot Replacement# Spring Boot endpoint:
@PostMapping("/api/markets/summary")
public ResponseEntity<MarketResponse> getMarketSummary(@RequestBody MarketRequest request)
# Equivalent Axis2 service:
@POST
@Path("/api/markets/summary")
public MarketResponse getMarketSummary(MarketRequest request)
Express.js/Node.js Replacement// Express.js endpoint:
app.post('/api/auth/login', (req, res) => { ... })
// Equivalent Axis2 service:
@POST
@Path("/api/auth/login")
public LoginResponse login(LoginRequest request)
ASP.NET Core Replacement// ASP.NET Core endpoint:
[HttpPost("/api/data/process")]
public ActionResult<DataResponse> ProcessData([FromBody] DataRequest request)
// Equivalent Axis2 service:
@POST
@Path("/api/data/process")
public DataResponse processData(DataRequest request)
Performance and Best PracticesThe Axis2 OpenAPI integration is designed for enterprise performance and scalability: Performance Optimizations
Best Practices
Security ConsiderationsEnsure secure REST API implementation:
Troubleshooting and SupportCommon issues and solutions when implementing OpenAPI REST services: Module Loading IssuesIf the OpenAPI module fails to load:
Swagger UI Access ProblemsIf Swagger UI is not accessible:
API Compatibility IssuesWhen replacing existing backends:
Performance IssuesFor performance optimization:
For additional support, contact the Axis2 community through the mailing lists or GitHub issues. The community welcomes contributions and feedback on the OpenAPI integration. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |