private String _delete ( nitro_service service , String req_args ) throws Exception { StringBuilder responseStr = new StringBuilder ( ) ; HttpURLConnection httpURLConnection = null ; try { String urlstr ; String ipaddress = service . get_ipaddress ( ) ; String version = service . get_version ( ) ; String sessionid = service . get_sessionid ( ) ; String objtype = get_object_type ( ) ; String protocol = service . get_protocol ( ) ; // build URL urlstr = protocol + "://" + ipaddress + "/nitro/" + version + "/config/" + objtype ; String name = this . get_object_id ( ) ; if ( name != null && name . length ( ) > 0 ) { urlstr = urlstr + "/" + nitro_util . encode ( nitro_util . encode ( name ) ) ; } /*if(req_args != null && req_args.length() > 0) { urlstr = urlstr + "?args=" + req_args; }*/ URL url = new URL ( urlstr ) ; httpURLConnection = ( HttpURLConnection ) url . openConnection ( ) ; httpURLConnection . setRequestMethod ( "DELETE" ) ; if ( sessionid != null ) { httpURLConnection . setRequestProperty ( "Cookie" , "SESSID=" + nitro_util . encode ( sessionid ) ) ; httpURLConnection . setRequestProperty ( "Accept-Encoding" , "gzip, deflate" ) ; } if ( httpURLConnection instanceof HttpsURLConnection ) { SSLContext sslContext = SSLContext . getInstance ( "SSL" ) ; //we are using an empty trust manager, because MPS currently presents //a test certificate not issued by any signing authority, so we need to bypass //the credentials check sslContext . init ( null , new TrustManager [ ] { new EmptyTrustManager ( ) } , null ) ; SocketFactory sslSocketFactory = sslContext . getSocketFactory ( ) ; HttpsURLConnection secured = ( HttpsURLConnection ) httpURLConnection ; secured . setSSLSocketFactory ( ( SSLSocketFactory ) sslSocketFactory ) ; secured . setHostnameVerifier ( new EmptyHostnameVerifier ( ) ) ; } InputStream input = httpURLConnection . getInputStream ( ) ; String contentEncoding = httpURLConnection . getContentEncoding ( ) ; // get correct input stream for compressed data: if ( contentEncoding != null ) { if ( contentEncoding . equalsIgnoreCase ( "gzip" ) ) input = new GZIPInputStream ( input ) ; //reads 2 bytes to determine GZIP stream! else if ( contentEncoding . equalsIgnoreCase ( "deflate" ) ) input = new InflaterInputStream ( input ) ; } int numOfTotalBytesRead ; byte [ ] buffer = new byte [ 1024 ] ; while ( ( numOfTotalBytesRead = input . read ( buffer , 0 , buffer . length ) ) != - 1 ) { responseStr . append ( new String ( buffer , 0 , numOfTotalBytesRead ) ) ; } httpURLConnection . disconnect ( ) ; input . close ( ) ; } catch ( MalformedURLException mue ) { System . err . println ( "Invalid URL" ) ; } catch ( IOException ioe ) { System . err . println ( "I/O Error - " + ioe ) ; } catch ( Exception e ) { System . err . println ( "Error - " + e ) ; } return responseStr . toString ( ) ; }
This method forms the http DELETE request applies on the MPS . Reads the response from the MPS and converts it to base response .