↓ Skip to main content
An ink and watercolour drawing of a copper pipe on a workbench that splits into three branches, each with a small teal hand valve and a different brass nozzle: round, wide and flat, and star-shaped. A sealed paper envelope lies at the open end of the pipe on the left.

Endpoint Scripts: HTTP, SOAP and JMS Handler Exits

Maximo Automation Scripts - This article is part of a series.
Part 20: This Article
An endpoint is where Manage hands a message to another system. A script can sit there in two ways: as the endpoint’s handler, or as an exit on the HTTP, SOAP or JMS handler. This article covers both, with the method names that work and the error paths as Manage runs them.

We checked IBM’s endpoint pages against the behaviour of Manage in the MAS 9.2 series, and we checked the methods of IBM’s examples on our test system. Where the pages and Manage disagree, this page follows Manage.

An endpoint that is a script
#

IBM’s steps work: add a handler with the class com.ibm.tivoli.maximo.script.ScriptRouterHandler, create an endpoint for it, and set its SCRIPT property to the script name. One detail is missing: write the script name in upper case. The handler looks the name up twice, once upper-cased and once as typed. With IBM’s lower-case example name, the second lookup finds nothing, and the call fails with a NullPointerException.

The script gets the message and the endpoint’s settings as variables:

VariableHolds
requestDatathe message as bytes
requestDataSthe message as text, decoded as UTF-8; None only when there is no data
every endpoint propertyits value, under its own name
metaDataall endpoint properties as one map
responseDataset by the script: text or bytes, returned to the caller

For a publish channel endpoint, the properties include JMS or Kafka headers, and destination is the external system.

IBM’s example sends the message by mail with variables called to, from and subject. In Python, from is a reserved word, so the script does not compile. Name the variable something else:

from psdi.server import MXServer

MXServer.getMXServer().sendEMail(to, sender, subject, requestDataS)

to, sender and subject are literal variables of the script.

Handler exits
#

The HTTP, SOAP and JMS handlers each accept an exit. Set the handler’s exit property to script:<NAME>:

HandlerExit property
HTTPHTTPEXIT
SOAP (JAX-WS)WSEXIT
JMSJMSEXIT

IBM’s pages never name JMSEXIT. An exit works through named functions, so the script needs the Interface flag. Manage does not set it for these names, so set it yourself. Without it, the source runs once from top to bottom, and no function is called. Each function receives a request or response object. The request objects also offer every method of service.

Where the HTTP exit's functions run in one call Where the HTTP exit's functions run in one call
Where the HTTP exit’s functions run in one call

The HTTP exit
#

FunctionWhat the script does there
getUrl(req)changes the target with req.setURL(url)
urlProps(req)adds query parameters with req.addUrlProp(name, value)
headerProps(req)adds headers with req.addHeader(name, value)
formData(req)adds form fields with req.addFormProp(name, value)
processResponse(resp)reads resp.getResponseCode() and resp.getData(), and can call resp.setError(...)

The traps:

  • The method is setURL. IBM writes setUrl, which was missing on our test system.
  • Your parameters and headers replace the configured ones. When urlProps runs, its parameters replace the query parameters from the endpoint, including those an invoke channel passed in. The same holds for headerProps and the configured headers.
  • formData exists. Neither IBM page names this function.
  • processResponse takes over the status check. With this function defined, the handler skips its own check, and a 4xx or 5xx answer counts as success unless the script calls setError.
  • The response body cannot be replaced. The handler returns the original body.
  • An error inside a function is caught and printed. The call goes on.

So a processResponse should always check the status:

from java.lang import Exception as JavaException

def processResponse(resp):
    if resp.getResponseCode() >= 400:
        resp.setError(JavaException("HTTP status " + str(resp.getResponseCode())))

setError takes a java.lang.Exception. IBM’s page writes java.util.Exception, a class that does not exist. The status text comes from resp.geResponseMsg(), with the spelling Manage uses. IBM Docs writes getResponseMsg, which was missing on our test system.

A common use of headerProps is a token. The function fetches it, for example with req.httpgetasjson(...), and sends it with req.addHeader. The IBM Docs copy of that example stops before the addHeader line, so it fetches the token and never sends it.

The SOAP exit
#

FunctionWhat it does
setupHeaders(req)adds SOAP headers with req.addHeader(namespace, name, value)
responseOk(resp)sees the answer; resp.setError(...) turns it into a failure
responseError(resp)sees the fault in resp.getError(); the fault is raised again unless the script calls resp.setError(None)

Three details:

  • The headers that the script adds replace the headers passed in. A second header with the same name replaces the first.
  • req.setURL has no effect. The method exists, and nothing reads its value.
  • The SOAP response headers are available. req.fetchResponseHeaders() asks for them, and resp.getResponseHeaders() returns them. Neither IBM page names the pair.

IBM’s WS-Security example builds its header with org.jdom. Manage 9.2 has org.jdom2, and the helper that turns the element into text takes a JDOM 2 element.

The JMS exit
#

FunctionWhat it does
msgProps(req)sets JMS message properties with req.addProperty(name, value)
responseOk(resp)runs after the commit; its result is ignored
responseError(resp)never runs in the 9.2 series

An error from the JMS provider never reaches the script. The handler raises it again without calling responseError, so resp.getError() is always None. After msgProps, the handler sets its own properties, such as INTERFACE, SENDER and destination, and overwrites script values with the same names. The JMS request has no setURL or getURL, as our test system confirmed.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
The SCRIPT propertya lower-case namemust be upper case, or the call fails
The mail examplea variable froma reserved word; the script does not compile
HTTP setUrlsets the URLmissing; the method is setURL
HTTP error typejava.util.Exceptionjava.lang.Exception
HTTP status textgetResponseMsg (IBM Docs)missing; the method is geResponseMsg
SOAP setURLoverrides the URLhas no effect
JMS responseErrorhandles an errornever called
JMS setURL, getURLexistmissing

Article 33 of this series collects the corrections that matter most.

What comes next
#

Article 21 covers publish channels, event filters, workflow and message-driven bean scripts.

IBM’s own pages are the reference to keep next to this series:

The complete list of corrections, with the evidence for each one, is in our member area. Members get access on request, so get in touch if you want it. If you want help with the scripts in your own Manage, our services page shows how we work.

IBM and Maximo are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.

Maximo Automation Scripts - This article is part of a series.
Part 20: This Article