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

Initialize

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.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");
Not Available
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");
Not Available
ServiceAPI api = new ServiceAPI("API_KEY","SECRET_KEY");
Not Available
Not Available
Not Available
Coming Soon 
Coming Soon

Build Service

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.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
CustomCodeService customCodeService = api.buildCustomCodeService(); 
CustomCodeService customCodeService = api.BuildCustomCodeService();  
Not Available
CustomCodeService customCodeService = api.buildCustomCodeService(); 
CustomCodeService customCodeService = api.buildCustomCodeService(); 
CustomCodeService customCodeService = api.BuildCustomCodeService(); 
Not Available
CustomCodeService customCodeService = api.BuildCustomCodeService(); 
Not Available
Not Available
Not Available
Coming Soon 
Coming Soon

Import Statement

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
 
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 Available
import 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 Available
using com.shephertz.app42.paas.sdk.csharp;  
using com.shephertz.app42.paas.sdk.csharp.customcode;  
Not Available
Not Available
Not Available
Coming Soon 
Coming Soon

Deploy Jar File

Deploys Custom code in App42 Cloud.

Required Parameters

name - Name of Custom Code Service to be deployed. jarFilePath - Custom code jar file path.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
String nameOfCustomCodeService = "CUSTOM NAME";
String jarFilePath = "JAR FILE PATH";
String jsonResponse = customCodeService.deployJarFile(nameOfCustomCodeService, jarFilePath);
Coming Soon
Not Available
Coming Soon
String nameOfCustomCodeService = "CUSTOM NAME";
String jarFilePath = "JAR FILE PATH";
String jsonResponse = customCodeService.deployJarFile(nameOfCustomCodeService, jarFilePath);
Coming Soon
Not Available
Coming Soon
Not Available
Not Available
Not Available
Coming Soon 
Coming Soon

Undeploy Jar File

Undeploy Java Code deployed in App42 Cloud.

Required Parameters

name - Name of Custom Code Service to be undeployed.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
String nameOfCustomCodeService = "CUSTOM NAME";
String jsonResponse = customCodeService.undeployJarFile(nameOfCustomCodeService);
Not Available
Not Available
Not Available
String nameOfCustomCodeService = "CUSTOM NAME";
String jsonResponse = customCodeService.undeployJarFile(nameOfCustomCodeService);
Not Available 
Not Available
Not Available
Not Available
Not Available
Not Available
Coming Soon 
Coming Soon

Run Java Code

Runs custom code deployed in the App42 Cloud.

Required Parameters

name - Name of deployed CustomCode Service. jsonBody - Request Body in JSON format.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
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 Available
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";
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 Available
String name = "CUSTOM NAME";
JObject jsonBody = new JObject();
jsonBody.Add("Company", "Shephertz");
JObject response = customCodeService.RunJavaCode(name, jsonBody);
Console.WriteLine("response is " + response);	
Not Available
Not Available
Not Available
Coming Soon 
Coming Soon

Exception Handling

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.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for J2ME
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
 
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 Available                       
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)*/ 
}	
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 Available 
Not Available
  
String 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 Available
Not Available
Not Available
Coming Soon 
Coming Soon

Error Codes

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