|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectatg.rest.client.RestComponentHelper
public class RestComponentHelper
A client side helper class which provides useful methods for making calls into the ATG platform using Rest. By default, all methods will return their results in the format that is configured as the default on the server. To override the default, add the "atg-rest-output" parameter to the pParams argument of the appropriate method with a suitable value, "xml", "json", or the identifier for an appropriate output customizer. To begin a session, first call the login() method. Below is a sample application which demonstrates the basic use of this client library. import atg.rest.client.RestClientException; import atg.rest.client.RestComponentHelper; import atg.rest.client.RestResult; import atg.rest.client.RestSession; import java.io.IOException; public class RestClientSample { private String mUsername = null; private String mPassword = null; private String mHost = "localhost"; private int mPort = 80; private RestSession mSession = null; public RestClientSample() {} protected void parseArguments(String[] pArgs) throws Exception { for (int i = 0; i < pArgs.length; i++) { String arg = pArgs[i]; if (arg.equals("-user")) mUsername = pArgs[i+1]; else if (arg.equals("-password")) mPassword = pArgs[i+1]; else if (arg.equals("-host")) mHost = pArgs[i+1]; else if (arg.equals("-port")) mPort = Integer.parseInt(pArgs[i+1]); } if (isBlank(mUsername)) throw new Exception("Must supply username"); if (isBlank(mPassword)) throw new Exception("Must supply password"); } protected boolean isBlank(String pStr) { return (pStr == null || pStr.length() == 0 || pStr.trim().length() == 0); } protected void println(String s) { System.out.println(s); } protected void println(Throwable t) { t.printStackTrace(System.out); } protected void execute() throws RestClientException { mSession = RestSession.createSession(mHost, mPort, mUsername, mPassword); mSession.setUseHttpsForLogin(false); try { mSession.login(); println("Login Successful"); // add REST requests here } catch (Throwable t) { println(t); } finally { try { mSession.logout(); println("Logout Successful"); } catch (RestClientException e) { println(e); } } } public static void main(String[] args) { RestClientSample sample = new RestClientSample(); try { sample.parseArguments(args); sample.execute(); } catch (Throwable t) { sample.println(t); } } }
Field Summary | |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string |
Constructor Summary | |
---|---|
RestComponentHelper()
|
Method Summary | |
---|---|
static RestResult |
executeMethod(java.lang.String pComponentPath,
java.lang.String pMethodName,
java.lang.Object[] pArguments,
java.util.Map<java.lang.String,java.lang.Object> pParams,
RestSession pSession)
Executes the specified method. |
static RestResult |
getComponent(java.lang.String pComponentPath,
java.util.Map<java.lang.String,java.lang.Object> pParams,
RestSession pSession)
Returns a representation of the given component |
static RestResult |
getPropertyValue(java.lang.String pComponentPath,
java.lang.String pProperty,
java.util.Map<java.lang.String,java.lang.Object> pParams,
RestSession pSession)
Returns the value of the requested property or sub-property |
static RestResult |
serviceRequest(java.lang.String pComponentPath,
java.util.Map<java.lang.String,java.lang.Object> pParams,
RestSession pSession)
Services a request (the server redirects the request to a JSP which returns JSON or XML) |
static RestResult |
setPropertyValue(java.lang.String pComponentPath,
java.lang.String pProperty,
java.lang.Object pValue,
java.util.Map<java.lang.String,java.lang.Object> pParams,
RestSession pSession)
Sets the specified property or sub-property on the given component. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String CLASS_VERSION
Constructor Detail |
---|
public RestComponentHelper()
Method Detail |
---|
public static RestResult getComponent(java.lang.String pComponentPath, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession) throws RestClientException
pComponentPath
- the path of the desired componentpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic static RestResult getPropertyValue(java.lang.String pComponentPath, java.lang.String pProperty, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession) throws RestClientException
pComponentPath
- the path of the desired componentpProperty
- the name of the desired property or sub-property formatted as follows: "property/sub-property/sub-property"pParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic static RestResult setPropertyValue(java.lang.String pComponentPath, java.lang.String pProperty, java.lang.Object pValue, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession) throws RestClientException
pComponentPath
- the path of the desired componentpProperty
- the name of the property to setpValue
- the value to setpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic static RestResult executeMethod(java.lang.String pComponentPath, java.lang.String pMethodName, java.lang.Object[] pArguments, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession) throws RestClientException
pComponentPath
- the path of the desired componentpMethodName
- the name of the method to callpArguments
- an array of arguments to be passed to the method or null if there are no argumentspParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the requestpublic static RestResult serviceRequest(java.lang.String pComponentPath, java.util.Map<java.lang.String,java.lang.Object> pParams, RestSession pSession) throws RestClientException
pComponentPath
- the path of the desired componentpParams
- a map of parameters to include in the request or null if no parameters are neededpSession
- the session object representing the current session
RestClientException
- if an error occurs issuing the request
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |