idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
10,400 | protected static char [ ] flags ( final CharSequence ... flagStrings ) { final StringBuilder sb = new StringBuilder ( ) ; for ( CharSequence flags : flagStrings ) sb . append ( flags ) ; return flags ( sb . toString ( ) ) ; } | Converts strings of flags into a sorted flag array that can be passed as a parameter to other utility methods . |
10,401 | protected static char [ ] flags ( final String flagString ) { if ( flagString == null || flagString . isEmpty ( ) ) { return NO_FLAGS ; } noDupsExcept ( flagString , NO_FLAGS ) ; final char [ ] flags = flagString . toCharArray ( ) ; Arrays . sort ( flags ) ; return flags ; } | Converts a string of flags into a sorted flag array that can be passed as a parameter to other utility methods . |
10,402 | protected void ensureNoFlags ( final String flags ) { if ( flags == null || flags . isEmpty ( ) ) return ; throw FormatException . formatFlagsMismatch ( flags , getFormatName ( ) ) ; } | Ensures no flags are given . |
10,403 | protected char selectFlag ( final String flags , final char [ ] choice ) { if ( flags == null ) return 0 ; StringBuilder conflict = null ; char found = 0 ; for ( int i = 0 ; i < flags . length ( ) ; i ++ ) { char f = flags . charAt ( i ) ; if ( oneOf ( f , choice ) ) { if ( found != 0 ) { if ( conflict == null ) conflict = new StringBuilder ( ) . append ( found ) ; conflict . append ( f ) ; } else { found = f ; } } } if ( conflict != null ) { throw FormatException . illegalFlags ( conflict . toString ( ) , getFormatName ( ) ) ; } return found ; } | Selects exactly one of the expected flags . |
10,404 | private void proxy ( final SipResponse msg ) { final ViaHeader via = msg . getViaHeader ( ) ; final Connection connection = this . stack . connect ( via . getHost ( ) , via . getPort ( ) ) ; connection . send ( msg ) ; } | Proxy the response to |
10,405 | private SipResponse processRegisterRequest ( final SipRequest request ) { final SipURI requestURI = ( SipURI ) request . getRequestUri ( ) ; final Buffer domain = requestURI . getHost ( ) ; final SipURI aor = getAOR ( request ) ; if ( ! validateDomain ( domain , aor ) ) { return request . createResponse ( 404 ) ; } final Binding . Builder builder = Binding . with ( ) ; builder . aor ( aor ) ; builder . callId ( request . getCallIDHeader ( ) ) ; builder . expires ( getExpires ( request ) ) ; builder . cseq ( request . getCSeqHeader ( ) ) ; builder . contact ( getContactURI ( request ) ) ; final Binding binding = builder . build ( ) ; final List < Binding > currentBindings = this . locationService . updateBindings ( binding ) ; final SipResponse response = request . createResponse ( 200 ) ; currentBindings . forEach ( b -> { final SipURI contactURI = b . getContact ( ) ; contactURI . setParameter ( "expires" , b . getExpires ( ) ) ; final ContactHeader contact = ContactHeader . with ( contactURI ) . build ( ) ; response . addHeader ( contact ) ; } ) ; return response ; } | Section 10 . 3 in RFC3261 outlines how to process a register request . For the purpose of this little exercise we are skipping many steps just to keep things simple . |
10,406 | private SipRequest generateAck ( final SipResponse response ) { final ContactHeader contact = response . getContactHeader ( ) ; final SipURI requestURI = ( SipURI ) contact . getAddress ( ) . getURI ( ) ; final ToHeader to = response . getToHeader ( ) ; final FromHeader from = response . getFromHeader ( ) ; final CSeqHeader cseq = CSeqHeader . with ( ) . cseq ( response . getCSeqHeader ( ) . getSeqNumber ( ) ) . method ( "ACK" ) . build ( ) ; final CallIdHeader callId = response . getCallIDHeader ( ) ; final ViaHeader via = response . getViaHeader ( ) . clone ( ) ; via . setBranch ( ViaHeader . generateBranch ( ) ) ; final SipRequest . Builder builder = SipRequest . ack ( requestURI ) ; builder . from ( from ) ; builder . to ( to ) ; builder . callId ( callId ) ; builder . cseq ( cseq ) ; builder . via ( via ) ; return builder . build ( ) ; } | Generating an ACK to a 2xx response is the same as any other subsequent request . However a subsequent request is generated in the context of what is known as a Dialog and since we currently are completely stateless this is not necessarily an easy thing to achieve but for now we will ignore many of the details . |
10,407 | public static ASN1OctetString getInstance ( Object obj ) { if ( obj == null || obj instanceof ASN1OctetString ) { return ( ASN1OctetString ) obj ; } if ( obj instanceof ASN1TaggedObject ) { return getInstance ( ( ( ASN1TaggedObject ) obj ) . getObject ( ) ) ; } if ( obj instanceof ASN1Sequence ) { Vector v = new Vector ( ) ; Enumeration e = ( ( ASN1Sequence ) obj ) . getObjects ( ) ; while ( e . hasMoreElements ( ) ) { v . addElement ( e . nextElement ( ) ) ; } return new BERConstructedOctetString ( v ) ; } throw new IllegalArgumentException ( "illegal object in getInstance: " + obj . getClass ( ) . getName ( ) ) ; } | return an Octet String from the given object . |
10,408 | public static Logger get ( Class < ? > cls , String resourceBundleName ) { return Logger . getLogger ( cls . getPackage ( ) . getName ( ) , resourceBundleName ) ; } | Get a logger for the class s package that uses the resource bundle for localisation . |
10,409 | @ SuppressWarnings ( "unchecked" ) public static < T > T lookup ( String name ) { try { return ( T ) new InitialContext ( ) . lookup ( name ) ; } catch ( NamingException e ) { throw new IllegalStateException ( e ) ; } } | Get the named object in the starting context . |
10,410 | public SmbTransport getDc ( String domain , SmbExtendedAuthenticator authenticator , NtlmPasswordAuthentication auth ) throws SmbAuthException { if ( DISABLED ) return null ; try { UniAddress addr = UniAddress . getByName ( domain , true ) ; SmbTransport trans = SmbTransport . getSmbTransport ( addr , 0 ) ; DfsReferral dr = trans . getDfsReferrals ( authenticator , auth , "\\" + domain , 1 ) ; if ( dr != null ) { DfsReferral start = dr ; IOException e = null ; do { try { addr = UniAddress . getByName ( dr . server ) ; return SmbTransport . getSmbTransport ( addr , 0 ) ; } catch ( IOException ioe ) { e = ioe ; } dr = dr . next ; } while ( dr != start ) ; throw e ; } } catch ( IOException ioe ) { if ( log . level >= 3 ) ioe . printStackTrace ( log ) ; if ( strictView && ioe instanceof SmbAuthException ) { throw ( SmbAuthException ) ioe ; } } return null ; } | >> SmbAuthenticator Fixed trusted domain issue . |
10,411 | public static boolean addAll ( LongCollection collection , long [ ] array ) { boolean changed = false ; for ( long element : array ) { changed |= collection . add ( element ) ; } return changed ; } | Add all elements in the array to the collection . |
10,412 | public static < T > T get ( T [ ] array , int index ) { return array != null && index >= 0 && index < array . length ? array [ index ] : null ; } | Get the element at the index in the array . |
10,413 | public static < T > T [ ] slice ( T [ ] array , int ... indexes ) { int length = indexes . length ; T [ ] slice = ObjectArrays . newArray ( array , length ) ; for ( int i = 0 ; i < length ; i ++ ) { slice [ i ] = array [ indexes [ i ] ] ; } return slice ; } | Get the elements in the array that are at the indexes . |
10,414 | public static < T > List < T > slice ( List < T > list , int ... indexes ) { List < T > slice = new ArrayList < > ( indexes . length ) ; for ( int i : indexes ) { slice . add ( list . get ( i ) ) ; } return slice ; } | Get the elements in the list that are at the indexes . |
10,415 | public static Class < ? > getClass ( Object obj ) { Class < ? > cls = obj . getClass ( ) ; return cls != Class . class ? cls : ( Class < ? > ) obj ; } | If the object is not a Class get its Class . Otherwise get the object as a Class . |
10,416 | public static Class < ? > getNamedClass ( Object obj ) { Class < ? > cls = getClass ( obj ) ; while ( cls != null && cls . isAnonymousClass ( ) ) { cls = cls . getEnclosingClass ( ) ; } return cls ; } | If the object is not a Class get its Class . Otherwise get the object as a Class . If the class is anonymous get a non - anonymous enclosing class . |
10,417 | public static Request request ( String url , String ... headers ) { Request . Builder request = new Request . Builder ( ) . url ( url ) ; if ( headers != null ) { int length = headers . length ; checkArgument ( length % 2 == 0 , "headers length must be a multiple of two" ) ; for ( int i = 0 ; i < length ; i += 2 ) { request . addHeader ( headers [ i ] , headers [ i + 1 ] ) ; } } return request . build ( ) ; } | Get a GET request for the URL and headers . |
10,418 | public Call call ( String url , String ... headers ) { return mCaller . newCall ( request ( url , headers ) ) ; } | Get a Call for a GET request for the URL and headers . |
10,419 | public Response response ( String url , String ... headers ) throws IOException { return call ( url , headers ) . execute ( ) ; } | Get a response to a GET request for the URL and headers . |
10,420 | public Response download ( String url , File destination ) throws IOException { return download ( url , destination , ( String [ ] ) null ) ; } | Download the resource at the URL and write it to the file . |
10,421 | public Response download ( String url , File destination , String ... headers ) throws IOException { try ( Response resp = response ( url , headers ) ) { if ( resp . isSuccessful ( ) ) { try ( BufferedSink sink = Okio . buffer ( Okio . sink ( destination ) ) ) { resp . body ( ) . source ( ) . readAll ( sink ) ; } } return resp ; } } | Download the resource at the URL with the headers and write it to the file . |
10,422 | public int getOffset ( ) { String value = getValue ( ) ; String superstring = getSuperstring ( ) ; return value != null && superstring != null ? superstring . indexOf ( value ) : - 1 ; } | Zero - based position of the first character of the substring within the superstring . |
10,423 | public String getString ( ) { StringBuffer buf = new StringBuffer ( ) ; for ( int i = 0 ; i != string . length ; i ++ ) { buf . append ( table [ ( string [ i ] >>> 4 ) % 0xf ] ) ; buf . append ( table [ string [ i ] & 0xf ] ) ; } return buf . toString ( ) ; } | UniversalStrings have characters which are 4 bytes long - for the moment we just return them in Hex ... |
10,424 | public static int clamp ( int value , int min , int max ) { return Math . min ( Math . max ( min , value ) , max ) ; } | Get the value if it is between min and max min if the value is less than min or max if the value is greater than max . |
10,425 | public static String normalise ( String s ) { if ( sDiacritics == null ) { sDiacritics = Pattern . compile ( "\\p{InCombiningDiacriticalMarks}+" ) ; } return sDiacritics . matcher ( Normalizer . normalize ( s , NFD ) ) . replaceAll ( "" ) . toUpperCase ( US ) ; } | Remove diacritics from the string and convert it to upper case . |
10,426 | public static String distance ( String latitudeColumn , String longitudeColumn , String latitudeCosineColumn , double latitude , double longitude , MeasureUnit unit , String alias ) { double degree = unit == MILE ? LATITUDE_DEGREE_MI : LATITUDE_DEGREE_KM ; return String . format ( ( Locale ) null , sDistance , degree , latitude , latitudeColumn , degree , latitude , latitudeColumn , degree , longitude , longitudeColumn , latitudeCosineColumn , degree , longitude , longitudeColumn , latitudeCosineColumn , alias ) ; } | Get a result column for the squared distance from the row coordinates to the supplied coordinates . SQLite doesn t have a square root core function so this must be applied in Java when reading the result column value . |
10,427 | public static void sleep ( long length , TimeUnit unit ) { try { unit . sleep ( length ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; } } | Sleep for the length of time . |
10,428 | boolean matches ( SmbExtendedAuthenticator authenticator , NtlmPasswordAuthentication auth ) { return matcheObject ( this . authenticator , authenticator ) && matcheObject ( this . auth , auth ) ; } | authenticator to decide whether or not reuse a session . |
10,429 | Key searchSessionKey ( Subject subject ) throws GSSException { if ( extendedGSSContextClass == null || inquireTypeSessionKey == null || inquireSecContext == null || gssContext == null ) { if ( log . level > 0 && ( ! deprecationWarningPrinted ) ) { log . print ( "WARNING: Kerberos Session Key is extracted from Kerberos Ticket. This is known to be problematic (See: https://bugs.openjdk.java.net/browse/JDK-8031973)." ) ; deprecationWarningPrinted = true ; } MIEName src = new MIEName ( gssContext . getSrcName ( ) . export ( ) ) ; MIEName targ = new MIEName ( gssContext . getTargName ( ) . export ( ) ) ; for ( KerberosTicket ticket : subject . getPrivateCredentials ( KerberosTicket . class ) ) { MIEName client = new MIEName ( gssContext . getMech ( ) , ticket . getClient ( ) . getName ( ) ) ; MIEName server = new MIEName ( gssContext . getMech ( ) , ticket . getServer ( ) . getName ( ) ) ; if ( src . equals ( client ) && targ . equals ( server ) ) { return ticket . getSessionKey ( ) ; } } return null ; } else { if ( extendedGSSContextClass . isAssignableFrom ( gssContext . getClass ( ) ) ) { try { return ( Key ) inquireSecContext . invoke ( gssContext , new Object [ ] { inquireTypeSessionKey } ) ; } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { log . print ( "Reflective access to ExtendedGSSContext failed" ) ; ex . printStackTrace ( log ) ; } } return null ; } } | Extract the context session key from the gssContext . The subject is only used if no support for extraction of the session key is not possible with an API and is used as a fallback method . |
10,430 | static protected int getPadBits ( int bitString ) { int val ; if ( bitString == 0 ) { return 7 ; } if ( bitString > 255 ) { val = ( ( bitString >> 8 ) & 0xFF ) ; } else { val = ( bitString & 0xFF ) ; } int bits = 1 ; while ( ( ( val <<= 1 ) & 0xFF ) != 0 ) { bits ++ ; } return 8 - bits ; } | return the correct number of pad bits for a bit string defined in a 16 bit constant |
10,431 | static protected byte [ ] getBytes ( int bitString ) { if ( bitString > 255 ) { byte [ ] bytes = new byte [ 2 ] ; bytes [ 0 ] = ( byte ) ( bitString & 0xFF ) ; bytes [ 1 ] = ( byte ) ( ( bitString >> 8 ) & 0xFF ) ; return bytes ; } else { byte [ ] bytes = new byte [ 1 ] ; bytes [ 0 ] = ( byte ) ( bitString & 0xFF ) ; return bytes ; } } | return the correct number of bytes for a bit string defined in a 16 bit constant |
10,432 | public static PreparedStatement setStrings ( PreparedStatement stmt , String ... params ) throws SQLException { return setStrings ( 1 , stmt , params ) ; } | Set the statement parameters starting at 1 in the order of the params . |
10,433 | public static int firstInt ( PreparedStatement stmt ) throws SQLException { ResultSet rs = stmt . executeQuery ( ) ; int i = rs . next ( ) ? rs . getInt ( 1 ) : Integer . MIN_VALUE ; stmt . close ( ) ; return i ; } | Execute the query get the int value in the first row and column of the result set and close the statement . |
10,434 | public static long firstLong ( PreparedStatement stmt ) throws SQLException { ResultSet rs = stmt . executeQuery ( ) ; long l = rs . next ( ) ? rs . getLong ( 1 ) : Long . MIN_VALUE ; stmt . close ( ) ; return l ; } | Execute the query get the long value in the first row and column of the result set and close the statement . |
10,435 | public static String firstString ( PreparedStatement stmt ) throws SQLException { ResultSet rs = stmt . executeQuery ( ) ; String s = rs . next ( ) ? rs . getString ( 1 ) : null ; stmt . close ( ) ; return s ; } | Execute the query get the String value in the first row and column of the result set and close the statement . |
10,436 | @ SuppressWarnings ( "unchecked" ) public static List < String > firstStringRow ( PreparedStatement stmt ) throws SQLException { return ( List < String > ) firstRow ( stmt , String . class ) ; } | Execute the query get the String values in the first row of the result set and close the statement . |
10,437 | @ SuppressWarnings ( "unchecked" ) public static List < String > allStrings ( PreparedStatement stmt ) throws SQLException { return ( List < String > ) all ( stmt , String . class ) ; } | Execute the query get the String values in the first column of the result set and close the statement . |
10,438 | public static int firstIntKey ( PreparedStatement stmt ) throws SQLException { stmt . execute ( ) ; ResultSet rs = stmt . getGeneratedKeys ( ) ; int key = rs . next ( ) ? rs . getInt ( 1 ) : 0 ; stmt . close ( ) ; return key ; } | Execute the insert statement get the first generated key as an int and close the statement . |
10,439 | public static long firstLongKey ( PreparedStatement stmt ) throws SQLException { stmt . execute ( ) ; ResultSet rs = stmt . getGeneratedKeys ( ) ; long key = rs . next ( ) ? rs . getLong ( 1 ) : 0L ; stmt . close ( ) ; return key ; } | Execute the insert statement get the first generated key as a long and close the statement . |
10,440 | public static int update ( PreparedStatement stmt ) throws SQLException { int rows = stmt . executeUpdate ( ) ; stmt . close ( ) ; return rows ; } | Execute the insert update or delete statement get the number of rows affected and close the statement . |
10,441 | public static Cpe parse ( String cpeString , boolean lenient ) throws CpeParsingException { if ( cpeString == null ) { throw new CpeParsingException ( "CPE String is null and cannot be parsed" ) ; } else if ( cpeString . regionMatches ( 0 , "cpe:/" , 0 , 5 ) ) { return parse22 ( cpeString , lenient ) ; } else if ( cpeString . regionMatches ( 0 , "cpe:2.3:" , 0 , 8 ) ) { return parse23 ( cpeString , lenient ) ; } throw new CpeParsingException ( "The CPE string specified does not conform to the CPE 2.2 or 2.3 specification" ) ; } | Parses a CPE String into an object with the option of parsing CPE 2 . 2 URI strings in lenient mode - allowing for CPE values that do not adhere to the specification . |
10,442 | protected static Cpe parse22 ( String cpeString , boolean lenient ) throws CpeParsingException { if ( cpeString == null || cpeString . isEmpty ( ) ) { throw new CpeParsingException ( "CPE String is null ir enpty - unable to parse" ) ; } CpeBuilder cb = new CpeBuilder ( ) ; String [ ] parts = cpeString . split ( ":" ) ; if ( parts . length <= 1 || parts . length > 8 ) { throw new CpeParsingException ( "CPE String is invalid - too many components specified: " + cpeString ) ; } if ( parts [ 1 ] . length ( ) != 2 ) { throw new CpeParsingException ( "CPE String contains a malformed part: " + cpeString ) ; } try { cb . part ( parts [ 1 ] . substring ( 1 ) ) ; if ( parts . length > 2 ) { cb . wfVendor ( Convert . cpeUriToWellFormed ( parts [ 2 ] , lenient ) ) ; } if ( parts . length > 3 ) { cb . wfProduct ( Convert . cpeUriToWellFormed ( parts [ 3 ] , lenient ) ) ; } if ( parts . length > 4 ) { cb . wfVersion ( Convert . cpeUriToWellFormed ( parts [ 4 ] , lenient ) ) ; } if ( parts . length > 5 ) { cb . wfUpdate ( Convert . cpeUriToWellFormed ( parts [ 5 ] , lenient ) ) ; } if ( parts . length > 6 ) { unpackEdition ( parts [ 6 ] , cb , lenient ) ; } if ( parts . length > 7 ) { cb . wfLanguage ( Convert . cpeUriToWellFormed ( parts [ 7 ] , lenient ) ) ; } return cb . build ( ) ; } catch ( CpeValidationException | CpeEncodingException ex ) { throw new CpeParsingException ( ex . getMessage ( ) ) ; } } | Parses a CPE 2 . 2 URI . |
10,443 | protected static void unpackEdition ( String edition , CpeBuilder cb , boolean lenient ) throws CpeParsingException { if ( edition == null || edition . isEmpty ( ) ) { return ; } try { String [ ] unpacked = edition . split ( "~" ) ; if ( edition . startsWith ( "~" ) ) { if ( unpacked . length > 1 ) { cb . wfEdition ( Convert . cpeUriToWellFormed ( unpacked [ 1 ] , lenient ) ) ; } if ( unpacked . length > 2 ) { cb . wfSwEdition ( Convert . cpeUriToWellFormed ( unpacked [ 2 ] , lenient ) ) ; } if ( unpacked . length > 3 ) { cb . wfTargetSw ( Convert . cpeUriToWellFormed ( unpacked [ 3 ] , lenient ) ) ; } if ( unpacked . length > 4 ) { cb . wfTargetHw ( Convert . cpeUriToWellFormed ( unpacked [ 4 ] , lenient ) ) ; } if ( unpacked . length > 5 ) { cb . wfOther ( Convert . cpeUriToWellFormed ( unpacked [ 5 ] , lenient ) ) ; } if ( unpacked . length > 6 ) { throw new CpeParsingException ( "Invalid packed edition" ) ; } } else { cb . wfEdition ( Convert . cpeUriToWellFormed ( edition , lenient ) ) ; } } catch ( CpeEncodingException ex ) { throw new CpeParsingException ( ex . getMessage ( ) ) ; } } | In a CPE 2 . 2 URI the new fields from CPE 2 . 3 may be packed into the edition field . If present each field will be preceeded by a ~ . Example ~edition~swEdition~targetSw~targetHw~other . |
10,444 | protected static Cpe parse23 ( String cpeString , boolean lenient ) throws CpeParsingException { if ( cpeString == null || cpeString . isEmpty ( ) ) { throw new CpeParsingException ( "CPE String is null ir enpty - unable to parse" ) ; } CpeBuilder cb = new CpeBuilder ( ) ; Cpe23PartIterator cpe = new Cpe23PartIterator ( cpeString ) ; try { cb . part ( cpe . next ( ) ) ; cb . wfVendor ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfProduct ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfVersion ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfUpdate ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfEdition ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfLanguage ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfSwEdition ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfTargetSw ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfTargetHw ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; cb . wfOther ( Convert . fsToWellFormed ( cpe . next ( ) , lenient ) ) ; } catch ( NoSuchElementException ex ) { throw new CpeParsingException ( "Invalid CPE (too few components): " + cpeString ) ; } if ( cpe . hasNext ( ) ) { throw new CpeParsingException ( "Invalid CPE (too many components): " + cpeString ) ; } try { return cb . build ( ) ; } catch ( CpeValidationException ex ) { throw new CpeParsingException ( ex . getMessage ( ) ) ; } } | Parses a CPE 2 . 3 Formatted String . |
10,445 | public static Status component ( String value ) { if ( value != null && ! value . isEmpty ( ) ) { if ( "\\-" . equals ( value ) ) { return Status . SINGLE_QUOTED_HYPHEN ; } for ( int x = 0 ; x < value . length ( ) ; x ++ ) { char c = value . charAt ( x ) ; if ( c == '?' && x > 0 && x < value . length ( ) - 1 && ! ( ( value . charAt ( x - 1 ) == '?' || value . charAt ( x - 1 ) == '*' || value . charAt ( x - 1 ) == '\\' ) || ( x < value . length ( ) - 1 && ( value . charAt ( x + 1 ) == '?' || value . charAt ( x + 1 ) == '*' ) ) ) ) { return Status . UNQUOTED_QUESTION_MARK ; } else if ( Character . isWhitespace ( c ) ) { return Status . WHITESPACE ; } else if ( c < 32 || c > 127 ) { return Status . NON_PRINTABLE ; } else if ( c == '*' && x != 0 && value . charAt ( x - 1 ) == '*' ) { return Status . ASTERISK_SEQUENCE ; } else if ( c == '*' && ! ( ( x == 0 || x == value . length ( ) - 1 ) || ( x > 0 && '\\' == value . charAt ( x - 1 ) ) ) ) { return Status . UNQUOTED_ASTERISK ; } } return Status . VALID ; } return Status . EMPTY ; } | Validates the component to ensure it meets the CPE 2 . 3 specification of allowed values . |
10,446 | private static long countCharacter ( String value , char c ) { return value . chars ( ) . filter ( s -> s == c ) . count ( ) ; } | Counts the number of times the char c is contained in the value . |
10,447 | public static Status cpe ( String value ) { if ( "cpe:2.3:" . regionMatches ( 0 , value , 0 , 8 ) ) { return formattedString ( value ) ; } return cpeUri ( value ) ; } | Validates the given CPE string value to ensure it is either a valid CPE URI or Formatted String . |
10,448 | public static String fromWellFormed ( String value ) { if ( value == null ) { return LogicalValue . ANY . getAbbreviation ( ) ; } StringBuilder buffer = new StringBuilder ( value ) ; char p = ' ' ; for ( int x = 0 ; x < buffer . length ( ) - 1 ; x ++ ) { char c = buffer . charAt ( x ) ; if ( c == '\\' && p != '\\' ) { buffer . delete ( x , x + 1 ) ; x -= 1 ; } p = c ; } return buffer . toString ( ) ; } | Transforms the given well formed string into a non - escaped string . A well formed string has all non - alphanumeric characters escaped with a backslash . |
10,449 | public static String wellFormedToFS ( Part value ) { if ( value == null ) { return LogicalValue . ANY . getAbbreviation ( ) ; } return value . getAbbreviation ( ) ; } | Encodes the given value into the CPE 2 . 3 Formatted String representation . |
10,450 | public static Pattern wellFormedToPattern ( String value ) { StringBuilder sb = new StringBuilder ( value . length ( ) + 4 ) ; for ( int x = 0 ; x < value . length ( ) ; x ++ ) { if ( value . charAt ( x ) == '*' ) { sb . append ( ".*" ) ; } else if ( value . charAt ( x ) == '?' ) { sb . append ( "." ) ; } else if ( value . charAt ( x ) == '\\' && ( x + 1 ) < value . length ( ) ) { sb . append ( '\\' ) . append ( value . charAt ( x ++ ) ) . append ( '\\' ) . append ( value . charAt ( x ) ) ; } else if ( ( value . charAt ( x ) >= 'a' && value . charAt ( x ) <= 'z' ) || ( value . charAt ( x ) >= 'A' && value . charAt ( x ) <= 'Z' ) || ( value . charAt ( x ) >= '0' && value . charAt ( x ) <= '9' ) ) { sb . append ( value . charAt ( x ) ) ; } else { sb . append ( '\\' ) . append ( value . charAt ( x ) ) ; } } return Pattern . compile ( sb . toString ( ) ) ; } | Converts a well formed string into a regular expression pattern . |
10,451 | private void validate ( String vendor1 , String product1 , String version1 , String update1 , String edition1 , String language1 , String swEdition1 , String targetSw1 , String targetHw1 , String other1 ) throws CpeValidationException { Status status = Validate . component ( vendor1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid vendor component: " + status . getMessage ( ) ) ; } status = Validate . component ( product1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid product component: " + status . getMessage ( ) ) ; } status = Validate . component ( version1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid version component: " + status . getMessage ( ) ) ; } status = Validate . component ( update1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid update component: " + status . getMessage ( ) ) ; } status = Validate . component ( edition1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid edition component: " + status . getMessage ( ) ) ; } status = Validate . component ( language1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid language component: " + status . getMessage ( ) ) ; } status = Validate . component ( swEdition1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid swEdition component: " + status . getMessage ( ) ) ; } status = Validate . component ( targetSw1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid targetSw component: " + status . getMessage ( ) ) ; } status = Validate . component ( targetHw1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid targetHw component: " + status . getMessage ( ) ) ; } status = Validate . component ( other1 ) ; if ( ! status . isValid ( ) ) { throw new CpeValidationException ( "Invalid other component: " + status . getMessage ( ) ) ; } } | Validates the CPE attributes . |
10,452 | public String toCpe22Uri ( ) throws CpeEncodingException { StringBuilder sb = new StringBuilder ( "cpe:/" ) ; sb . append ( Convert . wellFormedToCpeUri ( part ) ) . append ( ":" ) ; sb . append ( Convert . wellFormedToCpeUri ( vendor ) ) . append ( ":" ) ; sb . append ( Convert . wellFormedToCpeUri ( product ) ) . append ( ":" ) ; sb . append ( Convert . wellFormedToCpeUri ( version ) ) . append ( ":" ) ; sb . append ( Convert . wellFormedToCpeUri ( update ) ) . append ( ":" ) ; if ( ! ( ( swEdition . isEmpty ( ) || "*" . equals ( swEdition ) ) && ( targetSw . isEmpty ( ) || "*" . equals ( targetSw ) ) && ( targetHw . isEmpty ( ) || "*" . equals ( targetHw ) ) && ( other . isEmpty ( ) || "*" . equals ( other ) ) ) ) { sb . append ( "~" ) . append ( Convert . wellFormedToCpeUri ( edition ) ) . append ( "~" ) . append ( Convert . wellFormedToCpeUri ( swEdition ) ) . append ( "~" ) . append ( Convert . wellFormedToCpeUri ( targetSw ) ) . append ( "~" ) . append ( Convert . wellFormedToCpeUri ( targetHw ) ) . append ( "~" ) . append ( Convert . wellFormedToCpeUri ( other ) ) . append ( ":" ) ; } else { sb . append ( Convert . wellFormedToCpeUri ( edition ) ) . append ( ":" ) ; } sb . append ( Convert . wellFormedToCpeUri ( language ) ) ; return sb . toString ( ) . replaceAll ( "[:]*$" , "" ) ; } | Converts the CPE into the CPE 2 . 2 URI format . |
10,453 | public String toCpe23FS ( ) { return String . format ( "cpe:2.3:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s" , Convert . wellFormedToFS ( part ) , Convert . wellFormedToFS ( vendor ) , Convert . wellFormedToFS ( product ) , Convert . wellFormedToFS ( version ) , Convert . wellFormedToFS ( update ) , Convert . wellFormedToFS ( edition ) , Convert . wellFormedToFS ( language ) , Convert . wellFormedToFS ( swEdition ) , Convert . wellFormedToFS ( targetSw ) , Convert . wellFormedToFS ( targetHw ) , Convert . wellFormedToFS ( other ) ) ; } | Converts the CPE into the CPE 2 . 3 Formatted String . |
10,454 | public boolean matches ( ICpe target ) { boolean result = true ; result &= compareAttributes ( this . part , target . getPart ( ) ) ; result &= compareAttributes ( this . vendor , target . getWellFormedVendor ( ) ) ; result &= compareAttributes ( this . product , target . getWellFormedProduct ( ) ) ; result &= compareAttributes ( this . version , target . getWellFormedVersion ( ) ) ; result &= compareAttributes ( this . update , target . getWellFormedUpdate ( ) ) ; result &= compareAttributes ( this . edition , target . getWellFormedEdition ( ) ) ; result &= compareAttributes ( this . language , target . getWellFormedLanguage ( ) ) ; result &= compareAttributes ( this . swEdition , target . getWellFormedSwEdition ( ) ) ; result &= compareAttributes ( this . targetSw , target . getWellFormedTargetSw ( ) ) ; result &= compareAttributes ( this . targetHw , target . getWellFormedTargetHw ( ) ) ; result &= compareAttributes ( this . other , target . getWellFormedOther ( ) ) ; return result ; } | Determines if the CPE matches the given target CPE . This does not follow the CPE 2 . 3 Specification exactly as there are cases where undefined comparisons will result in either true or false . For instance ANY will match m + wild cards and NA will return false when the target has m + wild cards . |
10,455 | private static boolean containsSpecialCharacter ( String value ) { for ( int x = 0 ; x < value . length ( ) ; x ++ ) { char c = value . charAt ( x ) ; if ( c == '?' || c == '*' ) { return true ; } else if ( c == '\\' ) { x += 1 ; } } return false ; } | Determines if the string has an unquoted special character . |
10,456 | public int compareTo ( Object o ) { if ( o instanceof ICpe ) { ICpe otherObject = ( ICpe ) o ; final int before = - 1 ; final int equal = 0 ; final int after = 1 ; if ( this == otherObject ) { return equal ; } int r = getPart ( ) . getAbbreviation ( ) . compareTo ( otherObject . getPart ( ) . getAbbreviation ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getVendor ( ) . compareTo ( otherObject . getVendor ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getProduct ( ) . compareTo ( otherObject . getProduct ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = compareVersions ( getVersion ( ) , otherObject . getVersion ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getUpdate ( ) . compareTo ( otherObject . getUpdate ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getEdition ( ) . compareTo ( otherObject . getEdition ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getLanguage ( ) . compareTo ( otherObject . getLanguage ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getSwEdition ( ) . compareTo ( otherObject . getSwEdition ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getTargetSw ( ) . compareTo ( otherObject . getTargetSw ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getTargetHw ( ) . compareTo ( otherObject . getTargetHw ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } r = getOther ( ) . compareTo ( otherObject . getOther ( ) ) ; if ( r < 0 ) { return before ; } else if ( r > 0 ) { return after ; } return equal ; } throw new RuntimeException ( "Unable to compare " + o . getClass ( ) . getCanonicalName ( ) ) ; } | CompareTo is used for sorting this does not implement any CPE Matching rules . |
10,457 | protected static int compareVersions ( String left , String right ) { int result = 0 ; final List < String > subLeft = splitVersion ( left ) ; final List < String > subRight = splitVersion ( right ) ; final int subMax = ( subLeft . size ( ) <= subRight . size ( ) ) ? subLeft . size ( ) : subRight . size ( ) ; for ( int x = 0 ; result == 0 && x < subMax ; x ++ ) { if ( isPositiveInteger ( subLeft . get ( x ) ) && isPositiveInteger ( subRight . get ( x ) ) ) { try { result = Long . valueOf ( subLeft . get ( x ) ) . compareTo ( Long . valueOf ( subRight . get ( x ) ) ) ; } catch ( NumberFormatException ex ) { if ( ! subLeft . get ( x ) . equalsIgnoreCase ( subRight . get ( x ) ) ) { result = subLeft . get ( x ) . compareTo ( subRight . get ( x ) ) ; } } } else { result = subLeft . get ( x ) . compareTo ( subRight . get ( x ) ) ; } if ( result != 0 ) { return result ; } } if ( subLeft . size ( ) > subRight . size ( ) ) { result = 1 ; } if ( subRight . size ( ) > subLeft . size ( ) ) { result = - 1 ; } return result ; } | Compare version numbers to obtain the correct ordering . |
10,458 | protected void reset ( ) { part = Part . ANY ; vendor = LogicalValue . ANY . getAbbreviation ( ) ; product = LogicalValue . ANY . getAbbreviation ( ) ; version = LogicalValue . ANY . getAbbreviation ( ) ; update = LogicalValue . ANY . getAbbreviation ( ) ; edition = LogicalValue . ANY . getAbbreviation ( ) ; language = LogicalValue . ANY . getAbbreviation ( ) ; swEdition = LogicalValue . ANY . getAbbreviation ( ) ; targetSw = LogicalValue . ANY . getAbbreviation ( ) ; targetHw = LogicalValue . ANY . getAbbreviation ( ) ; other = LogicalValue . ANY . getAbbreviation ( ) ; } | Resets the CPE Builder to a clean state . |
10,459 | public void add ( E element ) { if ( element == null ) throw new NullPointerException ( ) ; if ( root == null ) { root = new MutableNode < > ( element ) ; } else { MutableNode < E > node = root ; while ( ! node . getElement ( ) . equals ( element ) ) { int distance = distance ( node . getElement ( ) , element ) ; MutableNode < E > parent = node ; node = parent . childrenByDistance . get ( distance ) ; if ( node == null ) { node = new MutableNode < > ( element ) ; parent . childrenByDistance . put ( distance , node ) ; break ; } } } } | Adds the given element to this tree if it s not already present . |
10,460 | public Set < Match < ? extends E > > search ( E query , int maxDistance ) { if ( query == null ) throw new NullPointerException ( ) ; if ( maxDistance < 0 ) throw new IllegalArgumentException ( "maxDistance must be non-negative" ) ; Metric < ? super E > metric = tree . getMetric ( ) ; Set < Match < ? extends E > > matches = new HashSet < > ( ) ; Queue < Node < E > > queue = new ArrayDeque < > ( ) ; queue . add ( tree . getRoot ( ) ) ; while ( ! queue . isEmpty ( ) ) { Node < E > node = queue . remove ( ) ; E element = node . getElement ( ) ; int distance = metric . distance ( element , query ) ; if ( distance < 0 ) { throw new IllegalMetricException ( format ( "negative distance (%d) defined between element `%s` and query `%s`" , distance , element , query ) ) ; } if ( distance <= maxDistance ) { matches . add ( new Match < > ( element , distance ) ) ; } int minSearchDistance = max ( distance - maxDistance , 0 ) ; int maxSearchDistance = distance + maxDistance ; for ( int searchDistance = minSearchDistance ; searchDistance <= maxSearchDistance ; ++ searchDistance ) { Node < E > childNode = node . getChildNode ( searchDistance ) ; if ( childNode != null ) { queue . add ( childNode ) ; } } } return matches ; } | Searches the tree for elements whose distance from the given query is less than or equal to the given maximum distance . |
10,461 | public boolean isLogger ( String loggerName ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , LOGGING , LOGGER , loggerName ) ; return null != readResource ( addr ) ; } | Checks to see if there is already a logger with the given name . |
10,462 | public String getLoggerLevel ( String loggerName ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , LOGGING , LOGGER , loggerName ) ; return getStringAttribute ( "level" , addr ) ; } | Returns the level of the given logger . |
10,463 | public void setLoggerLevel ( String loggerName , String level ) throws Exception { final Address addr = Address . root ( ) . add ( SUBSYSTEM , LOGGING , LOGGER , loggerName ) ; final ModelNode request ; if ( isLogger ( loggerName ) ) { request = createWriteAttributeRequest ( "level" , level , addr ) ; } else { final String dmrTemplate = "" + "{" + "\"category\" => \"%s\" " + ", \"level\" => \"%s\" " + ", \"use-parent-handlers\" => \"true\" " + "}" ; final String dmr = String . format ( dmrTemplate , loggerName , level ) ; request = ModelNode . fromString ( dmr ) ; request . get ( OPERATION ) . set ( ADD ) ; request . get ( ADDRESS ) . set ( addr . getAddressNode ( ) ) ; } final ModelNode response = execute ( request ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Sets the logger to the given level . If the logger does not exist yet it will be created . |
10,464 | public boolean isWebSubsystem ( ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_WEB ) ; return null != readResource ( addr ) ; } | Checks to see if the web subsystem exists . This should always exist unless the server is just starting up and its web subsystem has not even initialized yet . |
10,465 | public void setEnableWelcomeRoot ( boolean enableFlag ) throws Exception { final Address address = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_WEB , VIRTUAL_SERVER , DEFAULT_HOST ) ; final ModelNode req = createWriteAttributeRequest ( "enable-welcome-root" , Boolean . toString ( enableFlag ) , address ) ; final ModelNode response = execute ( req ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | The enable - welcome - root setting controls whether or not to deploy JBoss welcome - content application at root context . If you want to deploy your own app at the root context you need to disable the enable - welcome - root setting on the default host virtual server . If you want to show the JBoss welcome screen you need to enable this setting . |
10,466 | public boolean isConnector ( String name ) throws Exception { final Address address = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_WEB , CONNECTOR , name ) ; return null != readResource ( address ) ; } | Checks to see if there is already a connector with the given name . |
10,467 | public ModelNode getConnector ( String name ) throws Exception { final Address address = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_WEB , CONNECTOR , name ) ; return readResource ( address , true ) ; } | Returns the connector node with all its attributes . Will be null if it doesn t exist . |
10,468 | public void changeConnector ( String connectorName , String attribName , String attribValue ) throws Exception { final Address address = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_WEB , CONNECTOR , connectorName ) ; final ModelNode op = createWriteAttributeRequest ( attribName , attribValue , address ) ; final ModelNode response = execute ( op ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Use this to modify an attribute for an existing connector . |
10,469 | public void removeConnector ( String doomedConnectorName ) throws Exception { final Address address = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_WEB , CONNECTOR , doomedConnectorName ) ; if ( isConnector ( doomedConnectorName ) ) { remove ( address ) ; } return ; } | Removes the given web connector . |
10,470 | public static ModelNode createWriteAttributeRequest ( String attributeName , String attributeValue , Address address ) { final ModelNode op = createRequest ( WRITE_ATTRIBUTE , address ) ; op . get ( NAME ) . set ( attributeName ) ; setPossibleExpression ( op , VALUE , attributeValue ) ; return op ; } | Convienence method that allows you to create request that writes a single attribute s string value to a resource . |
10,471 | public static ModelNode createRequest ( String operation , Address address ) { return createRequest ( operation , address , null ) ; } | Convienence method that builds a partial operation request node . |
10,472 | public static ModelNode createRequest ( String operation , Address address , ModelNode extra ) { final ModelNode request = ( extra != null ) ? extra . clone ( ) : new ModelNode ( ) ; request . get ( OPERATION ) . set ( operation ) ; request . get ( ADDRESS ) . set ( address . getAddressNode ( ) ) ; return request ; } | Convienence method that builds a partial operation request node with additional node properties supplied by the given node . |
10,473 | public static ModelNode createBatchRequest ( ModelNode ... steps ) { final ModelNode composite = new ModelNode ( ) ; composite . get ( OPERATION ) . set ( BATCH ) ; composite . get ( ADDRESS ) . setEmptyList ( ) ; final ModelNode stepsNode = composite . get ( BATCH_STEPS ) ; for ( ModelNode step : steps ) { if ( step != null ) { stepsNode . add ( step ) ; } } return composite ; } | Creates a batch of operations that can be atomically invoked . |
10,474 | public static ModelNode getResults ( ModelNode operationResult ) { if ( ! operationResult . hasDefined ( RESULT ) ) { return new ModelNode ( ) ; } return operationResult . get ( RESULT ) ; } | If the given node has results those results are returned in a ModelNode . Otherwise an empty node is returned . |
10,475 | public ModelNode execute ( ModelNode request ) throws Exception { ModelControllerClient mcc = getModelControllerClient ( ) ; return mcc . execute ( request , OperationMessageHandler . logging ) ; } | Convienence method that executes the request . |
10,476 | public void remove ( Address doomedAddr ) throws Exception { final ModelNode request = createRequest ( REMOVE , doomedAddr ) ; final ModelNode response = execute ( request ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response , "Failed to remove resource at address [" + doomedAddr + "]" ) ; } return ; } | Removes the resource at the given address . |
10,477 | public void deploy ( String deploymentName , InputStream content , boolean enabled , Set < String > serverGroups , boolean forceDeploy ) { if ( serverGroups == null ) { serverGroups = Collections . emptySet ( ) ; } DeploymentResult result = null ; try { DeploymentManager dm = DeploymentManager . Factory . create ( getModelControllerClient ( ) ) ; Deployment deployment = Deployment . of ( content , deploymentName ) . addServerGroups ( serverGroups ) . setEnabled ( enabled ) ; if ( forceDeploy ) { result = dm . forceDeploy ( deployment ) ; } else { result = dm . deploy ( deployment ) ; } } catch ( Exception e ) { String errMsg ; if ( serverGroups . isEmpty ( ) ) { errMsg = String . format ( "Failed to deploy [%s] (standalone mode)" , deploymentName ) ; } else { errMsg = String . format ( "Failed to deploy [%s] to server groups: %s" , deploymentName , serverGroups ) ; } throw new FailureException ( errMsg , e ) ; } if ( ! result . successful ( ) ) { String errMsg ; if ( serverGroups . isEmpty ( ) ) { errMsg = String . format ( "Failed to deploy [%s] (standalone mode)" , deploymentName ) ; } else { errMsg = String . format ( "Failed to deploy [%s] to server groups [%s]" , deploymentName , serverGroups ) ; } throw new FailureException ( errMsg + ": " + result . getFailureMessage ( ) ) ; } return ; } | Uploads the content to the app server s content repository and then deploys the content . If this is to be used for app servers in domain mode you have to pass in one or more server groups . If this is to be used to deploy an app in a standalone server the server groups should be empty . |
10,478 | public void undeploy ( String deploymentName , Set < String > serverGroups , boolean removeContent ) { if ( serverGroups == null ) { serverGroups = Collections . emptySet ( ) ; } DeploymentResult result = null ; try { DeploymentManager dm = DeploymentManager . Factory . create ( getModelControllerClient ( ) ) ; UndeployDescription undeployDescription = UndeployDescription . of ( deploymentName ) . addServerGroups ( serverGroups ) . setFailOnMissing ( false ) . setRemoveContent ( removeContent ) ; result = dm . undeploy ( undeployDescription ) ; } catch ( Exception e ) { String errMsg ; if ( serverGroups . isEmpty ( ) ) { errMsg = String . format ( "Failed to undeploy [%s] (standalone mode)" , deploymentName ) ; } else { errMsg = String . format ( "Failed to undeploy [%s] from server groups: %s" , deploymentName , serverGroups ) ; } throw new FailureException ( errMsg , e ) ; } if ( ! result . successful ( ) ) { String errMsg ; if ( serverGroups . isEmpty ( ) ) { errMsg = String . format ( "Failed to undeploy [%s] (standalone mode)" , deploymentName ) ; } else { errMsg = String . format ( "Failed to undeploy [%s] from server groups [%s]" , deploymentName , serverGroups ) ; } throw new FailureException ( errMsg + ": " + result . getFailureMessage ( ) ) ; } return ; } | Undeploys an app . If an empty set of server groups is passed in this will assume we are operating on a standalone server . |
10,479 | public boolean isVault ( ) throws Exception { Address addr = Address . root ( ) . add ( CORE_SERVICE , VAULT ) ; final ModelNode queryNode = createRequest ( READ_RESOURCE , addr ) ; final ModelNode results = execute ( queryNode ) ; if ( isSuccess ( results ) ) { return true ; } return false ; } | Checks to see if there is already a vault configured . |
10,480 | public String getVaultClass ( ) throws Exception { Address addr = Address . root ( ) . add ( CORE_SERVICE , VAULT ) ; ModelNode vaultNode = readResource ( addr ) ; if ( vaultNode == null ) { return null ; } ModelNode codeNode = vaultNode . get ( "code" ) ; if ( codeNode == null ) { return null ; } return codeNode . asString ( ) ; } | Attempts to retrieve the configured class for the vault . This method will return null if no vault is configured or if the vault does not have a custom vault class . |
10,481 | public ModelNode createNewVaultRequest ( String className ) { String dmrTemplate = "" + "{" + "\"code\" => \"%s\"" + "}" ; String dmr = String . format ( dmrTemplate , className ) ; Address addr = Address . root ( ) . add ( CORE_SERVICE , VAULT ) ; final ModelNode request = ModelNode . fromString ( dmr ) ; request . get ( OPERATION ) . set ( ADD ) ; request . get ( ADDRESS ) . set ( addr . getAddressNode ( ) ) ; return request ; } | Returns a ModelNode that can be used to create the vault . Callers are free to tweak the queue request that is returned if they so choose before asking the client to execute the request . |
10,482 | public void setEnableAdminConsole ( boolean enableFlag ) throws Exception { final Address address = Address . root ( ) . add ( CORE_SERVICE , CORE_SERVICE_MGMT , MGMT_INTERFACE , MGMT_INTERFACE_HTTP ) ; final ModelNode req = createWriteAttributeRequest ( "console-enabled" , Boolean . toString ( enableFlag ) , address ) ; final ModelNode response = execute ( req ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Allows the caller to turn on or off complete access for the app server s admin console . |
10,483 | public Properties getSystemProperties ( ) throws Exception { final String [ ] address = { CORE_SERVICE , PLATFORM_MBEAN , "type" , "runtime" } ; final ModelNode op = createReadAttributeRequest ( true , "system-properties" , Address . root ( ) . add ( address ) ) ; final ModelNode results = execute ( op ) ; if ( isSuccess ( results ) ) { final Properties sysprops = new Properties ( ) ; final ModelNode node = getResults ( results ) ; final List < Property > propertyList = node . asPropertyList ( ) ; for ( Property property : propertyList ) { final String name = property . getName ( ) ; final ModelNode value = property . getValue ( ) ; if ( name != null ) { sysprops . put ( name , value != null ? value . asString ( ) : "" ) ; } } return sysprops ; } else { throw new FailureException ( results , "Failed to get system properties" ) ; } } | This returns the system properties that are set in the AS JVM . This is not the system properties in the JVM of this client object - it is actually the system properties in the remote JVM of the AS instance that the client is talking to . |
10,484 | public void setAppServerDefaultDeploymentScanEnabled ( boolean enabled ) throws Exception { final String [ ] addressArr = { SUBSYSTEM , DEPLOYMENT_SCANNER , SCANNER , "default" } ; final Address address = Address . root ( ) . add ( addressArr ) ; final ModelNode req = createWriteAttributeRequest ( "scan-enabled" , Boolean . toString ( enabled ) , address ) ; final ModelNode response = execute ( req ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Enabled or disables the default deployment scanner . |
10,485 | public String getAppServerDefaultDeploymentDir ( ) throws Exception { final String [ ] addressArr = { SUBSYSTEM , DEPLOYMENT_SCANNER , SCANNER , "default" } ; final Address address = Address . root ( ) . add ( addressArr ) ; final ModelNode resourceAttributes = readResource ( address ) ; if ( resourceAttributes == null ) { return null ; } final String path = resourceAttributes . get ( "path" ) . asString ( ) ; String relativeTo = null ; if ( resourceAttributes . hasDefined ( "relative-to" ) ) { relativeTo = resourceAttributes . get ( "relative-to" ) . asString ( ) ; } if ( relativeTo != null ) { String syspropValue = System . getProperty ( relativeTo ) ; if ( syspropValue == null ) { throw new IllegalStateException ( "Cannot support relative-to that isn't a sysprop: " + relativeTo ) ; } relativeTo = syspropValue ; } final File dir = new File ( relativeTo , path ) ; return dir . getAbsolutePath ( ) ; } | Returns the location where the default deployment scanner is pointing to . This is where EARs WARs and the like are deployed to . |
10,486 | public void setAppServerDefaultDeploymentTimeout ( long secs ) throws Exception { final String [ ] addressArr = { SUBSYSTEM , DEPLOYMENT_SCANNER , SCANNER , "default" } ; final Address address = Address . root ( ) . add ( addressArr ) ; final ModelNode req = createWriteAttributeRequest ( "deployment-timeout" , Long . toString ( secs ) , address ) ; final ModelNode response = execute ( req ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Sets the deployment timeout of the default deployment scanner . If a deployment takes longer than this value it will fail . |
10,487 | public void setSystemProperty ( String name , String value ) throws Exception { final ModelNode request = createRequest ( ADD , Address . root ( ) . add ( SYSTEM_PROPERTY , name ) ) ; request . get ( VALUE ) . set ( value ) ; final ModelNode response = execute ( request ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response , "Failed to set system property [" + name + "]" ) ; } } | Set a runtime system property in the JVM that is managed by JBossAS . |
10,488 | public void addExtension ( String name ) throws Exception { final ModelNode request = createRequest ( ADD , Address . root ( ) . add ( EXTENSION , name ) ) ; request . get ( MODULE ) . set ( name ) ; final ModelNode response = execute ( request ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response , "Failed to add new module extension [" + name + "]" ) ; } return ; } | Adds a new module extension to the core system . |
10,489 | public boolean isExtension ( String name ) throws Exception { return null != readResource ( Address . root ( ) . add ( EXTENSION , name ) ) ; } | Returns true if the given extension is already in existence . |
10,490 | public boolean isSubsystem ( String name ) throws Exception { return null != readResource ( Address . root ( ) . add ( SUBSYSTEM , name ) ) ; } | Returns true if the given subsystem is already in existence . |
10,491 | public void reload ( boolean adminOnly ) throws Exception { final ModelNode request = createRequest ( "reload" , Address . root ( ) ) ; request . get ( "admin-only" ) . set ( adminOnly ) ; final ModelNode response = execute ( request ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Invokes the management reload operation which will shut down all the app server services and restart them again potentially in admin - only mode . This does not shutdown the JVM itself . |
10,492 | public void shutdown ( boolean restart ) throws Exception { final ModelNode request = createRequest ( "shutdown" , Address . root ( ) ) ; request . get ( "restart" ) . set ( restart ) ; final ModelNode response = execute ( request ) ; if ( ! isSuccess ( response ) ) { throw new FailureException ( response ) ; } return ; } | Invokes the management shutdown operation that kills the JVM completely with System . exit . If restart is set to true the JVM will immediately be restarted again . If restart is false the JVM is killed and will stay down . Note that in either case the caller may not be returned to since the JVM in which this call is made will be killed and if the client is co - located with the server JVM this client will also die . |
10,493 | public boolean isQueue ( String queueName ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_MESSAGING , HORNETQ_SERVER , "default" ) ; String haystack = JMS_QUEUE ; return null != findNodeInList ( addr , haystack , queueName ) ; } | Checks to see if there is already a queue with the given name . |
10,494 | public ModelNode createNewQueueRequest ( String name , Boolean durable , List < String > entryNames ) { String dmrTemplate = "" + "{" + "\"durable\" => \"%s\", " + "\"entries\" => [\"%s\"] " + "}" ; String dmr = String . format ( dmrTemplate , ( ( null == durable ) ? "true" : durable . toString ( ) ) , entryNames . get ( 0 ) ) ; Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_MESSAGING , HORNETQ_SERVER , "default" , JMS_QUEUE , name ) ; final ModelNode request = ModelNode . fromString ( dmr ) ; request . get ( OPERATION ) . set ( ADD ) ; request . get ( ADDRESS ) . set ( addr . getAddressNode ( ) ) ; return request ; } | Returns a ModelNode that can be used to create a queue . Callers are free to tweak the queue request that is returned if they so choose before asking the client to execute the request . |
10,495 | @ SuppressWarnings ( "unchecked" ) public static < T > T [ ] cloneArray ( T [ ] original ) { if ( original == null ) { return null ; } try { Class < ? > clazz = original . getClass ( ) . getComponentType ( ) ; T [ ] copy = ( T [ ] ) Array . newInstance ( clazz , original . length ) ; if ( copy . length != 0 ) { Constructor < T > copyConstructor = ( Constructor < T > ) clazz . getConstructor ( clazz ) ; int i = 0 ; for ( T t : original ) { copy [ i ++ ] = copyConstructor . newInstance ( t ) ; } } return copy ; } catch ( Exception e ) { throw new RuntimeException ( "Cannot copy array. Does its type have a copy-constructor? " + original , e ) ; } } | Performs a deep copy of the given array by calling a copy constructor to build clones of each array element . |
10,496 | public boolean isSecurityDomain ( String securityDomainName ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_SECURITY ) ; String haystack = SECURITY_DOMAIN ; return null != findNodeInList ( addr , haystack , securityDomainName ) ; } | Checks to see if there is already a security domain with the given name . |
10,497 | public void createNewSecureIdentitySecurityDomain72 ( String securityDomainName , String username , String password ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_SECURITY , SECURITY_DOMAIN , securityDomainName ) ; ModelNode addTopNode = createRequest ( ADD , addr ) ; addTopNode . get ( CACHE_TYPE ) . set ( "default" ) ; Address authAddr = addr . clone ( ) . add ( AUTHENTICATION , CLASSIC ) ; ModelNode addAuthNode = createRequest ( ADD , authAddr ) ; Address loginAddr = authAddr . clone ( ) . add ( "login-module" , "SecureIdentity" ) ; ModelNode loginModule = createRequest ( ADD , loginAddr ) ; loginModule . get ( CODE ) . set ( "SecureIdentity" ) ; loginModule . get ( FLAG ) . set ( "required" ) ; ModelNode moduleOptions = loginModule . get ( MODULE_OPTIONS ) ; moduleOptions . setEmptyList ( ) ; addPossibleExpression ( moduleOptions , USERNAME , username ) ; addPossibleExpression ( moduleOptions , PASSWORD , password ) ; ModelNode batch = createBatchRequest ( addTopNode , addAuthNode , loginModule ) ; ModelNode results = execute ( batch ) ; if ( ! isSuccess ( results ) ) { throw new FailureException ( results , "Failed to create security domain [" + securityDomainName + "]" ) ; } return ; } | Create a new security domain using the SecureIdentity authentication method . This is used when you want to obfuscate a database password in the configuration . |
10,498 | public ModelNode getSecureIdentitySecurityDomainModuleOptions ( String securityDomainName ) throws Exception { Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_SECURITY , SECURITY_DOMAIN , securityDomainName , AUTHENTICATION , CLASSIC ) ; ModelNode authResource = readResource ( addr ) ; List < ModelNode > loginModules = authResource . get ( LOGIN_MODULES ) . asList ( ) ; for ( ModelNode loginModule : loginModules ) { if ( "SecureIdentity" . equals ( loginModule . get ( CODE ) . asString ( ) ) ) { ModelNode moduleOptions = loginModule . get ( MODULE_OPTIONS ) ; return moduleOptions ; } } return null ; } | Given the name of an existing security domain that uses the SecureIdentity authentication method this returns the module options for that security domain authentication method . This includes the username and password of the domain . |
10,499 | public void removeSecurityDomain ( String securityDomainName ) throws Exception { if ( ! isSecurityDomain ( securityDomainName ) ) { return ; } final Address addr = Address . root ( ) . add ( SUBSYSTEM , SUBSYSTEM_SECURITY , SECURITY_DOMAIN , securityDomainName ) ; ModelNode removeSecurityDomainNode = createRequest ( REMOVE , addr ) ; final ModelNode results = execute ( removeSecurityDomainNode ) ; if ( ! isSuccess ( results ) ) { throw new FailureException ( results , "Failed to remove security domain [" + securityDomainName + "]" ) ; } return ; } | Convenience method that removes a security domain by name . Useful when changing the characteristics of the login modules . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.