static void apply ( HttpCall . Factory callFactory , String name , String indexTemplate ) throws IOException { HttpUrl templateUrl = callFactory . baseUrl . newBuilder ( "_template" ) . addPathSegment ( name ) . build ( ) ; Request getTemplate = new Request . Builder ( ) . url ( templateUrl ) . tag ( "get-template" ) . build ( ) ; try { callFactory . newCall ( getTemplate , BodyConverters . NULL ) . execute ( ) ; } catch ( IllegalStateException e ) { // TODO: handle 404 slightly more nicely Request updateTemplate = new Request . Builder ( ) . url ( templateUrl ) . put ( RequestBody . create ( ElasticsearchStorage . APPLICATION_JSON , indexTemplate ) ) . tag ( "update-template" ) . build ( ) ; callFactory . newCall ( updateTemplate , BodyConverters . NULL ) . execute ( ) ; } }
This is a blocking call used inside a lazy . That s because no writes should occur until the template is available .