BoxLang 🚀 A New JVM Dynamic Language Learn More...
|:------------------------------------------------------: |
| ⚡︎ B o x L a n g ⚡︎
| Dynamic : Modular : Productive
|:------------------------------------------------------: |
Copyright Since 2023 by Ortus Solutions, Corp
www.boxlang.io | www.ortussolutions.com
The bx-compat-soap module provides comprehensive SOAP
(Simple Object Access Protocol) web services functionality for BoxLang
applications. It provides Compatibility for Adobe Coldfusion and Lucee
Axis web services functionality. This module enables you to create,
consume, and manage SOAP-based web services with automatic WSDL
generation, request/response handling, and full support for complex
data types.
access="remote"
remote are accessible via SOAPInstall the module using CommandBox:
box install bx-compat-soap
To create a SOAP web service, simply create a BoxLang class with
remote methods:
/**
* Calculator Web Service
*/
class {
/**
* Add two numbers
* @a First number
* @b Second number
* @return The sum
*/
remote numeric function add( required numeric a, required numeric b ) {
return arguments.a + arguments.b;
}
/**
* Get user information
* @userId The user ID to lookup
* @return User struct
*/
remote struct function getUser( required string userId ) {
return {
id: arguments.userId,
name: "John Doe",
email: "[email protected]"
};
}
/**
* Get list of users
* @limit Maximum number of users to return
* @return Array of user structs
*/
remote array function getUsers( numeric limit = 10 ) {
var users = [];
for( var i = 1; i <= arguments.limit; i++ ) {
users.append({
id: i,
name: "User #i#"
});
}
return users;
}
/**
* This method is NOT accessible via SOAP (not marked as remote)
*/
public numeric function multiply( required numeric a, required numeric b ) {
return arguments.a * arguments.b;
}
}
The WSDL is automatically generated and accessible via the
?wsdl parameter:
http://yourserver/path/to/Calculator.bx?wsdl
Send SOAP requests to your service endpoint using standard SOAP envelope format:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:add soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://DefaultNamespace">
<a xsi:type="xsd:double">5.0</a>
<b xsi:type="xsd:double">10.0</b>
</ns1:add>
</soapenv:Body>
</soapenv:Envelope>
The service returns standard SOAP responses:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<addResponse xmlns="http://boxlang.ortussolutions.com/soap/">
<return>15.0</return>
</addResponse>
</soap:Body>
</soap:Envelope>
Errors are returned as standard SOAP faults:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>Server</faultcode>
<faultstring>Method not found or not accessible: multiply</faultstring>
<detail>Only methods with access="remote" can be invoked via SOAP</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The easiest way to consume a SOAP web service is using BoxLang's
createObject() function:
// Create a SOAP web service instance
ws = createObject( "webservice", "http://example.com/Calculator.bx?wsdl" );
// Call methods directly on the web service object
result = ws.add( 5, 10 );
writeOutput( "5 + 10 = #result#" );
// Call methods with named arguments
user = ws.getUser( userId = "123" );
writeOutput( "User: #user.name# (#user.email#)" );
// Get multiple results
users = ws.getUsers( limit = 5 );
for( user in users ) {
writeOutput( "#user.id#: #user.name#<br>" );
}
For more control over the SOAP request, you can configure the web service instance:
// Create web service with custom configuration
ws = createObject(
"webservice",
"http://example.com/Calculator.bx?wsdl",
{
timeout: 30,
username: "admin",
password: "secret"
}
);
// Call methods
result = ws.complexCalculation(
operation = "multiply",
values = [1, 2, 3, 4, 5]
);
SOAP faults are automatically converted to BoxLang exceptions:
try {
ws = createObject( "webservice", "http://example.com/Calculator.bx?wsdl" );
// Try to call a non-remote method (will throw exception)
result = ws.multiply( 5, 10 );
} catch( any e ) {
writeOutput( "SOAP Error: #e.message#" );
writeOutput( "Detail: #e.detail#" );
}
You can also use the SOAP components programmatically within your BoxLang code:
controller = new bxmodules.bxsoap.public.WSDLController();
wsdl = controller.getWSDL( class = "com.myapp.services.Calculator" );
writeOutput( wsdl );
controller = new bxmodules.bxsoap.public.WSDLController();
result = controller.invokeServiceMethod(
class = "com.myapp.services.Calculator",
targetMethod = "add",
args = { a: 5, b: 10 }
);
The main controller for WSDL generation and SOAP request handling.
Methods:
getWSDL( required string class ) - Generate WSDL for a
given classinvokeServiceMethod( required string class, required string
targetMethod, struct args = {} ) - Invoke a remote methodGenerates WSDL XML documents from BoxLang class metadata.
Features:
Parses incoming SOAP requests and extracts method name and parameters.
Features:
Builds SOAP response envelopes and SOAP faults.
Features:
Handles dynamic invocation of BoxLang methods with type coercion.
Features:
Extracts function metadata from BoxLang classes for WSDL generation.
Features:
string → xsd:string
numeric → xsd:double
boolean → xsd:boolean
date → xsd:dateTime
struct → Complex type with named elementsarray → Array type with sequential itemsany → xsd:anyType
The module can be configured in your Application.bx:
component {
this.name = "MySOAPApp";
// Module settings
this.modules = {
"bx-compat-soap": {
// Default namespace for WSDL generation
defaultNamespace: "http://mycompany.com/soap/",
// SOAP version (1.1 or 1.2)
soapVersion: "1.1"
}
};
}
Execute the test suite:
gradle test
Build the module JAR:
gradle build
BoxLang is a professional open-source project and it is completely funded by the community and Ortus Solutions, Corp. Ortus Patreons get many benefits like a cfcasts account, a FORGEBOX Pro account and so much more. If you are interested in becoming a sponsor, please visit our patronage page: https://patreon.com/ortussolutions
"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
$
box install bx-compat-soap