Main Content

Configure Client-Server Connection

The MWHttpClientConfig interface in the Java® client API defines the default configuration that an instance of MWHttpClient uses when it establishes a client-server connection. To modify the default configuration, extend the MWHttpClientDefaultConfig class and override its methods.

Default Configuration

The default configuration consists of the following fields. The MWHttpClientDefaultConfig class inherits these fields from the MWHttpClientConfig interface.

Field NameDescriptionDefault Value
DEFAULT_IS_COOKIE_ENABLEDDetermines if the client sets the HTTP cookie.true
DEFAULT_IS_INTERRUPTABLEDetermines if the client can interrupt MATLAB® function execution.false
DEFAULT_RESPONSE_SIZE_LIMITMaximum size, in bytes, of the response that a client accepts.64*1024*1024 (64 MB)
DEFAULT_NUM_CONNECTIONS_PER_ADDRESSMaximum number of connections that the client opens to fulfill multiple requests.-1, specifies that the client can uses as many connections as the system allows.
DEFAULT_TIMEOUT_MSAmount of time, in milliseconds, that the client waits for a server response before timing out.120000

Implement Custom Connection Configurations

To implement a custom client-server connection configuration, extend the MWHttpClientDefaultConfig class, and override its methods to provide an implementation for your custom configuration. The MWHttpClientDefaultConfig class has one getter method corresponding to each configuration field that you can override.

public boolean isCookieEnabled()Returns true if the client sets the HTTP cookie; otherwise, returns false.
public boolean isInterruptible()Returns true if the client can interrupt the execution of a deployed MATLAB function while waiting for a response; otherwise, returns false.
public int getResponseSizeLimit()Returns the maximum number of bytes that the client can accept in a server response.
public int getTimeoutMs()Returns the time in milliseconds that a client waits for a response before generating an error.
public in getMaxConnectionsPerAddress()Returns the maximum number of connections that a client can use to handle simultaneous requests.


If isInterruptible() returns false, then getMaxConnectionsPerAddress() must return -1.

To change one or more client-server connection properties:

  1. Implement a custom connection configuration by extending the MWHttpClientDefaultConfig class.

  2. Create the client-server connection using the MWHttpClient constructor that accepts an instance of MWHttpClientDefaultConfig.

You need to override only the getters for the properties that you want to change. For example, to specify that a client times out after six seconds, can accept 4 MB responses, and does not save HTTP cookies, override getTimeOutMs(), getResponseSizeLimit(), and isCookieEnabled(). The sample code follows.

//Implement custom configuration
class MyClientConfig extends MWHttpClientDefaultConfig
  public long getTimeOutMs()
    return 6000;
  public int getResponseSizeLimit()
    return 4*1024*1024;
  public boolean isCookieEnabled()
    return false;
//Create client-server connection
MWClient client = new MWHttpClient(new MyClientConfig());

To modify the security configuration, provide an object that extends the MWSSLDefaultConfig utility class as an argument to the MWHttpClient constructor.

MWHttpClient(MWHttpClientConfig config, MWSSLConfig sslConfig)
For more information, see Customize Security Configuration.

Related Topics