idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
122,200
@ Then ( "^The Elasticsearch index named '(.+?)' and mapping '(.+?)' contains a column named '(.+?)' with the value '(.+?)'$" ) public void elasticSearchIndexContainsDocument ( String indexName , String mappingName , String columnName , String columnValue ) throws Exception { Assertions . assertThat ( ( commonspec . ge...
Check that an elasticsearch index contains a specific document
122,201
@ When ( "^I search in LDAP using the filter '(.+?)' and the baseDn '(.+?)'$" ) public void searchLDAP ( String filter , String baseDn ) throws Exception { this . commonspec . setPreviousLdapResults ( commonspec . getLdapUtils ( ) . search ( new SearchRequest ( baseDn , filter ) ) ) ; }
Search for a LDAP object
122,202
@ Then ( "^the LDAP entry contains the attribute '(.+?)' with the value '(.+?)'$" ) public void ldapEntryContains ( String attributeName , String expectedValue ) { if ( this . commonspec . getPreviousLdapResults ( ) . isPresent ( ) ) { Assertions . assertThat ( this . commonspec . getPreviousLdapResults ( ) . get ( ) ....
Checks if the previous LDAP search contained a single Entry with a specific attribute and an expected value
122,203
@ DataProvider ( parallel = true ) public static Iterator < String [ ] > availableBrowsers ( ITestContext context , Constructor < ? > testConstructor ) throws Exception { Map < String , String > map = new HashMap < String , String > ( ) ; List < String > browsers = gridBrowsers ( map ) ; return buildIterator ( browsers...
Get the browsers available in a selenium grid .
122,204
@ DataProvider ( parallel = true ) public static Iterator < String [ ] > availableUniqueBrowsers ( ITestContext context , Constructor < ? > testConstructor ) throws Exception { Map < String , String > map = new HashMap < String , String > ( ) ; List < String > browsers = gridBrowsers ( map ) ; HashSet < String > hs = n...
Get unique browsers available in a selenium grid .
122,205
private static Iterator < String [ ] > buildIterator ( List < String > browsers ) { List < String [ ] > lData = Lists . newArrayList ( ) ; for ( String s : browsers ) { lData . add ( new String [ ] { s } ) ; } if ( lData . size ( ) == 0 ) { lData . add ( new String [ ] { "" } ) ; } return lData . iterator ( ) ; }
Build an String Iterator from String List .
122,206
@ Around ( value = "availableBrowsersCallPointcut()" ) public Object availableBrowsersCalls ( ProceedingJoinPoint pjp ) throws Throwable { if ( pjp . getArgs ( ) . length > 0 ) { if ( pjp . getArgs ( ) [ 0 ] instanceof ITestContext ) { if ( Arrays . asList ( ( ( ITestContext ) pjp . getArgs ( ) [ 0 ] ) . getIncludedGro...
If a System property with FORCE_BROWSER exists then Methods in BrowsersDataProvider will return its value .
122,207
@ Given ( "^I connect to Zookeeper at '(.+)'$" ) public void connectToZk ( String zookeeperHosts ) throws InterruptedException { commonspec . getZookeeperSecClient ( ) . setZookeeperSecConnection ( zookeeperHosts , 3000 ) ; commonspec . getZookeeperSecClient ( ) . connectZk ( ) ; }
Connect to zookeeper .
122,208
@ When ( "^I create the zNode '(.+?)'( with content '(.+?)')? which (IS|IS NOT) ephemeral$" ) public void createZNode ( String path , String foo , String content , boolean ephemeral ) throws Exception { if ( content != null ) { commonspec . getZookeeperSecClient ( ) . zCreate ( path , content , ephemeral ) ; } else { c...
Create zPath and domcument
122,209
public void connect ( String secured ) { buildCluster ( secured ) ; this . cassandraqueryUtils = new CassandraQueryUtils ( ) ; this . metadata = this . cluster . getMetadata ( ) ; LOGGER . debug ( "Connected to cluster (" + host + "): " + metadata . getClusterName ( ) + "\n" ) ; this . session = this . cluster . connec...
Connect to Cassandra host .
122,210
public void executeQueriesList ( List < String > queriesList ) { for ( String query : queriesList ) { this . session . execute ( query ) ; } }
Execute a list of queries over Cassandra .
122,211
public void reconnect ( ) { metadata = cluster . getMetadata ( ) ; LOGGER . debug ( "Connected to cluster (" + host + "): " + metadata . getClusterName ( ) + "\n" ) ; this . session = this . cluster . connect ( ) ; }
Reconnect to Cassandra host .
122,212
public void disconnect ( ) throws DBException { if ( this . session == null ) { throw new DBException ( "The Cassandra is null" ) ; } if ( this . cluster . isClosed ( ) ) { throw new DBException ( "The cluster has been closed" ) ; } this . session . close ( ) ; this . cluster . close ( ) ; }
Disconnect from Cassandra host .
122,213
public Metadata getMetadata ( ) throws DBException { if ( ! this . cluster . isClosed ( ) ) { this . metadata = cluster . getMetadata ( ) ; return this . metadata ; } else { throw new DBException ( "The cluster has been closed" ) ; } }
Get the metadata of the Cassandra Cluster .
122,214
public void buildCluster ( String secured ) { if ( secured == null ) { this . cluster = Cluster . builder ( ) . addContactPoint ( this . host ) . build ( ) ; this . cluster . getConfiguration ( ) . getQueryOptions ( ) . setConsistencyLevel ( ConsistencyLevel . ONE ) ; } else { try { this . cluster = Cluster . builder (...
Build a Cassandra cluster .
122,215
public void createKeyspace ( String keyspace ) { Map < String , String > replicationSimpleOneExtra = new HashMap < > ( ) ; replicationSimpleOneExtra . put ( "'class'" , "'SimpleStrategy'" ) ; replicationSimpleOneExtra . put ( "'replication_factor'" , "1" ) ; String query = this . cassandraqueryUtils . createKeyspaceQue...
Create a keyspace in Cassandra .
122,216
public void createTableWithData ( String table , Map < String , String > colums , ArrayList < String > pk ) { String query = this . cassandraqueryUtils . createTable ( table , colums , pk ) ; LOGGER . debug ( query ) ; executeQuery ( query ) ; }
Create a table in Cassandra .
122,217
public void insertData ( String table , Map < String , Object > fields ) { String query = this . cassandraqueryUtils . insertData ( table , fields ) ; LOGGER . debug ( query ) ; executeQuery ( query ) ; }
Insert data in a keyspace .
122,218
public boolean existsKeyspace ( String keyspace , boolean showLog ) { this . metadata = cluster . getMetadata ( ) ; if ( ! ( this . metadata . getKeyspaces ( ) . isEmpty ( ) ) ) { for ( KeyspaceMetadata k : metadata . getKeyspaces ( ) ) { if ( k . getName ( ) . equals ( keyspace ) ) { return true ; } } } return false ;...
Checks if a keyspace exists in Cassandra .
122,219
public List < String > getKeyspaces ( ) { ArrayList < String > result = new ArrayList < String > ( ) ; this . metadata = this . cluster . getMetadata ( ) ; if ( ! ( metadata . getKeyspaces ( ) . isEmpty ( ) ) ) { for ( KeyspaceMetadata k : this . metadata . getKeyspaces ( ) ) { result . add ( k . getName ( ) ) ; } } re...
Get a list of the existing keyspaces in Cassandra .
122,220
public boolean existsTable ( String keyspace , String table , boolean showLog ) { this . metadata = this . cluster . getMetadata ( ) ; if ( ! ( this . metadata . getKeyspace ( keyspace ) . getTables ( ) . isEmpty ( ) ) ) { for ( TableMetadata t : this . metadata . getKeyspace ( keyspace ) . getTables ( ) ) { if ( t . g...
Checks if a keyspace contains an especific table .
122,221
public List < String > getTables ( String keyspace ) { ArrayList < String > result = new ArrayList < String > ( ) ; this . metadata = this . cluster . getMetadata ( ) ; if ( ( ! existsKeyspace ( keyspace , false ) ) || ( this . metadata . getKeyspace ( keyspace ) . getTables ( ) . isEmpty ( ) ) ) { return result ; } fo...
Get tables of a keyspace .
122,222
public static List < String > loadScript ( String path ) { List < String > result = new ArrayList < String > ( ) ; URL url = CassandraUtils . class . getResource ( path ) ; LOGGER . debug ( url . toString ( ) ) ; LOGGER . info ( "Loading script from: " + url ) ; try ( BufferedReader br = new BufferedReader ( new InputS...
Load the lines of a CQL script containing one statement per line into a list . l
122,223
public static Pattern matchesOrContains ( String expectedMessage ) { Pattern pattern ; if ( expectedMessage . startsWith ( "regex:" ) ) { String regex = expectedMessage . substring ( expectedMessage . indexOf ( "regex:" ) + 6 , expectedMessage . length ( ) ) ; pattern = Pattern . compile ( regex ) ; } else { pattern = ...
Checks if a given string matches a regular expression or contains a string
122,224
public String retrieveData ( String baseData , String type ) { String result ; InputStream stream = getClass ( ) . getClassLoader ( ) . getResourceAsStream ( baseData ) ; Writer writer = new StringWriter ( ) ; char [ ] buffer = new char [ 1024 ] ; Reader reader ; if ( stream == null ) { this . getLogger ( ) . error ( "...
Returns the information contained in file passed as parameter
122,225
public JsonObject removeNulls ( JsonObject object ) { for ( int j = 0 ; j < object . names ( ) . size ( ) ; j ++ ) { if ( JsonType . OBJECT . equals ( object . get ( object . names ( ) . get ( j ) ) . getType ( ) ) ) { removeNulls ( object . get ( object . names ( ) . get ( j ) ) . asObject ( ) ) ; } else { if ( object...
Eliminates null occurrences replacing them with TO_BE_NULL
122,226
public void setPreviousElement ( String element , String value ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException , InstantiationException , ClassNotFoundException , NoSuchMethodException , InvocationTargetException { Reflections reflections = new Reflections ( "com.st...
Saves the value in the attribute in class extending CommonG .
122,227
private boolean isUUID ( String uuid ) { try { UUID . fromString ( uuid ) ; return true ; } catch ( Exception ex ) { return false ; } }
Check if a string is a UUID
122,228
private boolean isThisDateValid ( String dateToValidate , String dateFromat ) { if ( dateToValidate == null ) { return false ; } SimpleDateFormat sdf = new SimpleDateFormat ( dateFromat ) ; sdf . setLenient ( false ) ; try { Date date = sdf . parse ( dateToValidate ) ; } catch ( ParseException e ) { e . printStackTrace...
Check is a String is a valid timestamp format
122,229
public void resultsMustBeElasticsearch ( DataTable expectedResults ) throws Exception { if ( getElasticsearchResults ( ) != null ) { List < List < String > > expectedResultList = expectedResults . raw ( ) ; assertThat ( expectedResultList . size ( ) - 1 ) . overridingErrorMessage ( "Expected number of columns to be" + ...
Checks the different results of a previous query to Elasticsearch database
122,230
public void runLocalCommand ( String command ) throws Exception { String result = "" ; String line ; Process p ; try { p = Runtime . getRuntime ( ) . exec ( new String [ ] { "/bin/sh" , "-c" , command } ) ; p . waitFor ( ) ; } catch ( java . io . IOException e ) { this . commandExitStatus = 1 ; this . commandResult = "...
Runs a command locally
122,231
public String removeJSONPathElement ( String jsonString , String expr ) { Configuration conf = Configuration . builder ( ) . jsonProvider ( new GsonJsonProvider ( ) ) . mappingProvider ( new GsonMappingProvider ( ) ) . build ( ) ; DocumentContext context = JsonPath . using ( conf ) . parse ( jsonString ) ; context . de...
Remove a subelement in a JsonPath
122,232
public String replaceJSONPathElement ( String jsonString , String key , String value ) { return JsonPath . parse ( jsonString ) . set ( key , value ) . jsonString ( ) ; }
The function searches over the array by certain field value and replaces occurences with the parameter provided .
122,233
public JSONObject parseJSONSchema ( JSONObject schema ) throws Exception { JSONObject json = new JSONObject ( ) ; String name = "" ; JSONObject properties = schema ; if ( schema . has ( "properties" ) ) { properties = schema . getJSONObject ( "properties" ) ; } Iterator < ? > keys = properties . keys ( ) ; while ( keys...
Generate deployment json from schema
122,234
public boolean matchJsonToSchema ( JSONObject schema , JSONObject json ) throws Exception { SchemaLoader . builder ( ) . useDefaults ( true ) . schemaJson ( schema ) . build ( ) . load ( ) . build ( ) . validate ( json ) ; return true ; }
Check json matches schema
122,235
public static SeleniumAssert assertThat ( CommonG commong , List < WebElement > actual ) { return new SeleniumAssert ( commong , actual ) ; }
Checks a selenium list of WebElements .
122,236
public SeleniumAssert contains ( CharSequence ... values ) { if ( actual instanceof WebDriver ) { Strings . instance ( ) . assertContains ( info , ( ( WebDriver ) actual ) . getPageSource ( ) , values ) ; } else if ( actual instanceof WebElement ) { Strings . instance ( ) . assertContains ( info , ( ( WebElement ) actu...
Checks if a webDriver or WebElement has values .
122,237
public SeleniumAssert isTextField ( Condition < WebElement > cond ) { if ( actual instanceof List ) { Conditions . instance ( ) . equals ( cond ) ; } return this ; }
Checks if a WebElement is a TextField .
122,238
@ When ( "^I read info from csv file '(.+?)' with separator '(.+?)'$" ) public void readFromCSV ( String csvFile , String separator ) throws Exception { char sep = ',' ; if ( separator . length ( ) > 1 ) { switch ( separator ) { case "\\t" : sep = '\t' ; break ; default : sep = ',' ; break ; } } else { sep = separator ...
Read csv file and store result in list of maps
122,239
@ When ( "^I read file '(.+?)' as '(.+?)' and save it in environment variable '(.+?)' with:$" ) public void readFileToVariable ( String baseData , String type , String envVar , DataTable modifications ) throws Exception { String retrievedData = commonspec . retrieveData ( baseData , type ) ; commonspec . getLogger ( ) ...
Read the file passed as parameter perform the modifications specified and save the result in the environment variable passed as parameter .
122,240
@ When ( "^I read file '(.+?)' as '(.+?)' and save it in environment variable '(.+?)'$" ) public void readFileToVariableNoDataTable ( String baseData , String type , String envVar ) throws Exception { String retrievedData = commonspec . retrieveData ( baseData , type ) ; ThreadProperty . set ( envVar , retrievedData ) ...
Read the file passed as parameter and save the result in the environment variable passed as parameter .
122,241
public static String getClipboardText ( final Context context ) { final ClipboardManager clipboard = ( ClipboardManager ) context . getSystemService ( Context . CLIPBOARD_SERVICE ) ; final ClipData clipData = clipboard . getPrimaryClip ( ) ; if ( clipData != null && clipData . getItemCount ( ) > 0 ) { final CharSequenc...
Get the current text from the clipboard .
122,242
public static void setClipboardText ( final Context context , final String text ) { if ( text != null ) { final ClipboardManager clipboard = ( ClipboardManager ) context . getSystemService ( Context . CLIPBOARD_SERVICE ) ; final ClipData clipData = ClipData . newPlainText ( text , text ) ; clipboard . setPrimaryClip ( ...
Set the clipboard text .
122,243
public static void closeKeyboard ( Context context , View field ) { try { InputMethodManager imm = ( InputMethodManager ) context . getSystemService ( Context . INPUT_METHOD_SERVICE ) ; imm . hideSoftInputFromWindow ( field . getWindowToken ( ) , 0 ) ; } catch ( Exception ex ) { Log . e ( "Caffeine" , "Error occurred t...
Go away keyboard nobody likes you .
122,244
public static void showKeyboard ( Context context , View field ) { try { field . requestFocus ( ) ; InputMethodManager imm = ( InputMethodManager ) context . getSystemService ( Context . INPUT_METHOD_SERVICE ) ; imm . showSoftInput ( field , InputMethodManager . SHOW_IMPLICIT ) ; } catch ( Exception ex ) { Log . e ( "C...
Show the pop - up keyboard
122,245
public static Bitmap viewToImage ( Context context , WebView viewToBeConverted ) { int extraSpace = 2000 ; int height = viewToBeConverted . getContentHeight ( ) + extraSpace ; Bitmap viewBitmap = Bitmap . createBitmap ( viewToBeConverted . getWidth ( ) , height , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canv...
Convert view to an image . Can be used to make animations smoother .
122,246
public static void launchWebBrowser ( final Context context , final String url ) { if ( context != null && url != null && ! "" . equals ( url ) ) { final Intent browserIntent = new Intent ( Intent . ACTION_VIEW , Uri . parse ( url ) ) ; if ( browserIntent . resolveActivity ( context . getPackageManager ( ) ) != null ) ...
Start Intent to launch web browser .
122,247
public static boolean isAppInstalled ( final Context context , final String packageName ) { try { context . getPackageManager ( ) . getPackageInfo ( packageName , 0 ) ; return true ; } catch ( Exception e ) { return false ; } }
Check if app for the given package name is installed on this device .
122,248
public static void launchCameraIntent ( final Activity context , final Uri outputDestination , final int requestCode ) { final Intent intent = new Intent ( MediaStore . ACTION_IMAGE_CAPTURE ) ; intent . putExtra ( MediaStore . EXTRA_OUTPUT , outputDestination ) ; if ( intent . resolveActivity ( context . getPackageMana...
Launch camera on the device using android s ACTION_IMAGE_CAPTURE intent .
122,249
public static boolean launchAppForPackage ( final Context context , final String packageName ) { try { final PackageManager packageManager = context . getPackageManager ( ) ; final Intent intent = packageManager . getLaunchIntentForPackage ( packageName ) ; intent . addCategory ( Intent . CATEGORY_LAUNCHER ) ; context ...
Tries to launch the application for a given package name .
122,250
public static void launchActivity ( Activity context , Class < ? extends Activity > activity , boolean closeCurrentActivity , Map < String , String > params ) { Intent intent = new Intent ( context , activity ) ; if ( params != null ) { Bundle bundle = new Bundle ( ) ; for ( Entry < String , String > param : params . e...
Launch an Activity .
122,251
public static void turnScreenOn ( Activity context ) { try { Window window = context . getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_DISMISS_KEYGUARD ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_SHOW_WHEN_LOCKED ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_TURN_SC...
Force screen to turn on if the phone is asleep .
122,252
public final static boolean isValidEmail ( String email ) { if ( email == null ) { return false ; } else { return android . util . Patterns . EMAIL_ADDRESS . matcher ( email ) . matches ( ) ; } }
Uses androids android . util . Patterns . EMAIL_ADDRESS to check if an email address is valid .
122,253
public final static boolean isValidURL ( String url ) { if ( url == null ) { return false ; } else { return Patterns . WEB_URL . matcher ( url ) . matches ( ) ; } }
Uses androids android . util . Patterns . WEB_URL to check if an url is valid .
122,254
public static Toast quickToast ( Context context , String message , boolean longLength ) { final Toast toast ; if ( longLength ) { toast = Toast . makeText ( context , message , Toast . LENGTH_LONG ) ; } else { toast = Toast . makeText ( context , message , Toast . LENGTH_SHORT ) ; } toast . show ( ) ; return toast ; }
Display a toast with the given message .
122,255
public Server onpublish ( Action < Map < String , Object > > action ) { publishActions . add ( action ) ; return this ; }
Adds an action to be called with a message to be published to every node in the cluster .
122,256
public static ServerSocketPredicate tag ( String ... tags ) { return socket -> socket . tags ( ) . containsAll ( Arrays . asList ( tags ) ) ; }
Returns a predicate that tests the socket tags against the given tags .
122,257
public static void addRoute ( MangooRoute route ) { Objects . requireNonNull ( route , Required . ROUTE . toString ( ) ) ; Preconditions . checkArgument ( routes . size ( ) <= MAX_ROUTES , "Maximum of " + MAX_ROUTES + " routes reached" ) ; routes . add ( route ) ; if ( route instanceof RequestRoute ) { RequestRoute req...
Adds a new route to the router
122,258
public static RequestRoute getReverseRoute ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; return reverseRoutes . get ( key . toLowerCase ( Locale . ENGLISH ) ) ; }
Retrieves a reverse route by its controller class and controller method
122,259
public void addChannel ( WebSocketChannel channel ) { Objects . requireNonNull ( channel , Required . CHANNEL . toString ( ) ) ; final String url = RequestUtils . getWebSocketURL ( channel ) ; Set < WebSocketChannel > channels = getChannels ( url ) ; if ( channels == null ) { channels = new HashSet < > ( ) ; channels ....
Adds a new channel to the manager
122,260
public Set < WebSocketChannel > getChannels ( String uri ) { Objects . requireNonNull ( uri , Required . URI . toString ( ) ) ; final Set < WebSocketChannel > channels = this . cache . get ( Default . WSS_CACHE_PREFIX . toString ( ) + uri ) ; return ( channels == null ) ? new HashSet < > ( ) : channels ; }
Retrieves all channels under a given URL
122,261
public < T > Future < T > submit ( Runnable runnable , T result ) { return this . executorService . submit ( runnable , result ) ; }
Submits a Runnable task for execution and returns a Future representing that task . The Future s get method will return the given result upon successful completion .
122,262
public void reload ( Locale locale ) { this . bundle = ResourceBundle . getBundle ( Default . BUNDLE_NAME . toString ( ) , locale ) ; }
Refreshes the resource bundle by reloading the bundle with the default locale
122,263
public static Response withRedirect ( String redirectTo ) { Objects . requireNonNull ( redirectTo , Required . REDIRECT_TO . toString ( ) ) ; return new Response ( redirectTo ) ; }
Creates a response object with a given url to redirect to
122,264
public Response andTemplate ( String template ) { Objects . requireNonNull ( template , Required . TEMPLATE . toString ( ) ) ; this . template = template ; return this ; }
Sets a specific template to use for the response
122,265
public Response andCharset ( String charset ) { Objects . requireNonNull ( charset , Required . CHARSET . toString ( ) ) ; this . charset = charset ; return this ; }
Sets a specific charset to the response
122,266
public Response andCookie ( Cookie cookie ) { Objects . requireNonNull ( cookie , Required . COOKIE . toString ( ) ) ; this . cookies . add ( cookie ) ; return this ; }
Adds an additional Cookie to the response which is passed to the client
122,267
@ SuppressFBWarnings ( justification = "null check of file on entry point of method" , value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" ) public Response andBinaryFile ( Path file ) { Objects . requireNonNull ( file , Required . FILE . toString ( ) ) ; try ( InputStream inputStream = Files . newInputStream ( file ) ) {...
Sends a binary file to the client skipping rendering
122,268
public Response andBinaryContent ( byte [ ] content ) { Objects . requireNonNull ( content , Required . CONTENT . toString ( ) ) ; this . binaryContent = content . clone ( ) ; this . binary = true ; this . rendered = false ; return this ; }
Sends binary content to the client skipping rendering
122,269
public Response andHeader ( HttpString key , String value ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; this . headers . put ( key , value ) ; return this ; }
Adds an additional header to the request response . If an header key already exists it will we overwritten with the latest value .
122,270
public Response andContent ( Map < String , Object > content ) { Objects . requireNonNull ( content , Required . CONTENT . toString ( ) ) ; this . content . putAll ( content ) ; return this ; }
Adds an additional content map to the content rendered in the template . Already existing values with the same key are overwritten .
122,271
public Response andHeaders ( Map < HttpString , String > headers ) { Objects . requireNonNull ( headers , Required . HEADERS . toString ( ) ) ; this . headers . putAll ( headers ) ; return this ; }
Adds an additional header map to the response . Already existing values with the same key are overwritten .
122,272
public RequestRoute respondeWith ( String method ) { Objects . requireNonNull ( method , Required . CONTROLLER_METHOD . toString ( ) ) ; this . controllerMethod = method ; return this ; }
Sets the controller method to response on request
122,273
public void withControllerClass ( Class < ? > clazz ) { Objects . requireNonNull ( clazz , Required . CONTROLLER_CLASS . toString ( ) ) ; this . controllerClass = clazz ; }
Sets the controller class of this request
122,274
public void withHttpMethod ( Http method ) { Objects . requireNonNull ( method , Required . METHOD . toString ( ) ) ; this . method = method ; }
Sets the HTTP method of this request
122,275
public String getHeader ( HttpString headerName ) { return ( this . httpServerExchange . getRequestHeaders ( ) . get ( headerName ) == null ) ? null : this . httpServerExchange . getRequestHeaders ( ) . get ( headerName ) . element ( ) ; }
Retrieves a specific header value by its name
122,276
public void addAttribute ( String key , Object value ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; this . attributes . put ( key , value ) ; }
Adds an attribute to the internal attributes map
122,277
public Object getAttribute ( String key ) { Objects . requireNonNull ( key , Required . KEY . toString ( ) ) ; return this . attributes . get ( key ) ; }
Returns an object attribute from a given key
122,278
public void addConnection ( ServerSentEventConnection connection ) { Objects . requireNonNull ( connection , Required . CONNECTION . toString ( ) ) ; final String url = RequestUtils . getServerSentEventURL ( connection ) ; Set < ServerSentEventConnection > uriConnections = getConnections ( url ) ; if ( uriConnections =...
Adds a new connection to the manager
122,279
public void send ( String uri , String data ) { Objects . requireNonNull ( uri , Required . URI . toString ( ) ) ; final Set < ServerSentEventConnection > uriConnections = getConnections ( uri ) ; if ( uriConnections != null ) { uriConnections . stream ( ) . filter ( ServerSentEventConnection :: isOpen ) . forEach ( ( ...
Sends data to all connections for a given URI resource
122,280
public Set < ServerSentEventConnection > getConnections ( String uri ) { Objects . requireNonNull ( uri , Required . URI . toString ( ) ) ; final Set < ServerSentEventConnection > uriConnections = this . cache . get ( Default . SSE_CACHE_PREFIX . toString ( ) + uri ) ; return ( uriConnections == null ) ? new HashSet < ...
Retrieves all connection resources under a given URL
122,281
public void put ( String key , String value ) { if ( validCharacters ( key ) && validCharacters ( value ) ) { this . values . put ( key , value ) ; } }
Adds a value with a specific key to the flash overwriting an existing value
122,282
private boolean validCharacters ( String value ) { if ( INVALID_CHARACTERS . contains ( value ) ) { LOG . error ( "Flash key or value can not contain the following characters: spaces, |, & or :" ) ; return false ; } return true ; }
Checks if the given value contains characters that are not allowed in the key or value of a flash cookie
122,283
public static String getVersion ( ) { String version = Default . VERSION_UNKNOW . toString ( ) ; try ( InputStream inputStream = Resources . getResource ( Default . VERSION_PROPERTIES . toString ( ) ) . openStream ( ) ) { final Properties properties = new Properties ( ) ; properties . load ( inputStream ) ; version = S...
Retrieves the current version of the framework from the version . properties file
122,284
public static Map < String , String > copyMap ( Map < String , String > originalMap ) { Objects . requireNonNull ( originalMap , Required . MAP . toString ( ) ) ; return new HashMap < > ( originalMap ) ; }
Copies a given map to a new map instance
122,285
public static String randomString ( int length ) { Preconditions . checkArgument ( length > MIN_PASSWORD_LENGTH , "random string length must be at least 1 character" ) ; Preconditions . checkArgument ( length <= MAX_PASSWORD_LENGTH , "random string length must be at most 256 character" ) ; return RandomStringUtils . ra...
Generates a random string with the given length .
122,286
public static String readableFileSize ( long size ) { if ( size <= 0 ) { return "0" ; } int index = ( int ) ( Math . log10 ( size ) / Math . log10 ( CONVERTION ) ) ; return new DecimalFormat ( "#,##0.#" ) . format ( size / Math . pow ( CONVERTION , index ) ) + " " + UNITS [ index ] ; }
Converts a given file size into a readable file size including unit
122,287
public static boolean resourceExists ( String name ) { Objects . requireNonNull ( name , Required . NAME . toString ( ) ) ; URL resource = null ; try { resource = Resources . getResource ( name ) ; } catch ( IllegalArgumentException e ) { } return resource != null ; }
Checks if a resource exists in the classpath
122,288
public static void minify ( String absolutePath ) { if ( absolutePath == null || absolutePath . contains ( MIN ) ) { return ; } if ( config == null ) { System . setProperty ( Key . APPLICATION_CONFIG . toString ( ) , basePath + Default . CONFIG_PATH . toString ( ) ) ; config = new Config ( Mode . DEV . toString ( ) ) ;...
Minifies a JS or CSS file to a corresponding JS or CSS file
122,289
public static void preprocess ( String absolutePath ) { if ( absolutePath == null ) { return ; } if ( config == null ) { System . setProperty ( Key . APPLICATION_CONFIG . toString ( ) , basePath + Default . CONFIG_PATH . toString ( ) ) ; config = new Config ( ) ; } if ( config . isApplicationPreprocessLess ( ) && absol...
Compiles a LESS or SASS file to a corresponding CSS file
122,290
@ SuppressFBWarnings ( justification = "SourcePath should intentionally come from user file path" , value = "PATH_TRAVERSAL_IN" ) private List < Source > getSources ( int errorLine , String sourcePath ) throws IOException { Objects . requireNonNull ( sourcePath , Required . SOURCE_PATH . toString ( ) ) ; StringBuilder ...
Retrieves the lines of code where an exception occurred
122,291
private String getSourceCodePath ( StackTraceElement stackTraceElement ) { Objects . requireNonNull ( stackTraceElement , Required . STACK_TRACE_ELEMENT . toString ( ) ) ; String packageName = stackTraceElement . getClassName ( ) ; int position = packageName . lastIndexOf ( '.' ) ; if ( position > 0 ) { packageName = p...
Retrieves the source code file name from an StrackTraceElement
122,292
private String getCacheKey ( HttpServerExchange exchange ) { String host = null ; HeaderMap headerMap = exchange . getRequestHeaders ( ) ; if ( headerMap != null ) { HeaderValues headerValues = headerMap . get ( Header . X_FORWARDED_FOR . toHttpString ( ) ) ; if ( headerValues != null ) { host = headerValues . element ...
Creates a key for used for limit an request containing the requested url and the source host
122,293
protected void nextHandler ( HttpServerExchange exchange ) throws Exception { if ( this . attachment . hasBasicAuthentication ( ) ) { HttpHandler httpHandler = RequestUtils . wrapBasicAuthentication ( Application . getInstance ( LocaleHandler . class ) , this . attachment . getUsername ( ) , getPassword ( ) ) ; httpHan...
Handles the next request in the handler chain
122,294
public static String getQRCode ( String name , String issuer , String secret , HmacShaAlgorithm algorithm , String digits , String period ) { Objects . requireNonNull ( name , Required . ACCOUNT_NAME . toString ( ) ) ; Objects . requireNonNull ( secret , Required . SECRET . toString ( ) ) ; Objects . requireNonNull ( i...
Generates a QR code to share a secret with a user
122,295
public static String getOtpauthURL ( String name , String issuer , String secret , HmacShaAlgorithm algorithm , String digits , String period ) { Objects . requireNonNull ( name , Required . ACCOUNT_NAME . toString ( ) ) ; Objects . requireNonNull ( secret , Required . SECRET . toString ( ) ) ; Objects . requireNonNull...
Generates a otpauth code to share a secret with a user
122,296
@ SuppressWarnings ( "unchecked" ) protected Session getSessionCookie ( HttpServerExchange exchange ) { Session session = Session . create ( ) . withContent ( new HashMap < > ( ) ) . withAuthenticity ( MangooUtils . randomString ( STRING_LENGTH ) ) ; if ( this . config . getSessionCookieExpires ( ) > 0 ) { session . wi...
Retrieves the current session from the HttpServerExchange
122,297
protected Authentication getAuthenticationCookie ( HttpServerExchange exchange ) { Authentication authentication = Authentication . create ( ) . withSubject ( null ) ; String cookieValue = getCookieValue ( exchange , this . config . getAuthenticationCookieName ( ) ) ; if ( StringUtils . isNotBlank ( cookieValue ) ) { t...
Retrieves the current authentication from the HttpServerExchange
122,298
@ SuppressWarnings ( "unchecked" ) protected Flash getFlashCookie ( HttpServerExchange exchange ) { Flash flash = Flash . create ( ) ; final String cookieValue = getCookieValue ( exchange , this . config . getFlashCookieName ( ) ) ; if ( StringUtils . isNotBlank ( cookieValue ) ) { try { String decryptedValue = Applica...
Retrieves the flash cookie from the current
122,299
private String getCookieValue ( HttpServerExchange exchange , String cookieName ) { String value = null ; Map < String , Cookie > requestCookies = exchange . getRequestCookies ( ) ; if ( requestCookies != null ) { Cookie cookie = exchange . getRequestCookies ( ) . get ( cookieName ) ; if ( cookie != null ) { value = co...
Retrieves the value of a cookie with a given name from a HttpServerExchange