protected String httpPost ( String request , JsonObject body ) throws IOException , RuntimeException { String host = getKieRESTUrl ( ) ; URL url = new URL ( host + "/" + request ) ; Activator . println ( "[POST] " + url . toString ( ) + " body: " + body ) ; HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; conn . setDoOutput ( body != null ) ; conn . setRequestMethod ( "POST" ) ; conn . setRequestProperty ( "Content-Type" , "application/json" ) ; setHttpCredentials ( conn ) ; if ( body != null ) { java . io . OutputStream os = conn . getOutputStream ( ) ; Writer writer = new OutputStreamWriter ( os , "UTF-8" ) ; body . writeTo ( writer ) ; writer . close ( ) ; os . flush ( ) ; } String response = new BufferedReader ( new InputStreamReader ( ( conn . getInputStream ( ) ) ) ) . readLine ( ) ; Activator . println ( "[POST] response: " + response ) ; if ( conn . getResponseCode ( ) != HttpURLConnection . HTTP_ACCEPTED ) { throw new IOException ( "HTTP POST failed : HTTP error code : " + conn . getResponseCode ( ) ) ; } JsonObject jo = JsonObject . readFrom ( response ) ; String status = jo . get ( "status" ) . asString ( ) ; if ( status != null && ! status . isEmpty ( ) ) { if ( ! "APPROVED" . equals ( status ) ) throw new IOException ( "HTTP POST failed : Request status code : " + status ) ; } String jobId = jo . get ( "jobId" ) . asString ( ) ; if ( jobId != null && ! jobId . isEmpty ( ) ) return jobId ; return response ; }
Send an HTTP POST request to the KIE console .