|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.equilibrium.util.api.MGRequest
public abstract class MGRequest
This class is used to make MediaGenerator requests.
See the MGConnection class for factory methods that
create these requests.
A functioning sample application similar to that presented below is located in the
"sample" folder of the Java API installation.
The following example shows how to request an image generation from MediaRich.
The following MediaScript (sampleScript.ms) is located in the APISampleModule folder. Please see the installation instructions in that folder.
For more information about writing MediaScript see the MediaRich Programmers Guide.
// sampleScript.ms
// Sample media script to scale an image.
function scale()
{
// get the scale amount and the image.
var scaleAmount = parseFloat(req.getParameter("amount"));
var imagePath = req.getFileParamPath(req.getParameter("file"));
var outputType = req.getParameter("type");
// your script should check these parameters....
// scale the image
var m = new Media();
m.load(name @ imagePath);
m.scale(xs @ m.getWidth() * scaleAmount, constrain @ true);
// return it.
m.save(type @ outputType);
}
The following code excerpt invokes the preceding script to scale an image (assumed to exist at C:/myImages/testImage.jpg).
// get a scaled copy of the image at imagePath
MGConnection conn = null;
try
{
conn = new MGConnection();
MGRequest req = conn.createRequest();
req.setScript("sample:/sampleScript.ms");
req.setFunction("scale");
req.setParam("amount", "0.5");
req.setParam("type", "jpeg");
// make a relative path for the path key
String imagePath = "C:/myImages/testImage.jpg"; // assuming this exists
String remotePath = "testImage.jpg"; // must be relative
// add the file to the request using a 64K buffer.
req.addFile("file", imagePath, remotePath, 65536);
// commit the request
MGResponse resp = req.commit();
if (resp.hasContent())
{
// read the content from the resp.
byte[] content = new byte[resp.getContentLength()];
resp.readContent(content);
// do something with the file.
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
try { if (conn != null) conn.close(); } catch(Exception ex) {}
}
// done
| Method Summary | |
|---|---|
void |
addFile(java.lang.String filePath,
java.lang.String remotePath,
int maxBufferSize)
Add the specified file to the request and associate it with the given remotePath. |
void |
addFile(java.lang.String key,
java.lang.String filePath,
java.lang.String remotePath,
int maxBufferSize)
Add the specified file to the request and associate it with the given remotePath. |
void |
addFileParam(java.lang.String fileName,
int len)
Send a file to the MediaGenerator along with the request. |
void |
addStringAsFile(java.lang.String value,
java.lang.String remotePath)
Send the specified string to the MediaGenerator as a file parameter. |
void |
addStringAsFile(java.lang.String key,
java.lang.String value,
java.lang.String remotePath)
Send the specified string to the MediaGenerator as a file parameter. |
MGResponse |
commit()
Commit the request and return the response. |
void |
discard()
Discard the current request. |
void |
sendFileParamData(byte[] data,
int len)
Send the data associated with the file parameter. |
static void |
setClientType(long clientKey,
java.lang.String clientId)
Set the client type for all instances MGRequest. |
void |
setFunction(java.lang.String functionName)
Specify the entry point function within the script. |
void |
setFunction(java.lang.String scriptPath,
java.lang.String functionName)
Specify the entry point function and script.. |
void |
setParam(java.lang.String key,
java.lang.String val)
Set the script parameter for key to the specified value. |
void |
setPriority(int priority)
Set the priority for the request. |
void |
setScript(java.lang.String scriptPath)
Designate the path to the script to execute. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void setClientType(long clientKey,
java.lang.String clientId)
clientKey - the key for this client.clientId - a unique client id.public void setPriority(int priority)
priority - the priority value.
public void setParam(java.lang.String key,
java.lang.String val)
throws java.io.IOException
key - the key for this parameter.val - the value for the parameter.
java.io.IOException
public void setScript(java.lang.String scriptPath)
throws java.io.IOException
scriptPath - the MediaGenerator path to the script to execute.
java.io.IOException
public void setFunction(java.lang.String functionName)
throws java.io.IOException
functionName - the script entry-point function name.
java.io.IOException
public void setFunction(java.lang.String scriptPath,
java.lang.String functionName)
throws java.io.IOException
functionName - the script entry-point function name.
java.io.IOException
public void addFileParam(java.lang.String fileName,
int len)
throws java.io.IOException
This call must be immediately followed by repeated calls to
MGRequest.sendFileParamData(byte[], int) until
fileName - the key name for this file parameter. Must be relative path.len - the size of file.
java.io.IOException
public void sendFileParamData(byte[] data,
int len)
throws java.io.IOException
data - an array containing data for the current file parameter.len - the length of the data to send.
java.io.IOExceptionpublic void discard()
public MGResponse commit()
throws java.io.IOException,
MGException
java.io.IOException
MGException
public void addFile(java.lang.String filePath,
java.lang.String remotePath,
int maxBufferSize)
throws java.io.IOException
filePath - the path to a file on the local system.remotePath - the relative path for the MediaGenerator.maxBufferSize - the buffer size to use to stream the file.
java.io.IOException
public void addFile(java.lang.String key,
java.lang.String filePath,
java.lang.String remotePath,
int maxBufferSize)
throws java.io.IOException
key - the request key to map remote path to.filePath - the path to a file on the local system.remotePath - the relative path for the MediaGenerator.maxBufferSize - the buffer size to use to stream the file.
java.io.IOException
public void addStringAsFile(java.lang.String value,
java.lang.String remotePath)
throws java.io.IOException
value - the file contents.remotePath - the relative path for the MediaGenerator.
java.io.IOException
public void addStringAsFile(java.lang.String key,
java.lang.String value,
java.lang.String remotePath)
throws java.io.IOException
value - the file contents.remotePath - the relative path for the MediaGenerator.
java.io.IOException
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||