FAQ

Can ColdFusion Send Push Notifications?

Definition

Yes—ColdFusion (CFML on Adobe ColdFusion or Lucee) can send Push notifications. ColdFusion doesn’t include a “push” tag, but it can call push services such as Firebase Cloud Messaging (FCM) for Android and web, Apple Push Notification service (APNs) for iOS/macOS, and Web Push endpoints for PWAs. You do this by making authenticated HTTP requests (REST APIs), generating tokens (JWT/VAPID) when required, and managing device tokens or topics server-side.


How It Works

At a high level, ColdFusion acts as the server-side orchestrator:

  • Your app collects device tokens or web push subscriptions from clients (mobile app, browser).
  • ColdFusion stores these identifiers securely (database, cache).
  • When an event occurs (e.g., order shipped), ColdFusion composes a payload and sends it via:
    • FCM (Android, iOS via Firebase SDKs, and web)
    • APNs (directly for iOS/macOS if you don’t use FCM for iOS)
    • Web Push (VAPID-based for browsers supporting the Push API)
  • The push platform delivers the notification to the device.

Key CFML capabilities you’ll use:

  • cfhttp or HTTP client libraries to call REST endpoints
  • JSON serialization/deserialization
  • JWT creation (for APNs and FCM HTTP v1 OAuth flow) via Java interop
  • Scheduling and background tasks via cfschedule or cfthread
  • Secure key storage (environment variables, secrets manager)

Implementation Options

Option 1: Firebase Cloud Messaging (FCM)

  • Best for Android, and commonly used for iOS and web as well.
  • Supports single-device, device groups, topics, and condition messaging.
  • Modern HTTP v1 API uses OAuth 2.0 access tokens generated from a Google service account (more secure than legacy server key).
See also  Can ColdFusion Be Learned Without Prior Coding Experience?

Option 2: Apple Push Notification service (APNs)

  • Direct iOS/macOS push if you’re not using FCM for iOS.
  • Requires a developer account, APNs key (p8), Team ID, and Key ID.
  • Uses JWT (ES256) to authenticate to Apple’s servers and HTTP/2.

Option 3: Web Push (VAPID)

  • For Progressive Web Apps and desktop browser notifications.
  • Requires VAPID public/private keys and payload encryption per Standards.
  • Typically easier with a Java Web Push library called from CFML.

Step-by-Step: Sending to FCM (HTTP v1)

Prerequisites

  • Firebase project with FCM enabled
  • Google Cloud service account (JSON key)
  • Device registration tokens or subscribed topics

Flow

  1. Create a short-lived OAuth 2.0 access token from your service account (scopes: https://www.googleapis.com/auth/firebase.messaging).
  2. Build a JSON payload with notification/data fields.
  3. POST to FCM send endpoint: https://fcm.googleapis.com/v1/projects/PROJECT_ID/messages:send
  4. Handle response, log message ID, retry on transient errors.

Example CFML (CFScript) using cfhttp to FCM

Note: This example expects an accessToken already generated via a server-side JWT-to-OAuth exchange (use Java Google Auth libs or an HTTP call to Google OAuth).

projectId = “your-firebase-project-id”;
accessToken = variables.oauthAccessToken; // obtain via service account
deviceToken = “your-device-registration-token”;

payload = {
message: {
token: deviceToken,
notification: { title: “Order Ready”, body: “Tap to view your order.” },
data: { orderId: “12345”, action: “view” },
android: { priority: “HIGH”, ttl: “3600s” },
apns: { headers: { “apns-priority”: “10” } }
}
};

cfhttp(
method=”POST”,
url=”https://fcm.googleapis.com/v1/projects/#projectId#/messages:send“,
result=”fcmResp”
) {
cfhttpparam(type=”header”, name=”Authorization”, value=”Bearer #accessToken#”);
cfhttpparam(type=”header”, name=”Content-Type”, value=”application/json; charset=UTF-8″);
cfhttpparam(type=”body”, value=serializeJSON(payload));
}

if (fcmResp.statusCode EQ “200”) {
writeOutput(“Success: ” & fcmResp.fileContent);
} else {
writeOutput(“Error: ” & fcmResp.statusCode & ” – ” & fcmResp.fileContent);
}

Tips:

  • Prefer HTTP v1 over legacy server keys for improved Security.
  • Use topics (e.g., news, offers) to avoid managing huge token lists.
  • Apply collapse_key and TTL to control delivery semantics.

Step-by-Step: Sending to APNs (Direct)

Prerequisites

  • Apple developer account
  • APNs Auth Key (.p8), Team ID, Key ID
  • App bundle ID
  • Device token from iOS app

Flow

  1. Generate a JWT signed with ES256 using your .p8 key (header includes alg and kid, claims include iss and iat).
  2. Construct HTTP/2 POST to:
  3. Include apns-topic (bundle ID) header and the JSON payload.
  4. Refresh JWT at least every 20 minutes.

Because CFML runs on the JVM, you can use Java’s crypto (or BouncyCastle) to sign ES256. Consider creating a reusable CFC that loads the private key once and signs tokens on demand.

See also  Can ColdFusion Scale for Large Applications?

Web Push from ColdFusion (VAPID)

  • Generate VAPID public/private keys once (store securely).
  • Clients subscribe via the Push API and send you an endpoint URL plus keys (p256dh, auth).
  • Server encrypts payload with the subscription keys and sends an HTTP POST to the endpoint.
  • In CFML, call a Java Web Push library to handle encryption:
    • Example: web-push Java libraries (e.g., web-push for Java) via createObject(“java”, …).
  • Useful for PWAs on Chrome, Firefox, Edge, and Safari (with caveats and evolving support).

Real-World Example

A SaaS reporting platform processes large data exports. When a report is ready:

  • The job runner (CF scheduled task) marks the report complete.
  • ColdFusion looks up the user’s preferred channel: iOS token, Android token, or PWA subscription.
  • CF posts a notification:
    • FCM topic “reports” if many users opted in.
    • Individual FCM tokens or APNs device token for personal alerts.
    • Web Push for browser users.
  • The payload includes a deep link to the report view. ColdFusion logs the push response, retries on 5xx, and records delivery IDs for auditing.

Outcome: Users receive timely alerts across devices, while the server keeps a clean Audit trail and token hygiene.


Best practices

  • Security and Secrets
    • Store API keys, service account JSON, and APNs p8 in environment variables or a secrets manager.
    • Rotate keys periodically.
  • Token Management
    • Persist tokens per user/device with metadata (platform, app version).
    • Remove invalid tokens when FCM/APNs returns errors (e.g., NotRegistered, Unregistered).
  • Delivery Semantics
    • Use TTL and collapse keys to minimize noisy notifications.
    • Prefer data messages when your app needs custom handling; use notification payload for simple alerts.
  • Resilience
    • Implement exponential backoff on 429/5xx.
    • Queue messages (e.g., Redis, RabbitMQ) for bursts and retries.
  • Observability
    • Log request/response, message IDs, and outcomes.
    • Monitor rate limits, error codes, and latency.
  • Environment Separation
    • Distinguish APNs sandbox vs production.
    • Use separate Firebase projects for dev/stage/prod.
  • Compliance
    • Provide opt-in/out and honor user preferences.
    • Avoid sensitive data in payloads; encrypt where appropriate.

Pros and cons of Using ColdFusion for Push

  • Pros

    • Leverages existing CFML backend; no new server stack needed.
    • Strong HTTP/JSON support via cfhttp.
    • Easy scheduling via cfschedule and parallelism with cfthread.
    • JVM interop unlocks JWT/VAPID libraries.
  • Cons

    • No built-in push tag; you must integrate APIs and crypto.
    • APNs requires HTTP/2 and ES256 signing; adds complexity.
    • Web Push encryption is non-trivial without a helper library.
    • Must build token/topic management and retry logic.
See also  Is ColdFusion Good for SaaS Products?

Syntax and API Notes

  • FCM HTTP v1
    • Auth: OAuth 2.0 bearer token from a service account.
    • Endpoint: /v1/projects/PROJECT_ID/messages:send
    • Features: topics, condition, android/ios/web overrides, analytics label.
  • FCM Legacy (not recommended)
    • Auth: server key in Authorization: key= header.
    • Endpoint: /fcm/send
  • APNs
    • Auth: JWT via ES256; header includes kid; claims include iss (Team ID).
    • Headers: apns-topic (bundle ID), apns-priority, apns-expiration.
    • Requires HTTP/2; use a modern HTTP client on the JVM.
  • Web Push
    • Requires VAPID headers and payload encryption with user-visible keys.

Key Takeaways

  • ColdFusion can absolutely send Push notifications by integrating with FCM, APNs, and Web Push via REST.
  • There’s no native tag; use cfhttp, Java interop for JWT/VAPID, and robust token management.
  • Prefer FCM HTTP v1 with OAuth 2.0 and consider topics for scale.
  • Build resilience: retries, logging, TTLs, and cleanup of invalid tokens.
  • Secure your secrets and separate environments to avoid accidental cross-traffic.

FAQ

Does ColdFusion have a built-in tag for push notifications?

No. ColdFusion provides cfhttp and related tools to call external push services. You implement push by integrating FCM, APNs, or Web Push APIs from CFML.

Can Lucee do the same things as Adobe ColdFusion for push?

Yes. Both run CFML on the JVM and can call the same HTTP endpoints and Java libraries. Ensure your Lucee/Java version supports the TLS/HTTP2 and crypto required by APNs and modern libraries.

Should I use FCM or APNs for iOS?

Many teams use FCM for both Android and iOS to unify messaging and analytics. Others prefer direct APNs for iOS. Both work with ColdFusion; choose based on ecosystem preferences, instrumentation, and operational simplicity.

How do I handle invalid or expired device tokens?

Inspect error codes from FCM/APNs. Remove tokens flagged as NotRegistered/Unregistered or with permanent errors. Implement automatic cleanup to prevent repeated failures and to reduce costs.

What’s the best way to schedule and scale push sends?

Use cfschedule for periodic jobs, cfthread for parallelism, and a queue (Redis/RabbitMQ/SQS) for burst control and retries. For high volume, batch tokens by topic and use exponential backoff on 429/5xx responses.

About the author

Aaron Longnion

Aaron Longnion

Hey there! I'm Aaron Longnion — an Internet technologist, web software engineer, and ColdFusion expert with more than 24 years of experience. Over the years, I've had the privilege of working with some of the most exciting and fast-growing companies out there, including lynda.com, HomeAway, landsofamerica.com (CoStar Group), and Adobe.com.

I'm a full-stack developer at heart, but what really drives me is designing and building internet architectures that are highly scalable, cost-effective, and fault-tolerant — solutions built to handle rapid growth and stay ahead of the curve.