Using Custom Code Service developer can deploy and run their custom code on our servers with out scalability consideration. App42 Custom Code platform is intelligent enought to give the scalibility to your code on the fly. App42 Custom Code platfrom comes with some guideline to write the custom code. Learn How to write Custom Code App42 Custom code can be used to put the validation and custom logic on your data that you want to run on server instead of client sideCustom code can include App42 APIs inside it, and can be used to aggregate two or more services into your own custom code serviceOnce Custom code is deployed, developer can access deployed service using REST or any of supported SDKs. Deployed Custom code service are wrapped in our REST Security model hence as a developer you are free to just focus on business logic Custom Code API available Through REST and in SDKs can be used to run and deploy the custom code
In order to use various functions available in a specific API, a developer has to create an instance of ServiceAPI by passing the apiKey and secretKey which will be created after the app creation from AppHQ dashboard.
Required Parameters
apiKey - The Application key given when the application was created.
secretKey - The secret key corresponding to the application key given when the application was created.
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");Not AvailableServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");Not AvailableServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");Not AvailableNot AvailableNot AvailableComing SoonComing Soon
After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of CustomCodeService, buildCustomCodeService() method needs to be called.
CustomCodeService customCodeService = api.buildCustomCodeService();CustomCodeService customCodeService = api.BuildCustomCodeService();Not AvailableCustomCodeService customCodeService = api.buildCustomCodeService();CustomCodeService customCodeService = api.buildCustomCodeService();CustomCodeService customCodeService = api.BuildCustomCodeService();Not AvailableCustomCodeService customCodeService = api.BuildCustomCodeService();Not AvailableNot AvailableNot AvailableComing SoonComing Soon
import com.shephertz.app42.paas.sdk.android.ServiceAPI; import com.shephertz.app42.paas.sdk.android.App42Response; import com.shephertz.app42.paas.sdk.android.App42Exception; import com.shephertz.app42.paas.sdk.android.App42BadParameterException; import com.shephertz.app42.paas.sdk.android.App42NotFoundException; import com.shephertz.app42.paas.sdk.android.customcode.CustomCodeService;using com.shephertz.app42.paas.sdk.windows; using com.shephertz.app42.paas.sdk.windows.customcode;Not Availableimport com.shephertz.app42.paas.sdk.jme.ServiceAPI; import com.shephertz.app42.paas.sdk.jme.App42Response; import com.shephertz.app42.paas.sdk.jme.App42Exception; import com.shephertz.app42.paas.sdk.jme.App42BadParameterException; import com.shephertz.app42.paas.sdk.jme.App42NotFoundException; import com.shephertz.app42.paas.sdk.jme.customcode.CustomCodeService;import com.shephertz.app42.paas.sdk.java.ServiceAPI; import com.shephertz.app42.paas.sdk.java.App42Response; import com.shephertz.app42.paas.sdk.java.App42Exception; import com.shephertz.app42.paas.sdk.java.App42BadParameterException; import com.shephertz.app42.paas.sdk.java.App42NotFoundException; import com.shephertz.app42.paas.sdk.java.customcode.CustomCodeService;using com.shephertz.app42.paas.sdk.csharp; using com.shephertz.app42.paas.sdk.csharp.customcode;Not Availableusing com.shephertz.app42.paas.sdk.csharp; using com.shephertz.app42.paas.sdk.csharp.customcode;Not AvailableNot AvailableNot AvailableComing SoonComing Soon
Deploys Custom code in App42 Cloud.
Required Parameters
name - Name of Custom Code Service to be deployed.
jarFilePath - Custom code jar file path.
String nameOfCustomCodeService = "CUSTOM NAME"; String jarFilePath = "JAR FILE PATH"; String jsonResponse = customCodeService.deployJarFile(nameOfCustomCodeService, jarFilePath);Coming SoonNot AvailableComing SoonString nameOfCustomCodeService = "CUSTOM NAME"; String jarFilePath = "JAR FILE PATH"; String jsonResponse = customCodeService.deployJarFile(nameOfCustomCodeService, jarFilePath);Coming SoonNot AvailableComing SoonNot AvailableNot AvailableNot AvailableComing SoonComing Soon
Undeploy Java Code deployed in App42 Cloud.
Required Parameters
name - Name of Custom Code Service to be undeployed.
String nameOfCustomCodeService = "CUSTOM NAME"; String jsonResponse = customCodeService.undeployJarFile(nameOfCustomCodeService);Not AvailableNot AvailableNot AvailableString nameOfCustomCodeService = "CUSTOM NAME"; String jsonResponse = customCodeService.undeployJarFile(nameOfCustomCodeService);Not AvailableNot AvailableNot AvailableNot AvailableNot AvailableNot AvailableComing SoonComing Soon
Runs custom code deployed in the App42 Cloud.
Required Parameters
name - Name of deployed CustomCode Service.
jsonBody - Request Body in JSON format.
String name = "CUSTOM NAME"; JSONObject jsonBody = new JSONObject(); jsonBody.put("Company", "Shephertz"); JSONObject response = customCodeService.runJavaCode(name, jsonBody); System.out.println("response is " + response);public class Callback : App42Callback { String name = "CUSTOM NAME"; JObject jsonBody = new JObject(); jsonBody.Add("Company", "Shephertz"); customCodeService.RunJavaCode(name, jsonBody,this); void App42Callback.OnException(App42Exception exception) { Console.WriteLine("Exception Message"); } void App42Callback.OnSuccess(Object response) { JObject json = (JObject) response; String jsonResponse = json.ToString(); } }Not AvailableString name = "CUSTOM NAME"; JSONObject jsonBody = new JSONObject(); jsonBody.put("Company", "Shephertz"); JSONObject response = customCodeService.runJavaCode(name, jsonBody); System.out.println("response is " + response);String name = "CUSTOM NAME"; JSONObject jsonBody = new JSONObject(); jsonBody.put("Company", "Shephertz"); JSONObject response = customCodeService.runJavaCode(name, jsonBody); System.out.println("response is " + response);String name = "CUSTOM NAME"; JObject jsonBody = new JObject(); jsonBody.Add("Company", "Shephertz"); customCodeService.RunJavaCode(name, jsonBody, new UnityCallBack()); public class UnityCallBack : App42CallBack { public void OnSuccess(object response) { JObject objecti = (JObject)response; App42Log.Console("objectName is : " + objecti["name"]); App42Log.Console("Success : " + response); } public void OnException(Exception e) { App42Log.Console("Exception : " + e); } }Not AvailableString name = "CUSTOM NAME"; JObject jsonBody = new JObject(); jsonBody.Add("Company", "Shephertz"); JObject response = customCodeService.RunJavaCode(name, jsonBody); Console.WriteLine("response is " + response);Not AvailableNot AvailableNot AvailableComing SoonComing Soon
The functions available under Custom Code API can throw some exceptions in abnormal conditions. Example of the same has been given below. For example, if you are trying to deploy the custom code with the name that already exist, you will get an appErrorCode as 1902 stating that Invalid JSON in request body.
String name = "CUSTOM NAME"; JSONObject jsonBody = new JSONObject(); jsonBody.put("Company", "Shephertz"); try { customCodeService.runJavaCode(name, jsonBody); } catch (App42Exception ex) { int appErrorCode = ex.getAppErrorCode(); int httpErrorCode = ex.getHttpErrorCode(); if(ex.getAppErrorCode() == 1902) { //Handle here for Bad Request (Invalid JSON in request body.) } else if(ex.getAppErrorCode() == 1900) { //Handle here for Bad Request (Jar File contains the invalid content or class usage that is not allowed for deployment) //Example of it using System class or putting .sh/.dll file inside jar file } else if(ex.getAppErrorCode() == 1401) { // handle here for Client is not authorized } else if(ex.getAppErrorCode() == 1500) { // handle here for Internal Server Error } String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/ }public class Callback : App42Callback { String name = "CUSTOM NAME"; JObject jsonBody = new JObject(); jsonBody.Add("Company", "Shephertz"); customCodeService.RunJavaCode(name, jsonBody, this); void App42Callback.OnException(App42Exception ex) { int appErrorCode = ex.GetAppErrorCode(); int httpErrorCode = ex.GetHttpErrorCode(); if(ex.getAppErrorCode() == 1902) { //Handle here for Bad Request (Invalid JSON in request body.) } else if(ex.getAppErrorCode() == 1900) { //Handle here for Bad Request (Jar File contains the invalid content or class usage that is not allowed for deployment) //Example of it using System class or putting .sh/.dll file inside jar file } else if(ex.getAppErrorCode() == 1401) { // handle here for Client is not authorized } else if(ex.getAppErrorCode() == 1500) { // handle here for Internal Server Error } String jsonText = ex.GetMessage(); } void App42Callback.OnSuccess(Object response) { JObject json = (JObject) response; Console.WriteLine("response is " + json); } }Not AvailableString name = "CUSTOM NAME"; JSONObject jsonBody = new JSONObject(); jsonBody.put("Company", "Shephertz"); try { customCodeService.runJavaCode(name, jsonBody); } catch (App42Exception ex) { int appErrorCode = ex.getAppErrorCode(); int httpErrorCode = ex.getHttpErrorCode(); if(ex.getAppErrorCode() == 1902) { //Handle here for Bad Request (Invalid JSON in request body.) } else if(ex.getAppErrorCode() == 1900) { //Handle here for Bad Request (Jar File contains the invalid content or class usage that is not allowed for deployment) //Example of it using System class or putting .sh/.dll file inside jar file } else if(ex.getAppErrorCode() == 1401) { // handle here for Client is not authorized } else if(ex.getAppErrorCode() == 1500) { // handle here for Internal Server Error } String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/ }String name = "CUSTOM NAME"; JSONObject jsonBody = new JSONObject(); jsonBody.put("Company", "Shephertz"); try { customCodeService.runJavaCode(name, jsonBody); } catch (App42Exception ex) { int appErrorCode = ex.getAppErrorCode(); int httpErrorCode = ex.getHttpErrorCode(); if(ex.getAppErrorCode() == 1902) { //Handle here for Bad Request (Invalid JSON in request body.) } else if(ex.getAppErrorCode() == 1900) { //Handle here for Bad Request (Jar File contains the invalid content or class usage that is not allowed for deployment) //Example of it using System class or putting .sh/.dll file inside jar file } else if(ex.getAppErrorCode() == 1401) { // handle here for Client is not authorized } else if(ex.getAppErrorCode() == 1500) { // handle here for Internal Server Error } String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/ }Not AvailableNot AvailableString name = "CUSTOM NAME"; JObject jsonBody = new JObject(); jsonBody.Add("Company", "Shephertz"); try { customCodeService.runJavaCode(name, jsonBody); } catch (App42Exception ex) { int appErrorCode = ex.GetAppErrorCode(); int httpErrorCode = ex.GetHttpErrorCode(); if(ex.getAppErrorCode() == 1902) { //Handle here for Bad Request (Invalid JSON in request body.) } else if(ex.getAppErrorCode() == 1900) { //Handle here for Bad Request (Jar File contains the invalid content or class usage that is not allowed for deployment) //Example of it using System class or putting .sh/.dll file inside jar file } else if(ex.getAppErrorCode() == 1401) { // handle here for Client is not authorized } else if(ex.getAppErrorCode() == 1500) { // handle here for Internal Server Error } String jsonText = ex.GetMessage(); /* returns the Exception text in JSON format. (as shown below)*/ }Not AvailableNot AvailableNot AvailableComing SoonComing Soon
Functions in Custom API might throw exceptions with following HTTP and Application Error Codes (along with their descriptions):
1400 - BAD REQUEST - The Request parameters are invalid.
1401 - UNAUTHORIZED - Client is not authorized.
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again.
1902 - BAD REQUEST - Invalid JSON in request body.
1903 - BAD REQUEST - Application Exception : Will include exception coming from your deployed code. For example, java.lang.NullPointerException
1904 - BAD REQUEST - Application Exception : Request Execution Time Exceeded