public class LearnSphereWebServicesClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE
number of bytes to read at a time.
|
Constructor and Description |
---|
LearnSphereWebServicesClient(java.lang.String apiToken,
java.lang.String secret)
Constructor.
|
LearnSphereWebServicesClient(java.lang.String servicesRoot,
java.lang.String apiToken,
java.lang.String secret)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
deleteWorkflow(java.lang.Integer id)
Convenience method for calling the workflow delete web service.
|
java.lang.String |
getApiToken()
Gets the API token.
|
static LearnSphereWebServicesClient |
getDatashopClientForLocalRequests()
Instantiates a LearnSphere client to be used for remote requests to master DataShop servers.
|
static LearnSphereWebServicesClient |
getDatashopClientForRemoteRequests()
Instantiates a LearnSphereWeServiceClient to be used for remote requests to master LearnSphere servers.
|
void |
getFileService(java.lang.String path,
java.lang.String accept,
java.lang.String outputFileLoc) |
java.lang.String |
getHelloWorld()
Hello World is our sanity check, to confirm that web services are up and running.
|
java.lang.String |
getPostService(java.lang.String path,
java.lang.String postData,
java.lang.String accept)
Get the results of calling the specified service as a string.
|
java.lang.String |
getPostServiceWithFileAttachment(java.lang.String path,
java.lang.String postData,
java.io.File fileToAttach,
java.lang.String accept)
Get the results of calling the specified service as a string.
|
java.lang.String |
getRootURL()
Returns the root URL.
|
java.lang.String |
getSecret()
Gets the secret.
|
java.lang.String |
getService(java.lang.String path,
java.lang.String accept)
Get the results of calling the specified service as a string.
|
java.lang.String |
getWorkflow(java.lang.Integer id)
Convenience method for calling the workflow web service.
|
void |
getWorkflowFiles(java.lang.Integer id,
java.lang.String zipFilePath)
Convenience method for calling the workflow_files web service.
|
java.lang.String |
getWorkflows()
Convenience method for calling the workflows web service.
|
static void |
main(java.lang.String[] args)
Run LearnSphereWebServiceClient from the command line.
|
protected void |
print(java.io.InputStream in,
java.io.OutputStream out)
Print the entire contents of in to out.
|
void |
printHelloWorld()
Hello World is our sanity check, to confirm that web services are up and running.
|
void |
printService(java.lang.String path,
java.lang.String accept)
Print the results of calling the specified service to standard out.
|
protected java.lang.String |
printToString(java.io.InputStream is)
Return the entire contents of the input stream as a string.
|
void |
printWorkflow(java.lang.Integer id)
Convenience method for calling the workflow web service.
|
void |
printWorkflows()
Convenience method for calling the workflows web service.
|
java.lang.String |
runWorkflow(java.lang.Integer id)
Convenience method for calling the workflow run web service.
|
java.lang.String |
saveAsNewWorkflow(java.lang.Integer id,
java.lang.String newWorkflowName,
boolean isGlobal,
java.lang.String description)
Convenience method for calling the workflow saveAsNew web service.
|
java.net.HttpURLConnection |
serviceGetConnection(java.lang.String servicePath)
Signed connection to the service specified by path using HTTP GET method.
|
java.net.HttpURLConnection |
servicePostConnection(java.lang.String servicePath)
Signed connection to the service specified by path with HTTP method POST.
|
java.net.HttpURLConnection |
servicePutConnection(java.lang.String servicePath)
Signed connection to the service specified by path with HTTP method PUT.
|
void |
setApiToken(java.lang.String apiToken)
Sets the API token.
|
void |
setRootURL(java.lang.String rootURL)
Sets the root URL.
|
void |
setSecret(java.lang.String secret)
Sets the secret
|
public static final int BUFFER_SIZE
public LearnSphereWebServicesClient(java.lang.String servicesRoot, java.lang.String apiToken, java.lang.String secret)
servicesRoot
- URL prefix for web servicesapiToken
- public API token for authenticationsecret
- secret key for authenticationpublic LearnSphereWebServicesClient(java.lang.String apiToken, java.lang.String secret)
apiToken
- public API token for authenticationsecret
- secret key for authenticationpublic static LearnSphereWebServicesClient getDatashopClientForRemoteRequests()
public static LearnSphereWebServicesClient getDatashopClientForLocalRequests()
public java.lang.String getRootURL()
public void setRootURL(java.lang.String rootURL)
public java.lang.String getApiToken()
public void setApiToken(java.lang.String apiToken)
apiToken
- the API tokenpublic java.lang.String getSecret()
public void setSecret(java.lang.String secret)
secret
- the secretpublic java.net.HttpURLConnection serviceGetConnection(java.lang.String servicePath)
servicePath
- specifies the service to GETpublic java.net.HttpURLConnection servicePutConnection(java.lang.String servicePath)
servicePath
- specifies the service to PUTpublic java.net.HttpURLConnection servicePostConnection(java.lang.String servicePath)
servicePath
- specifies the servicepublic void printService(java.lang.String path, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.accept
- mime type we expect in return, such as text/xml
(should we allow multiple values here?)java.io.IOException
- thrown if there is a communications problempublic java.lang.String getService(java.lang.String path, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.accept
- mime type we expect in return, such as text/xml
(should we allow multiple values here?)java.io.IOException
- thrown if there is a communications problempublic void getFileService(java.lang.String path, java.lang.String accept, java.lang.String outputFileLoc) throws java.io.IOException
java.io.IOException
public java.lang.String getPostService(java.lang.String path, java.lang.String postData, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.postData
- the contentaccept
- mime type we expect in return, such as text/xmljava.io.IOException
- thrown if there is a communications problempublic java.lang.String getPostServiceWithFileAttachment(java.lang.String path, java.lang.String postData, java.io.File fileToAttach, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.postData
- the contentaccept
- mime type we expect in return, such as text/xmljava.io.IOException
- thrown if there is a communications problemprotected void print(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the input streamout
- the output streamjava.io.IOException
- if something goes wrongprotected java.lang.String printToString(java.io.InputStream is) throws java.io.IOException
is
- the input streamjava.io.IOException
- if something goes wrongpublic void printHelloWorld() throws java.lang.Exception
java.lang.Exception
- if something goes wrongpublic java.lang.String getHelloWorld() throws java.lang.Exception
java.lang.Exception
- if something goes wrongpublic void printWorkflow(java.lang.Integer id) throws java.io.IOException
id
- the workflow idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getWorkflow(java.lang.Integer id) throws java.io.IOException
id
- the workflow idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String runWorkflow(java.lang.Integer id) throws java.io.IOException
id
- the workflow idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String deleteWorkflow(java.lang.Integer id) throws java.io.IOException
id
- the workflow idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String saveAsNewWorkflow(java.lang.Integer id, java.lang.String newWorkflowName, boolean isGlobal, java.lang.String description) throws java.io.IOException
id
- the workflow idjava.io.IOException
- thrown if there is a communications problempublic void printWorkflows() throws java.io.IOException
java.io.IOException
- thrown if there is a communications problempublic java.lang.String getWorkflows() throws java.io.IOException
java.io.IOException
- thrown if there is a communications problempublic void getWorkflowFiles(java.lang.Integer id, java.lang.String zipFilePath) throws java.io.IOException
id
- the workflow idjava.io.IOException
- thrown if there is a communications problempublic static void main(java.lang.String[] args)
args
- Arguments are alternating keys and values. Valid keys are
apitoken - the user's public token
secret - the user's secret key
root - the root URL for the web service host
path - the path indicating which web service to call.
file - name of the file to upload to the server
ALTERNATIVE: a single argument is taken to be a complete web services URL to call,
with the credentials provided in learnsphere_webservices.properties.Copyright (c) 2015 - Pittsburgh Science of Learning Center