JavaScript HTTP Adapter

Overview

By using HTTP adapters, you can send GET or POST HTTP requests and retrieve data from the response headers and body. HTTP adapters work with RESTful and SOAP-based services, and can read structured HTTP sources such as RSS feeds.

You can easily customize HTTP adapters with simple server-side JavaScript code. For example, you could set up server-side filtering if necessary. The retrieved data can be in XML, HTML, JSON, or plain text format.

The adapter is configured with XML to define the adapter properties and procedures.
Optionally, it is also possible to use XSL to filter received records and fields.

xsi:type: Mandatory. The value of this attribute must be http:HTTPConnectionPolicyType.

cookiePolicy: Optional. This attribute sets how the HTTP adapter handles cookies that arrive from the back-end application. The following values are valid.

BEST_MATCH: default value

BROWSER_COMPATIBILITY

RFC_2109

RFC_2965

NETSCAPE

IGNORE_COOKIES

For more information about these values, see the Apache HTTP components page.

maxRedirects: Optional. The maximum number of redirects that the HTTP adapter can follow. This attribute is useful when the back-end application sends circular redirects as a result of some error, such as authentication failures. If this attribute is set to 0, the adapter does not attempt to follow redirects at all, and the HTTP 302 response is returned to the user. The default value is 10.

protocol: Optional. The URL protocol to use. The following values are valid: http (default), https.

domain: Mandatory. The host address.

port: Optional. The port address. If no port is specified the default HTTP/S port is used (80/443)

sslCertificateAlias: Optional for regular HTTP authentication and simple SSL authentication. Mandatory for mutual SSL authentication. The alias of the adapter private SSL key, which is used by the HTTP adapter key manager to access the correct SSL certificate in the keystore. For more information about the keystore setup process, see Using SSL in HTTP adapters tutorial.

sslCertificatePassword: Optional for regular HTTP authentication and simple SSL authentication. Mandatory for mutual SSL authentication. The password of the adapter private SSL key, which is used by the HTTP adapter key manager to access the correct SSL certificate in the keystore. For more information about the keystore setup process, see Using SSL in HTTP adapters tutorial.

authentication: Optional. Authentication configuration of the HTTP adapter. The HTTP adapter can use one of two authentication protocols. Define the authentication< element, as follows:

Basic authentication

<authentication><basic/></authentication>

Digest authentication

<authentication><digest/></authentication>

The connection policy can contain a serverIdentity element. This feature applies to all authentication schemes. For example:

proxy: Optional. The proxy element specifies the details of the proxy server to use when accessing the back-end application. The proxy details must include the protocol domain and port. If the proxy requires authentication, add a nested authentication element inside proxy. This element has the same structure as the one used to describe the authentication protocol of the adapter. The following example shows a proxy that requires basic authentication and uses a server identity.

maxConcurrentConnectionsPerNode: Optional. Defines the maximum number of concurrent connections, which the MobileFirst Server can open to the back end. Mobile Foundation does not limit the incoming service requests from applications. This limits only the number of concurrent HTTP connections to the back-end service.

The default number of concurrent HTTP connections is 50. You can modify this number based on the expected concurrent requests to the adapter and the maximum requests allowed on the back-end service. You can also configure the back-end service to limit the number of concurrent incoming requests.

Consider a two-node system, where the expected load on the system is 100 concurrent requests and the back-end service can support up to 80 concurrent requests. You can set maxConcurrentConnectionsPerNode to 40. This setting ensures that no more than 80 concurrent requests are made to the back-end service.

If you increase the value, the back-end application needs more memory. To avoid memory issues, do not to set this value too high. Instead, estimate the average and peak number of transactions per second, and evaluate their average duration. Then, calculate the number of required concurrent connections as indicated in this example, and add a 5-10% margin. Then, monitor your back end, and adjust this value as required, to ensure that your back-end application can process all incoming requests.

When you deploy adapters to a cluster, set the value of this attribute to the maximum required load divided by the number of cluster members.

connectionTimeoutInMilliseconds: Optional. The timeout in milliseconds until a connection to the back-end can be established. Setting this timeout does not ensure that a timeout exception occurs after a specific time elapses after the invocation of the HTTP request. If you pass a different value for this parameter in the invokeHTTP() function, you can override the value that is defined here.

socketTimeoutInMilliseconds: Optional. The timeout in milliseconds between two consecutive packets, starting from the connection packet. Setting this timeout does not ensure that a timeout exception occurs after a specific time elapses after the invocation of the HTTP request. If you pass a different value for the socketTimeoutInMilliseconds parameter in the invokeHttp() function, you can override the value that is defined here.

JavaScript implementation

A service URL is used for procedure invocations. Some parts of the URL are constant; for example, http://example.com/.
Other parts of the URL can be parameterized; that is, substituted at run time by parameter values that are provided to the procedure.

The following URL parts can be parameterized.

Path elements

Query string parameters

Fragments

To call an HTTP request, use the MFP.Server.invokeHttp method.
Provide an input parameter object, which must specify:

Creating a SOAP-based service request

You can use the MFP.Server.invokeHttp API method to create a SOAP envelope.
Note: To call a SOAP-based service in a JavaScript HTTP adapter, you can encode the SOAP XML envelope within the request body using E4X.