Post navigation

Writing Custom Code — Your Code, Our Cloud

App42 platform has various technical and business services using which app development can be done without writing a single line of backend code. However there might be a case where the app developer might need to have some server side custom code for their app. There could be multiple scenarios for example-

You want to add server side validation and or custom logic on the input data instead of on the client.

You want to make a custom service by aggregating two or more App42 services. For example aggregating Push and Storage service for custom requirement.

App logic that might get changed in future and hence you don’t want to bundle it in your app. Instead you would like to put it on the server where it can be accessed through REST calls from your app.

App42 platform now gives you the power to host your custom server side code in our cloud. Below are the listed features and advantages for the same.

You don’t have to pay for an entire VM/Instance for hosting, you have to just pay based on your usage which will include the number of API calls made to your custom code.

You don’t need to worry about scalability and high availability issues with your custom code, App42 Custom Code platform is intelligent enough to give scalibility to your code on the fly.

Deployed Custom code services are wrapped in our REST Security model, hence as a developer you are free to just focus on the business logic keeping aside any security concerns.

App42 Custom code can be written using powerful and scalable JAVA language.

In the above example, if you want to rename or change the package and class name, you are free to do so.

Above example uses App42 Logging Service to do the logging inside your custom code. These logs would be available to you inside AppHQ console.

Custom Code deployed in our cloud runs inside a sand-boxed environment for each service. There are restrictions on using certain JAVA APIs like System, FileIO, Reflection, ByteCode injection etc. If you have any requirement where you are looking to use these restricted APIs or any other third party Jar file, please write to us at support@shephertz.com for further help.

Deploying Custom Code

Once you have written your custom code, you can deploy it either through ant command line or using our APIs.

To deploy your custom code through Ant script, run < ant deploy > from a command line inside your root folder of the sample project that you downloaded from above. Before running this command, modify build.properties to enter your APIKey and SecretKey for the same.

Once you run the above command, you will be asked to enter the name for the custom code to be deployed on App42 Cloud. It’s default name is MyCustomCode. If you get BUILD SUCCESSFUL message after entering the name, your App is deployed on App42 Cloud. Otherwise you will get an appropriate exception message.

To deploy your custom code through API, you have to call deployJarFile method on CustomCodeService API by passing the name and the jar file’s location. In this case you have to first create the Jar file of your custom code using the JDK Jar utility and then call the API by passing the jar file’s location and name of the service to be deployed.

Running Custom Code

Once your custom code service is deployed, it can be accessed either through REST calls using url https://customcode.shephertz.com/1.0/run/java/ or from native App42 SDKs available in different languages.