Skip to content

Instantly share code, notes, and snippets.

View Ikhiloya's full-sized avatar

Ikhiloya Ikhiloya

View GitHub Profile
@Ikhiloya
Ikhiloya / How to Deploy a Spring Boot App with Docker to DigitalOcean App Platform.md
Last active January 19, 2024 23:23
This article provides developers with instructions on how to deploy a Java Spring Boot application to the DigitalOcean App Platform using Docker

How to Deploy a Spring Boot App with Docker to DigitalOcean App Platform

Digital Ocean App Platform Logo

Introduction

DigitalOcean App platform is a Platform-as-a-service (Paas) that allows developers to publish code directly to DigialOcean servers without worrying about the underlying infrastructure. The Platform supports two ways to build an image for your app: Cloud Native Buildpacks and Dockerfiles.

When an app is deployed to the App Platform either via GitHub or DockerHub, it defaults to using Dockerfile if one is present in the root directory or specified app spec. Otherwise, the App Platform checks your code to determine what language or framework it uses. If it supports the language or framework, it chooses an appropriate resource type and uses the proper buildpack to build the app and deploy a container.

Java/Spring boot is no

//Java
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("<your html file>"); //not in scope of this gist
webview.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url){
//Here you want to use .loadUrl again
//on the webview object and pass in
//"javascript:<your javaScript function"
webview.loadUrl("javascript:myJavaScriptFunc('" + argumentPassingIn + "')"); //if passing in an object. Mapping may need to take place
}
private fun cache(): Cache? {
val cacheSize = 5 * 1024 * 1024.toLong()
return Cache(instance!!.applicationContext.cacheDir, cacheSize)
}
@Ikhiloya
Ikhiloya / OfflineCacheInterceptorWithHeader.kt
Created October 28, 2020 07:13
An offline interceptor to cache requests when there is no network connection. It checks if a specific header is present before caching.
open class OfflineCacheInterceptorWithHeader : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
val header = request.headers["Cacheable"]
if (header != null) {
/* check if this request has the [Cacheable] header */
if (header == "true" &&
!PaymentApp.instance!!.isNetworkConnected()
@Test(expected = NotFoundException::class)
@Throws(Exception::class)
fun testIfCustomAnnotationIsPresent() {
val httpLoggingInterceptor = HttpLoggingInterceptor(
HttpLoggingInterceptor.Logger { message: String? -> Timber.i(message) }
)
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
val networkInterceptor = NetworkInterceptor()
@Ikhiloya
Ikhiloya / WebServiceCallWithHeader.kt
Created October 28, 2020 07:07
A simple web service call with a custom header to ensure that the request is retrieved from the cached
@GET(Constant.PAYMENT_TYPES)
@Headers("Cacheable: true")
fun getPaymentTypesWithHeaders(): Call<MutableList<PaymentType>>
@Ikhiloya
Ikhiloya / WebServiceCallWithAnnotation.kt
Created October 28, 2020 07:02
A simple web service call annotated with a custom annotation to ensure that the request is retrieved cached
@Cacheable
@GET(Constant.PAYMENT_TYPES)
fun getPaymentTypes(): Call<MutableList<PaymentType>>
@Ikhiloya
Ikhiloya / RetrofitInstance.kt
Created October 28, 2020 06:58
Retrofit Instance for network calls in android
//OkHttpClient
val okHttpClient: OkHttpClient = OkHttpClient().newBuilder()
.cache(cache())
.addInterceptor(httpLoggingInterceptor)
.addNetworkInterceptor(networkInterceptor) // only used when network is on
.addInterceptor(offlineCacheInterceptor)
.build()
@Ikhiloya
Ikhiloya / OfflineCacheInterceptor.kt
Last active October 28, 2020 07:13
An offline interceptor to cache requests when there is no network connection. It checks if a specific annotation is present before caching.
open class OfflineCacheInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
val invocation: Invocation? = request.tag(Invocation::class.java)
if (invocation != null) {
val annotation: Cacheable? =
invocation.method().getAnnotation(Cacheable::class.java)
@Ikhiloya
Ikhiloya / AnnotationCheck.kt
Created October 28, 2020 06:53
check if this request has the Cacheable annotation
if (annotation != null &&
annotation.annotationClass.simpleName.equals("Cacheable") &&
!PaymentApp.instance!!.isNetworkConnected()) {
// prevent caching when network is on. For that we use the "networkInterceptor"
Timber.d("cache interceptor: called.")
val cacheControl = CacheControl.Builder()
.maxStale(7, TimeUnit.DAYS)
.build()