protected < T > T getResource ( String path , Class < T > objectClass ) throws SmartsheetException { Util . throwIfNull ( path , objectClass ) ; if ( path . isEmpty ( ) ) { com . smartsheet . api . models . Error error = new com . smartsheet . api . models . Error ( ) ; error . setMessage ( "An empty path was provided." ) ; throw new ResourceNotFoundException ( error ) ; } HttpRequest request = createHttpRequest ( smartsheet . getBaseURI ( ) . resolve ( path ) , HttpMethod . GET ) ; T obj = null ; String content = null ; try { HttpResponse response = this . smartsheet . getHttpClient ( ) . request ( request ) ; InputStream inputStream = response . getEntity ( ) . getContent ( ) ; switch ( response . getStatusCode ( ) ) { case 200 : try { if ( log . isInfoEnabled ( ) ) { ByteArrayOutputStream contentCopyStream = new ByteArrayOutputStream ( ) ; inputStream = StreamUtil . cloneContent ( inputStream , response . getEntity ( ) . getContentLength ( ) , contentCopyStream ) ; content = StreamUtil . toUtf8StringOrHex ( contentCopyStream , getResponseLogLength ( ) ) ; } obj = this . smartsheet . getJsonSerializer ( ) . deserialize ( objectClass , inputStream ) ; } catch ( JsonParseException e ) { log . info ( "failure parsing '{}'" , content , e ) ; throw new SmartsheetException ( e ) ; } catch ( JsonMappingException e ) { log . info ( "failure mapping '{}'" , content , e ) ; throw new SmartsheetException ( e ) ; } catch ( IOException e ) { log . info ( "failure loading '{}'" , content , e ) ; throw new SmartsheetException ( e ) ; } break ; default : handleError ( response ) ; } } catch ( JSONSerializerException jsx ) { log . info ( "failed to parse '{}'" , content , jsx ) ; throw jsx ; } finally { smartsheet . getHttpClient ( ) . releaseConnection ( ) ; } return obj ; }
Get a resource from Smartsheet REST API .