public class MWHttpClient extends java.lang.Object implements MWClient
MWHttpClient
allows Java clients to invoke MATLAB functions
exported by a CTF file hosted by the server. The CTF is specified by a URL.
A server can host multiple CTF's and each CTF has a unique URL.
To establish client-server communication, following information is required:
http://server_name:port_number/CTF_name_without_extension
com.mathworks.mps.client.MATLABException
: Represents MATLAB errorsjava.io.IOException
: Represents any transport errors during client-server communicationMWHttpClient
can be configured by providing an object that extends the
MWHttpClientDefaultConfig
utility class to change its properties.
MWHttpClientDefaultConfig
has the following properties:
Interruptible
: Determines if the MATLAB function call can be interupted while waiting for a response.
The default is false
.TimeOutMs
: Specifies the time in mS that the client waits for the response from the server. The
default is 120000 mS.MaxConnectionsPerAddress
: Specifies the maximum number of connections per address used by
MWHttpClient
to fulfill multiple simultaneous requests created by client. The default is -1.ResponseSizeLimit
: Specifies the maximum size, in bytes, of the response the client will accept.
The default is 64*1024*1024.MWHttpClient
security configuration can be modified by providing an object that extends the
MWSSLDefaultConfig
utility class to change its properties.
Here's a quick example that demonstrates the use of MWHttpClient
class when both client and
server are hosted on the same machine.
Let's consider a simple MATLAB function mymagic
that returns a magic square:
function m = mymagic(in) m = magic(in);
mymagic
takes an int as input and returns a 2-D double arrayLet's assume that MATLAB function mymagic
magiccomponent.ctf
and this
CTF is hosted by the server at URL: http://localhost:8990/magiccomponent
The Java interface Magic
shown below represents magiccomponent.ctf
on the client side:
interface Magic { double[][] mymagic(int in1) throws IOException, MATLABException; }
This is how MWHttpClient
uses the Magic
interface and the URL to invoke mymagic
MATLAB function:
import com.mathworks.mps.client.MWClient; import com.mathworks.mps.client.MWHttpClient; import com.mathworks.mps.client.MATLABException; import java.net.URL; public class ClientExample { public static void main(String[] args){ MWClient client = new MWHttpClient(); try{ Magic m = client.createProxy(new URL("http://localhost:8990/magiccomponent"), Magic.class ); double[][] result = m.mymagic(5); }catch(IOException ex){ ex.printStackTrace(); }catch(MATLABException ex){ ex.printMATLABStackTrace(); }finally{ client.close(); } } }
Constructor and Description |
---|
MWHttpClient()
Create an
MWHttpClient instance with an instance of MWHttpClientDefaultConfig to configure
the client-server connection and an instance of MWSSLDefaultConfig to configure secure socket connection
over HTTPS . |
MWHttpClient(MWHttpClientConfig config)
Create an
MWHttpClient instance with a user provided configuration. |
MWHttpClient(MWHttpClientConfig config,
MWSSLConfig sslConfig)
Create an
MWHttpClient instance with user provided configurations for both the client-server
connection and the SSL layer. |
MWHttpClient(MWSSLConfig sslConfig)
Create an
MWHttpClient instance with a user user provided configuration for the secure socket
communication. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the client-server communication.
|
MWInvokable |
createComponentProxy(java.net.URL url)
Creates a reflection-based proxy object reference to a deployable archive hosted by MATLAB Production Server.
|
MWInvokable |
createComponentProxy(java.net.URL url,
MWMarshalingRules marshalingRules)
Creates a reflection-based proxy object reference to a deployable archive hosted by MATLAB Production Server.
|
<T> T |
createProxy(java.net.URL url,
java.lang.Class<T> mwComponent)
Creates an interface-based proxy object reference to a deployable archive hosted by the server.
|
MWHttpClientConfig |
getConfig()
Returns a reference to the connection configuration associated with this instance of
MWHttpClient . |
MWSSLConfig |
getSSLConfig()
Returns a reference to the SSL configuration associated with this instance of
MWHttpClient . |
public MWHttpClient()
MWHttpClient
instance with an instance of MWHttpClientDefaultConfig
to configure
the client-server connection and an instance of MWSSLDefaultConfig
to configure secure socket connection
over HTTPS
.public MWHttpClient(MWHttpClientConfig config)
MWHttpClient
instance with a user provided configuration.
It uses an instance of MWSSLDefaultConfig
to configure secure socket connection.config
- user extended instance of MWHttpClientDefaultConfig
MWHttpClientDefaultConfig
public MWHttpClient(MWSSLConfig sslConfig)
MWHttpClient
instance with a user user provided configuration for the secure socket
communication. It uses an instance of MWHttpClientDefaultConfig
to configure
the client-server connection.sslConfig
- user extended instance of MWSSLDefaultConfig
MWSSLDefaultConfig
public MWHttpClient(MWHttpClientConfig config, MWSSLConfig sslConfig)
MWHttpClient
instance with user provided configurations for both the client-server
connection and the SSL layer.config
- user extended instance of MWHttpClientDefaultConfig
sslConfig
- user extended instance of MWSSLDefaultConfig
MWClientDefaultConfig
,
MWSSLDefaultConfig
public MWHttpClientConfig getConfig()
MWHttpClient
.MWHttpClientConfig
instance associated with this instance of MWHttpClient
public MWSSLConfig getSSLConfig()
MWHttpClient
.MWSSLConfig
instance associated with this instance of MWHttpClient
public <T> T createProxy(java.net.URL url, java.lang.Class<T> mwComponent)
mwComponent
. The proxy object has public methods of the interface defined by
mwComponent
. This interface has methods with names of MATLAB functions in the deployable
archive and with inputs and outputs consistent with MATLAB functions in terms of types and numbers.
When a method is invoked, the proxy object establishes a client-server connection over HTTP. The HTTP
request carries the inputs for the MATLAB function and the response carries the MATLAB result.createProxy
in interface MWClient
T
- The type of the returned objecturl
- url to the deployable archive with the form: http://:/
mwComponent
- Reference to interface modeled after the deployable archive pointed by the URLpublic MWInvokable createComponentProxy(java.net.URL url, MWMarshalingRules marshalingRules)
invoke method to call
MATLAB functions contained in the specified deployable archive.
createComponentProxy
in interface MWClient
url
- url to the deployable archive with the form: http://:/
marshalingRules
- List of java classes, used as input or output argument to the MATLAB function, that represent a MATALB structMWInvocable
interface that provides methods to invoke MATLAB functions directlypublic MWInvokable createComponentProxy(java.net.URL url)
invoke
method to call
MATLAB functions contained in the specified deployable archive.createComponentProxy
in interface MWClient
url
- url to the deployable archive with the form: http://:/
MWInvocable
interface that provides methods to invoke MATLAB functions directlypublic void close()
MWHttpClient
cannot be
restarted. It should not be used to create new deployable archive references and the existing
deployable archive references created using this instance of MWHttpClient
are unusable.Copyright 2010-2013 The MathWorks, Inc.