Java Client Programming

Create client programs in Java®

The MATLAB® Production Server™ Java client API allows you to evaluate MATLAB functions deployed on remote servers using native Java data. The Java client API offers two workflows for client-server communication.

One workflow hides the implementation details of request creation and data serialization when evaluating MATLAB functions deployed on servers. This workflow uses the MWHttpClient class and provides the following two options to evaluate a deployed MATLAB function.

  • Static proxy — You provide an interface that models the MATLAB function signature. This is a type-safe API that enforces passing the proper data types to the function at compile time.

  • Dynamic proxy — You pass the function name as a parameter to the proxy along with the function arguments. This defers type checking until runtime.

The other workflow uses the MATLAB Production Server RESTful API for MATLAB function execution for request creation and protocol buffers (protobuf) for data serialization. Protocol buffers are a language-neutral and platform-neutral method of serializing structured data.

To use protobuf when making a request to the server, set the HTTP Content-Type header to application/x-google-protobuf in the client code. The Java client library provides helper classes to internally create protobuf messages based on a proto format and returns the corresponding byte array. Use this byte array in the HTTP request body. The Java client library provides methods and classes to deserialize the protobuf responses.

In an on-premises MATLAB Production Server installation, the client APIs are located in $MPS_INSTALL/client, where $MPS_INSTALL is the MATLAB Production Server installation location. The client APIs are also available at MATLAB Production Server Client Libraries.

Topics

Programming Using Static and Dynamic Proxy

Create a Java MATLAB Production Server Client Using the MWHttpClient Class

Learn how to create a MATLAB Production Server client in Java.

Create a Java Client Using the MWHttpClient Class

Learn how to call a MATLAB function deployed to MATLAB Production Server from a Java application.

Configure the Client-Server Connection

You configure the client-server connection using an object that implements the MWHttpClientConfig interface.

Invoke MATLAB Functions Dynamically

Invoke MATLAB functions using a function name and argument list.

Bond Pricing Tool for Java Client

This example shows an application that calculates a bond price from a simple formula.

Java Client Logging

How to use logging capability in the Java client for debugging.

Java Client Coding Best Practices

When you write Java interfaces to invoke MATLAB code, remember these considerations:

Programming Using RESTful API and Protocol Buffers for Data Serialization

Asynchronous RESTful Requests Using Protocol Buffers in the Java Client

Example that shows how to make asynchronous RESTful requests using protocol buffers in the Java client.

Synchronous RESTful Requests Using Protocol Buffers in the Java Client

Example that shows how to make synchronous RESTful requests using protocol buffers in the Java client.

Struct Support for RESTful Requests Using Protocol Buffers in the Java Client

Example that shows the support for structs as input for RESTful requests using protocol buffers in the Java client.

Inputs and Outputs

Code Multiple Outputs for Java Client

MATLAB allows users to write functions that return multiple outputs.

Code Variable-Length Inputs and Outputs for Java Client

MATLAB supports functions with both variable number of input arguments (varargin) and variable number of output arguments (varargout).

Security

Access Secure Programs Using HTTPS

Connect to a MATLAB Production Server instance over HTTPS.

Customize Security Configuration

Configure HTTPS settings using MWSSLConfig.

Data Types and Data Conversion

Marshal MATLAB Structures (Structs) in Java

Structures (or structs) are MATLAB arrays with elements accessed by textual field designators.

Data Conversion with Java and MATLAB Types

There are many data types that you can work with in MATLAB.

Conversion of Java Types to MATLAB Types

Rules for data conversion from Java to MATLAB types

Conversion of MATLAB Types to Java Types

Unsupported MATLAB Data Types for Client and Server Marshaling

List of supported and unsupported MATLAB data types.