A comprehensive API-led MuleSoft architecture for Oil & Gas field service operations integrating Salesforce Agentforce, ServiceNow, SAP S/4HANA, and Contract Management systems.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXPERIENCE LAYER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β experience-energy-ops-api β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β Work Orders β β Asset Context β β Dispatch & β β
β β β’ Create β β β’ Lookup β β Estimates β β
β β β’ Update β β β’ Cache β β β’ Approval β β
β β β’ List/Get β β β’ Contracts β β β’ Assignment β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β OAuth 2.0 | JWT | Rate Limiting | OWASP Policies | mTLS β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PROCESS LAYER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β process-field-service-orch-api β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β Work Order β β Asset Master β β Contract β β
β β Orchestration β β Sync β β Resolution β β
β β β’ Saga Pattern β β β’ Delta Sync β β β’ Rate Cards β β
β β β’ Compensation β β β’ Cache Refresh β β β’ SLA Terms β β
β β β’ Retry/Circuit β β β’ Batch Process β β β’ Geo Matching β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β Anypoint MQ | Event Streaming | Error Handling | Monitoring β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββ
β SYSTEM LAYER β β SYSTEM LAYER β β SYSTEM LAYER β
βββββββββββββββββββββ€ βββββββββββββββββββββ€ βββββββββββββββββββββ€
βsystem-sap-eam-api β βsystem-servicenow β β system-clm-api β
β β β -api β β β
β βββββββββββββββββ β β βββββββββββββββββ β β βββββββββββββββββ β
β β Asset Master β β β β Work Orders β β β β Contracts β β
β β Maintenance β β β β ITSM/Field β β β β Rate Cards β β
β β Notifications β β β β Technicians β β β β SLA Terms β β
β β Parts/Labor β β β β Scheduling β β β β Approvals β β
β βββββββββββββββββ β β βββββββββββββββββ β β βββββββββββββββββ β
β OData/RFC/IDoc β β REST API v2 β β Generic REST β
β Circuit Breaker β β OAuth 2.0 β β Custom Auth β
βββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββ
β SAP S/4HANA β β ServiceNow β β CLM β
β β β β β (Icertis/ β
β β’ Plant Maint(PM) β β β’ ITSM β β DocuSign/ β
β β’ Asset Hierarchy β β β’ Field Service β β Agiloft) β
β β’ Work Orders β β β’ Dispatch β β β
β β’ Inventory β β β’ Mobile Apps β β β’ Service Contractsβ
β β’ Confirmations β β β’ SLA Management β β β’ Rate Management β
βββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββ
- Experience Layer: Purpose-built for Agentforce & human apps
- Process Layer: Cross-system orchestration with saga patterns
- System Layer: Vendor abstraction with unified contracts
- OAuth 2.0 client credentials for machine-to-machine
- JWT validation for user contexts
- mTLS between API layers
- Rate limiting with SLA tiers
- OWASP security policies
- Idempotency keys for safe retries
- Distributed tracing with correlation IDs
- Structured JSON logging with PII masking
- Anypoint Monitoring dashboards
- Business metrics (MTTR, SLA compliance)
- Error aggregation and alerting
- Event-driven architecture with Anypoint MQ
- Asset cache with TTL-based refresh
- Optimistic locking with ETags
- Compensation patterns for failures
- Replay-safe message processing
energy-field-service-integration/
βββ shared-models/ # Canonical data models
β βββ src/main/resources/
β βββ schemas/ # JSON Schema definitions
β β βββ Asset.json
β β βββ WorkOrder.json
β β βββ Contract.json
β β βββ EventEnvelope.json
β βββ dw/types/ # DataWeave type definitions
β βββ AssetType.dwl
β βββ WorkOrderType.dwl
β βββ ContractType.dwl
β βββ EventType.dwl
β βββ ErrorType.dwl
β
βββ experience-energy-ops-api/ # Experience Layer
β βββ src/main/
β β βββ mule/
β β β βββ app.xml # Main API flow & APIKit
β β β βββ global.xml # Global configs & security
β β β βββ work-order-flows.xml # Work order business logic
β β β βββ asset-flows.xml # Asset context & caching
β β β βββ dispatch-flows.xml # Dispatch & estimation
β β βββ resources/
β β βββ api/
β β β βββ experience-energy-ops-api.yaml
β β βββ config-dev.yaml
β β βββ config-staging.yaml
β β βββ config-prod.yaml
β β βββ secure-config-${env}.yaml
β βββ src/test/munit/ # MUnit test suites
β
βββ process-field-service-orch-api/ # Process Layer
β βββ src/main/mule/
β β βββ orchestration-flows.xml # Main orchestration logic
β β βββ saga-flows.xml # Saga & compensation patterns
β β βββ event-flows.xml # Event processing & MQ
β β βββ integration-flows.xml # System API calls
β βββ src/test/munit/
β
βββ system-sap-eam-api/ # SAP System API
β βββ src/main/mule/
β β βββ sap-asset-flows.xml # Asset master operations
β β βββ sap-maintenance-flows.xml # Work order operations
β β βββ sap-integration-flows.xml # OData/RFC/IDoc handling
β
βββ system-servicenow-api/ # ServiceNow System API
β βββ src/main/mule/
β β βββ snow-incident-flows.xml # Incident/Work Order CRUD
β β βββ snow-dispatch-flows.xml # Technician assignment
β β βββ snow-integration-flows.xml # REST API v2 handling
β
βββ system-clm-api/ # Contract Management System API
β βββ src/main/mule/
β β βββ clm-contract-flows.xml # Contract operations
β β βββ clm-ratecard-flows.xml # Rate management
β β βββ clm-integration-flows.xml # Generic REST handling
β
βββ deployment/ # CI/CD & Deployment
β βββ cloudhub2/ # CloudHub 2.0 configs
β βββ rtf/ # Runtime Fabric configs
β βββ github-actions/ # CI/CD workflows
β βββ docker/ # Container definitions
β
βββ docs/ # Additional documentation
βββ api-specifications/ # Complete OAS files
βββ integration-patterns/ # Pattern documentation
βββ troubleshooting/ # Runbooks & guides
- Java 17
- Maven 3.8+
- Anypoint Studio 7.x
- Anypoint Platform account
- Access to SAP, ServiceNow, Salesforce, CLM systems
-
Clone and Build
git clone <repository-url> cd energy-field-service-integration mvn clean install
-
Configure Secure Properties
# Create secure configuration files cp src/main/resources/secure-config-template.yaml src/main/resources/secure-config-dev.yaml # Update with your credentials # Use Anypoint CLI to encrypt sensitive values anypoint-cli secure-properties encrypt --value "your-secret" --key "encryption-key"
-
Start Applications
# Start each application (in separate terminals) cd experience-energy-ops-api && mvn mule:run cd process-field-service-orch-api && mvn mule:run cd system-sap-eam-api && mvn mule:run cd system-servicenow-api && mvn mule:run cd system-clm-api && mvn mule:run
# HTTP Configuration
http:
host: "0.0.0.0"
port: "8081"
# TLS Configuration
tls:
keystore:
path: "keystore.jks"
password: "!{secure::keystore.password}"
key:
password: "!{secure::keystore.key.password}"
truststore:
path: "truststore.jks"
password: "!{secure::truststore.password}"
# API Configuration
api:
base:
url: "https://localhost:8081/field-service/v1"
# Process API Configuration
process:
api:
host: "localhost"
port: "8082"
client:
id: "!{secure::process.api.client.id}"
secret: "!{secure::process.api.client.secret}"
token:
url: "https://auth.energy.com/oauth2/token"
# Salesforce Configuration
salesforce:
username: "!{secure::salesforce.username}"
password: "!{secure::salesforce.password}"
security:
token: "!{secure::salesforce.security.token}"
consumer:
key: "!{secure::salesforce.consumer.key}"
secret: "!{secure::salesforce.consumer.secret}"
login:
url: "https://login.salesforce.com/services/oauth2/token"
# OAuth Configuration
oauth:
issuer: "https://auth.energy.com"
# Rate Limiting
rate:
limit:
requests:
per:
minute: 100
# Application Metadata
app:
version: "1.0.0"
env: "dev"
# Security (for testing only)
test:
username: "testuser"
password: "testpass"sequenceDiagram
participant AF as Agentforce
participant EXP as Experience API
participant PROC as Process API
participant SAP as SAP System API
participant CLM as CLM System API
participant SNOW as ServiceNow API
participant SF as Salesforce
AF->>EXP: POST /work-orders (caseId, assetId, symptoms)
EXP->>EXP: Validate OAuth/JWT + Rate Limit
EXP->>EXP: Check Idempotency Key
EXP->>PROC: GET /assets/{assetId}
PROC->>SAP: Fetch asset context
SAP-->>PROC: Asset details + maintenance history
PROC-->>EXP: Enriched asset context
EXP->>PROC: GET /contracts/applicable
PROC->>CLM: Find contracts by location/vendor
CLM-->>PROC: Rate cards + SLA terms
PROC-->>EXP: Best-fit contract
EXP->>PROC: POST /estimates/calculate
PROC-->>EXP: Cost breakdown
EXP->>PROC: POST /work-orders
PROC->>SNOW: Create work order/incident
PROC->>SF: Create/update Case task
PROC->>SAP: Create maintenance notification
PROC-->>EXP: Work order with external IDs
EXP-->>AF: 201 Created + Work Order details
sequenceDiagram
participant SNOW as ServiceNow
participant SNOW_API as ServiceNow API
participant PROC as Process API
participant SAP_API as SAP System API
participant SAP as SAP S/4HANA
participant SF as Salesforce
participant MQ as Anypoint MQ
SNOW->>SNOW_API: Work order status update webhook
SNOW_API->>PROC: POST /work-orders/{id}/status
PROC->>PROC: Transform to canonical WorkOrder
alt Status = COMPLETED
PROC->>SAP_API: POST /confirmations
SAP_API->>SAP: Goods issue + time confirmation
SAP-->>SAP_API: Success
end
PROC->>SF: Update Case/Task status
SF-->>PROC: Success
PROC->>MQ: Publish workorder.status.changed event
MQ-->>PROC: Event published
PROC-->>SNOW_API: 200 OK
sequenceDiagram
participant SCHEDULER as Anypoint Scheduler
participant PROC as Process API
participant SAP_API as SAP System API
participant SAP as SAP S/4HANA
participant CACHE as Object Store
participant MQ as Anypoint MQ
SCHEDULER->>PROC: Trigger asset delta sync
PROC->>SAP_API: GET /assets/delta?since=lastSync
SAP_API->>SAP: Query changed assets (EQUI/FUNC)
SAP-->>SAP_API: Delta asset records
SAP_API-->>PROC: Normalized asset list
loop For each changed asset
PROC->>PROC: Transform to canonical Asset
PROC->>CACHE: Update asset cache
PROC->>MQ: Publish asset.changed event
end
PROC->>PROC: Update last sync timestamp
<!-- OAuth Provider Configuration -->
<oauth:provider-config name="oauth-provider">
<oauth:client-credentials-grant-type
clientId="${oauth.client.id}"
clientSecret="${oauth.client.secret}"
tokenUrl="${oauth.token.url}">
<oauth:token-validation>
<oauth:jwt-validation
issuer="${oauth.issuer}"
audience="${oauth.audience}" />
</oauth:token-validation>
</oauth:client-credentials-grant-type>
</oauth:provider-config><!-- Rate Limiting with Object Store -->
<flow name="rate-limiting-flow">
<set-variable variableName="clientKey"
value="#[vars.clientId ++ ':' ++ attributes.remoteAddress]" />
<set-variable variableName="rateLimitKey"
value="#['rate-limit:' ++ vars.clientKey ++ ':' ++
((now() as Number) / 60000 as Number {format: '0'})]" />
<os:retrieve key="#[vars.rateLimitKey]"
objectStore="rate-limit-store" />
<validation:is-true expression="#[(payload as Number + 1) <= ${rate.limit.requests.per.minute}]"
message="Rate limit exceeded" />
<os:store key="#[vars.rateLimitKey]"
objectStore="rate-limit-store">
<os:value>#[payload as Number + 1]</os:value>
</os:store>
</flow><json-logger:logger config-ref="json-logger-config"
message="Work Order Created">
<json-logger:content><![CDATA[
{
"correlationId": "$(correlationId)",
"workOrderId": "$(vars.workOrderId)",
"assetId": "$(vars.assetId)",
"priority": "$(vars.priority)",
"estimatedCost": "$(vars.costEstimate.total)",
"responseTime": "$((now() - vars.startTime) as Number)",
"timestamp": "$(now())"
}
]]></json-logger:content>
</json-logger:logger>- Work orders created per hour/day
- Mean Time to Resolution (MTTR)
- SLA compliance percentage
- Cost accuracy (estimated vs actual)
- Asset utilization rates
- Contract utilization by vendor
- API response time < 2s (95th percentile)
- System availability > 99.9%
- Error rate < 0.1%
- Cache hit ratio > 80%
- Message processing latency < 500ms
<!-- Example MUnit Test -->
<munit:test name="create-work-order-test" description="Test work order creation">
<munit:behavior>
<munit-tools:mock-when processor="http:request" doc:name="Mock Process API">
<munit-tools:with-attributes>
<munit-tools:with-attribute whereValue="process-api-config" attributeName="config-ref"/>
</munit-tools:with-attributes>
<munit-tools:then-return>
<munit-tools:payload value="#[{woId: 'WO0000123456', status: 'NEW'}]"/>
</munit-tools:then-return>
</munit-tools:mock-when>
</munit:behavior>
<munit:execution>
<flow-ref name="create-work-order-flow"/>
</munit:execution>
<munit:validation>
<munit-tools:assert-that expression="#[payload.woId]"
is="#[MunitTools::notNullValue()]"/>
<munit-tools:assert-equals actual="#[payload.status]" expected="NEW"/>
</munit:validation>
</munit:test>- Unit Tests: Individual flow testing with mocks
- Integration Tests: End-to-end API testing
- Contract Tests: OAS specification validation
- Load Tests: Performance under stress
- Security Tests: Authentication & authorization
- Chaos Tests: Resilience testing
# deployment/cloudhub2/experience-api-deployment.yaml
apiVersion: v1alpha1
kind: Application
metadata:
name: experience-energy-ops-api
environment: production
spec:
image: experience-energy-ops-api:1.0.0
replicas: 3
resources:
vcores: 2.0
memory: 4Gi
networking:
ingress:
enabled: true
host: api.energy.com
tls:
enabled: true
monitoring:
enabled: true
metrics:
- business.metrics
- performance.metrics# Deploy to RTF
anypoint-cli runtime-fabric deploy \
--application-name experience-energy-ops-api \
--target production-rtf \
--artifact-path target/experience-energy-ops-api-1.0.0-mule-application.jar \
--replicas 3 \
--cpu-limit 2000m \
--memory-limit 4Gi# .github/workflows/deploy.yml
name: Deploy Energy APIs
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
- run: mvn clean test
build-and-deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
- run: mvn clean package -DskipTests
- run: |
anypoint-cli login \
--username ${{ secrets.ANYPOINT_USERNAME }} \
--password ${{ secrets.ANYPOINT_PASSWORD }}
anypoint-cli cloudhub2 deploy \
--application-name experience-energy-ops-api-prod \
--artifact target/*.jar \
--replicas 3<!-- Health Check Flow -->
<flow name="health-check-flow">
<http:listener path="/health" config-ref="httpListenerConfig"/>
<choice>
<when expression="#[attributes.queryParams.deep == 'true']">
<parallel-foreach collection="#[['process-api', 'sap-api', 'snow-api', 'clm-api']]">
<try>
<http:request method="GET"
path="/health"
config-ref="#[payload ++ '-config']"/>
<set-payload value="#[{service: payload, status: 'UP', responseTime: vars.responseTime}]"/>
<error-handler>
<on-error-continue>
<set-payload value="#[{service: payload, status: 'DOWN', error: error.description}]"/>
</on-error-continue>
</error-handler>
</try>
</parallel-foreach>
<set-payload value="#[{
status: if (payload..status contains 'DOWN') 'DEGRADED' else 'UP',
timestamp: now(),
services: payload,
version: '${app.version}',
environment: '${env}'
}]"/>
</when>
<otherwise>
<set-payload value="#[{
status: 'UP',
timestamp: now(),
version: '${app.version}',
environment: '${env}'
}]"/>
</otherwise>
</choice>
</flow>- Asset Cache: 4-hour TTL with background refresh
- Contract Cache: 24-hour TTL with change notifications
- Rate Limit Cache: 1-minute sliding window
- Authentication Cache: 15-minute JWT validation cache
<http:request-connection-provider name="pooled-connection-provider">
<http:pooling-profile
maxActive="50"
maxIdle="10"
exhaustedAction="WHEN_EXHAUSTED_WAIT"
maxWait="60000"/>
<http:tcp-client-socket-properties
connectionTimeout="30000"
keepAlive="true"/>
</http:request-connection-provider>-
OAuth Token Expiration
Error: OAUTH:TOKEN_UNAUTHORIZED Solution: Check token expiration and refresh logic -
Rate Limit Exceeded
Error: HTTP:TOO_MANY_REQUESTS Solution: Implement exponential backoff in client -
SAP Connection Issues
Error: SAP:RFC_EXCEPTION Solution: Check SAP gateway configuration and user permissions -
ServiceNow Timeout
Error: HTTP:TIMEOUT Solution: Increase timeout values and implement circuit breaker
GET /health- Application health statusGET /health?deep=true- Deep health check with dependenciesGET /metrics- Performance metricsGET /config- Configuration validation (non-sensitive only)
- Anypoint Platform Documentation
- API-Led Connectivity Methodology
- MuleSoft Best Practices
- OAuth 2.0 RFC
- OpenAPI 3.0 Specification
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is proprietary software owned by Energy Corp. All rights reserved.
Contact: Field Service API Team - [email protected] Version: 1.0.0 Last Updated: January 2024