public String requestPost ( final String id ) throws SDKException { CloseableHttpResponse response = null ; HttpPost httpPost = null ; checkToken ( ) ; try { log . debug ( "pathUrl: " + pathUrl ) ; log . debug ( "id: " + pathUrl + "/" + id ) ; // call the api here log . debug ( "Executing post on: " + this . pathUrl + "/" + id ) ; httpPost = new HttpPost ( this . pathUrl + "/" + id ) ; preparePostHeader ( httpPost , "application/json" , "application/json" ) ; response = httpClient . execute ( httpPost ) ; // check response status RestUtils . checkStatus ( response , HttpURLConnection . HTTP_CREATED ) ; // return the response of the request String result = "" ; if ( response . getEntity ( ) != null ) { result = EntityUtils . toString ( response . getEntity ( ) ) ; } closeResponseObject ( response ) ; log . trace ( "received: " + result ) ; httpPost . releaseConnection ( ) ; return result ; } catch ( IOException e ) { // catch request exceptions here log . error ( e . getMessage ( ) , e ) ; if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } throw new SDKException ( "Could not http-post or open the object properly" , e . getStackTrace ( ) , "Could not http-post or open the object properly because: " + e . getMessage ( ) ) ; } catch ( SDKException e ) { if ( response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_UNAUTHORIZED ) { token = null ; if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } return requestPost ( id ) ; } else { if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } try { throw new SDKException ( "Status is " + response . getStatusLine ( ) . getStatusCode ( ) , new StackTraceElement [ 0 ] , EntityUtils . toString ( response . getEntity ( ) ) ) ; } catch ( IOException e1 ) { e1 . printStackTrace ( ) ; throw new SDKException ( "Status is " + response . getStatusLine ( ) . getStatusCode ( ) , new StackTraceElement [ 0 ] , "could not provide reason because: " + e . getMessage ( ) ) ; } } } }
Does the POST Request