Software

How to Create a Webhook for Uptime Robot

Oracle Integration Cloud

Java

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "SampleUptimeRobotServlet", value = "/")
public class SampleUptimeRobotServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    ...
  }

}

Go

package main

import (
  "net/http"

  "github.com/gorilla/handlers"
)

func main() {
  http.Handle("/", handlers.MethodHandler{
    http.MethodGet: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...
    }),
  })

  http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
}

Node.js

const fs = require('fs')
const https = require('https')

const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

app.get('/', (req, res) => {
  ...
})

https.createServer(options, app).listen(8443)

Python

from flask import Flask

app = Flask(__name__)

@app.route('/', methods = [ 'GET' ])
def do_get():
  ...

Ruby

require 'sinatra'

get '/' do
  ...
end
Software

How to Create a Webhook for Uptime (formerly Pingometer)

Oracle Integration Cloud

Java

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "SampleUptimeServlet", value = "/")
public class SampleUptimeServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
    ...
  }

}

Go

package main

import (
  "net/http"

  "github.com/gorilla/handlers"
)

func main() {
  http.Handle("/", handlers.MethodHandler{
    http.MethodPost: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...
    }),
  })

  http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
}

Node.js

const fs = require('fs')
const https = require('https')

const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

app.post('/', (req, res) => {
  ...
})

https.createServer(options, app).listen(8443)

Python

from flask import Flask

app = Flask(__name__)

@app.route('/', methods = [ 'POST' ])
def do_post():
  ...

Ruby

require 'sinatra'

post '/' do
  ...
end
Software

How to Create a Webhook for Pingdom

Oracle Integration Cloud

Java

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "SamplePingdomServlet", value = "/")
public class SamplePingdomServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
    ...
  }

}

Go

package main

import (
  "net/http"

  "github.com/gorilla/handlers"
)

func main() {
  http.Handle("/", handlers.MethodHandler{
    http.MethodPost: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...
    }),
  })

  http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
}

Node.js

const fs = require('fs')
const https = require('https')

const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

app.post('/', (req, res) => {
  ...
})

https.createServer(options, app).listen(8443)

Python

from flask import Flask

app = Flask(__name__)

@app.route('/', methods = [ 'POST' ])
def do_post():
  ...

Ruby

require 'sinatra'

post '/' do
  ...
end
Software

How to Create a Bot for Microsoft Teams

Bot Framework API w/ Java

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

@WebServlet(name = "SampleTeamsServlet", value = "/")
public class SampleTeamsServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
    ...

    Client client = ClientBuilder.newClient();

    client.target("https://host/v3/conversations/sampleConversationId/activities/sampleActivityId").request().header("Authorization", "...").post(Entity.json("{ \"type\": \"message\", \"from\": { \"id\": \"sampleBotId\", \"name\": \"SampleBot\" }, \"recipient\": { \"id\": \"sampleUserId\", \"name\": \"Sample User\" }, \"text\": \"Sample Message\" }"));

    client.close();
  }

}

Bot Framework API w/ Go

package main

import (
  "net/http"

  "github.com/go-resty/resty/v2"
  "github.com/gorilla/handlers"
)

func main() {
  http.Handle("/", handlers.MethodHandler{
    http.MethodPost: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...

      client := resty.New()

      client.R().SetHeader("Authorization", "...").SetHeader("Content-Type", "application/json").SetBody(`{ "type": "message", "from": { "id": "sampleBotId", "name": "SampleBot" }, "recipient": { "id": "sampleUserId", "name": "Sample User" }, "text": "Sample Message" }`).Post("https://host/v3/conversations/sampleConversationId/activities/sampleActivityId")
    }),
  })

  http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
}

Bot Framework API w/ Node.js

const fs = require('fs')
const https = require('https')

const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

app.post('/', (req, res) => {
  ...

  var req = https.request({ headers: { 'Authorization': '...', 'Content-Type': 'application/json', 'User-Agent': 'Sample Client' }, hostname: 'graph.facebook.com', method: 'POST', path: '/me/messages' })

  req.write('{ "type": "message", "from": { "id": "sampleBotId", "name": "SampleBot" }, "recipient": { "id": "sampleUserId", "name": "Sample User" }, "text": "Sample Message" }')

  req.end()
})

https.createServer(options, app).listen(8443)

Bot Framework API w/ Python

from flask import Flask
import requests

app = Flask(__name__)

@app.route('/', methods = [ 'POST' ])
def do_post():
  ...

  requests.post('https://host/v3/conversations/sampleConversationId/activities/sampleActivityId', json = { 'type': 'message', 'from': { 'id': 'sampleBotId', 'name': 'SampleBot' }, 'recipient': { 'id': 'sampleUserId', 'name': 'Sample User' }, 'text': 'Sample Message' }, headers = { 'Authorization': '...' })

  return ''

Bot Framework API w/ Ruby

require 'rest-client'
require 'sinatra'

post '/' do
  ...

  RestClient.post 'https://host/v3/conversations/sampleConversationId/activities/sampleActivityId', '{ "type": "message", "from": { "id": "sampleBotId", "name": "SampleBot" }, "recipient": { "id": "sampleUserId", "name": "Sample User" }, "text": "Sample Message" }', :authorization => '...', :content_type => 'application/json'
end

Bot Framework Java SDK

import java.util.concurrent.CompletableFuture;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.microsoft.bot.builder.Activity;
import com.microsoft.bot.builder.ActivityHandler;
import com.microsoft.bot.builder.BotFrameworkAdapter;
import com.microsoft.bot.builder.TurnContext;

@WebServlet(name = "SampleTeamsServlet", value = "/")
public class SampleTeamsServlet extends HttpServlet {
  private BotFrameworkAdapter adapter;

  @Override
  public void init() {
    adapter = ...
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
    Jsonb jsonb = JsonbBuilder.create();

    adapter.processIncomingActivity(req.getHeader("Authorization"), jsonb.fromJson(request.getInputStream(), Activity.class), new ActivityHandler() {

      @Override
      public CompletableFuture<Void> onTurn(TurnContext context) {
        context.sendActivity("Sample Message");
      }

    });
  }

}

Bot Framework Node.js SDK

const fs = require('fs')
const https = require('https')

const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

var adapter = ...

app.post('/', (req, res) => {
  ...

  adapter.processActivity(req, res, (context) => {
    context.sendActivity('Sample Message')
  })
})

https.createServer(options, app).listen(8443)

Bot Framework Python SDK

from botbuilder.schema import Activity
from flask import Flask, request

app = Flask(__name__)

adapter = ...

def on_turn(context):
  context.send_activity('Sample Message')

@app.route('/', methods = [ 'POST' ])
def do_post():
  ...

  adapter.process_activity(Activity.deserialize(request.json), request.headers['Authorization'], on_turn)

  return ''
Software

How to Create a Webhook/Custom Channel for Oracle Digital Assistant

Oracle Integration Cloud

API w/ Java

import java.io.IOException;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;

@WebServlet(name = "SampleDigitalAssistantServlet", value = "/")
public class SampleDigitalAssistantServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ...

    HttpClient client = HttpClient.newHttpClient();

    String body = "{ \"userId\": \"sampleUserId\", \"messagePayload\": { \"type\": \"text\", \"text\": \"Sample Message\" } }";

    client.send(HttpRequest.newBuilder().uri(URI.create("https://host/path")).header("X-Hub-Signature", "sha256=" + new HmacUtils(HmacAlgorithms.HMAC_SHA_256, "sampleSecret").hmacHex(body)).POST(BodyPublishers.ofString(body)).build(), BodyHandlers.discarding());
  }

}

API w/ Go

package main

import (
  "bytes"
  "crypto/hmac"
  "crypto/sha256"
  "encoding/hex"
  "net/http"

  "github.com/gorilla/handlers"
)

func main() {
  http.Handle("/", handlers.MethodHandler{
    http.MethodPost: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...

      client := &http.Client{}

      body := []byte(`{ "userId": "sampleUserId", "messagePayload": { "type": "text", "text": "Sample Message" } }`)

      req, _ := http.NewRequest("POST", "https://host/path", bytes.NewReader(body))

      mac := hmac.New(sha256.New, []byte("sampleSecret"))

      mac.Write(body)

      req.Header.Add("X-Hub-Signature", "sha256=" + hex.EncodeToString(mac.Sum(nil)))

      client.Do(req)
    }),
  })

  http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
}

API w/ Node.js

const fs = require('fs')
const https = require('https')

const CryptoJS = require('crypto-js')
const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

app.post('/', (req, res) => {
  ...

  var body = '{ "userId": "sampleUserId", "messagePayload": { "type": "text", "text": "Sample Message" } }'

  var req = https.request({ headers: { 'X-Hub-Signature': 'sha256=' + CryptoJS.HmacSHA256(body, 'sampleSecret') }, hostname: 'host', method: 'POST', path: '/path' })

  req.write(body)

  req.end()
})

https.createServer(options, app).listen(8443)

API w/ Python

from flask import Flask
import hashlib, hmac, requests

app = Flask(__name__)

@app.route('/', methods = [ 'POST' ])
def do_post():
  ...

  body = b'{ "userId": "sampleUserId", "messagePayload": { "type": "text", "text": "Sample Message" } }'

  requests.post('https://host/path', data = body, headers = { 'X-Hub-Signature': 'sha256=' + hmac.new(b'sampleSecret', body, hashlib.sha256).hexdigest() })

  return ''

API w/ Ruby

require 'net/http'
require 'openssl'
require 'sinatra'

post '/' do
  ...

  http = Net::HTTP.new('host', Net::HTTP.https_default_port())

  http.use_ssl = true

  req = Net::HTTP::Post.new('/path')

  req.body = '{ "userId": "sampleUserId", "messagePayload": { "type": "text", "text": "Sample Message" } }'

  req['X-Hub-Signature'] = 'sha256=' + OpenSSL::HMAC.hexdigest('SHA256', 'sampleSecret', req.body)

  http.request(req)
end

Node.js SDK

const fs = require('fs')
const https = require('https')

const OracleBot = require('@oracle/bots-node-sdk')
const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

var webhook = new OracleBot.Middleware.WebhookClient({ channel: { url: 'https://host/path', secret: 'sampleSecret' } })

app.post('/', (req, res) => {
  ...

  webhook.send({ "userId": "sampleUserId", "messagePayload": { "type": "text", "text": "Sample Message" } })
})

https.createServer(options, app).listen(8443)
Software

How to Create a Webhook/Bot for Workplace by Facebook

Oracle Integration Cloud

Java

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

@WebServlet(name = "SampleWorkplaceServlet", value = "/")
public class SampleWorkplaceServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ...

    resp.getWriter().print(req.getParameter("hub.challenge")); // void-safe
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
    ...

    Client client = ClientBuilder.newClient();

    client.target("https://graph.facebook.com/me/messages").request().header("Authorization", "...").post(Entity.json("{ \"recipient\": { \"id\": \"sampleUserId\" }, \"message\": { \"text\": \"Sample Message\" } }")); // or "{ "recipient": { "thread_key": "sampleThreadId" }, "message": { "text": "Sample Message" } }" for group chats

    client.close();
  }

}

Go

package main

import (
  "net/http"

  "github.com/go-resty/resty/v2"
  "github.com/gorilla/handlers"
)

func main() {
  http.Handle("/", handlers.MethodHandler{
    http.MethodGet: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...

      w.Write([]byte(r.URL.Query().Get("hub.challenge"))) // void-safe
    }),
    http.MethodPost: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      ...

      client := resty.New()

      client.R().SetHeader("Authorization", "...").SetHeader("Content-Type", "application/json").SetBody(`{ "recipient": { "id": "sampleUserId" }, "message": { "text": "Sample Message" } }`).Post("https://graph.facebook.com/me/messages") // or "{ "recipient": { "thread_key": "sampleThreadId" }, "message": { "text": "Sample Message" } }" for group chats
    }),
  })

  http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", nil)
}

Node.js

const fs = require('fs')
const https = require('https')

const express = require('express')

var options = {
  cert: fs.readFileSync('cert.pem'),
  key: fs.readFileSync('key.pem')
}

var app = express()

app.get('/', (req, res) => {
  ...

  res.write(req.query['hub.challenge']) // non-void-safe

  res.end()
});

app.post('/', (req, res) => {
  ...

  var req = https.request({ headers: { 'Authorization': '...', 'Content-Type': 'application/json', 'User-Agent': 'Sample Client' }, hostname: 'graph.facebook.com', method: 'POST', path: '/me/messages' })

  req.write('{ "recipient": { "id": "sampleUserId" }, "message": { "text": "Sample Message" } }') // or '{ "recipient": { "thread_key": "sampleThreadId" }, "message": { "text": "Sample Message" } }' for group chats

  req.end()
})

https.createServer(options, app).listen(8443)

Python

from flask import Flask, request
import requests

app = Flask(__name__)

@app.route('/', methods = [ 'GET' ])
def do_get():
  ...

  return request.args.get('hub.challenge') # non-void-safe

@app.route('/', methods = [ 'POST' ])
def do_post():
  ...

  requests.post('https://graph.facebook.com/me/messages', json = { 'recipient': { 'id': 'sampleUserId' }, 'message': { 'text': 'Sample Message' } }, headers = { 'Authorization': '...' }) # or { 'recipient': { 'thread_key': 'sampleThreadId' }, 'message': { 'text': 'Sample Message' } }' for group chats

  return ''

Ruby

require 'rest-client'
require 'sinatra'

get '/' do
  ...

  params['hub.challenge'] # void-safe
end

post '/' do
  ...

  RestClient.post 'https://graph.facebook.com/me/messages', '{ "recipient": { "id": "sampleUserId" }, "message": { "text": "Sample Message" } }', :authorization => '...', :content_type => 'application/json' # or '{ "recipient": { "thread_key": "sampleThreadId" }, "message": { "text": "Sample Message" } }' for group chats
end
Software

How to Update an Entry with the Infinispan REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

@WebServlet(name = "SampleInfinispanServlet", value = "/")
public class SampleInfinispanServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    Client client = ClientBuilder.newClient();

    client.register(HttpAuthenticationFeature.basic("user", "password"));

    Entity entity = ...

    client.target("http://host:8080/rest/samplecache/samplekey").request().post(entity);

    client.close();
  }

}
Software

How to Search MBeans with the Jolokia REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@SuppressWarnings("serial")
@WebServlet(name = "SampleJolokiaServlet", value = "/")
public class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Client client = ClientBuilder.newClient();

    Response res = client.target("http://localhost:8161/jolokia/search/<Pattern>").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}
Software

How to Execute an Operation with the Jolokia REST API

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

@WebServlet(name = "SampleJolokiaServlet", value = "/")
public class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Client client = ClientBuilder.newClient();

    Response res = client.target("http://host:8161/jolokia/exec/<MBean Name>/<Operation Name>/<Arg>/<Arg2>/...").request().get();

    resp.getWriter().println(res.readEntity(String.class));

    client.close();
  }

}
Software

How to Write an Attribute with the Jolokia REST API

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

@WebServlet(name = "SampleJolokiaServlet", value = "/")
public class SampleJolokiaServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    Client client = ClientBuilder.newClient();

    client.target("http://host:8161/jolokia/write/<MBean Name>/<Attribute Name>/<Attribute Value>/<Inner Path>").request().get();

    client.close();
  }

}