idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
28,000 | public void setName ( int pathId , String pathName ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_PATH + " SET " + Constants . PATH_PROFILE_PATHNAME + " = ?" + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setString ( 1 , pathName ) ; statement . setInt ( 2 , pathId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Sets the path name for this ID |
28,001 | public void setPath ( int pathId , String path ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_PATH + " SET " + Constants . PATH_PROFILE_ACTUAL_PATH + " = ? " + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setString ( 1 , path ) ; statement . setInt ( 2 , pathId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Sets the actual path for this ID |
28,002 | public void setBodyFilter ( int pathId , String bodyFilter ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_PATH + " SET " + Constants . PATH_PROFILE_BODY_FILTER + " = ? " + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setString ( 1 , bodyFilter ) ; statement . setInt ( 2 , pathId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Sets the body filter for this ID |
28,003 | public void setContentType ( int pathId , String contentType ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_PATH + " SET " + Constants . PATH_PROFILE_CONTENT_TYPE + " = ? " + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setString ( 1 , contentType ) ; statement . setInt ( 2 , pathId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Sets the content type for this ID |
28,004 | public void setRequestType ( int pathId , Integer requestType ) { if ( requestType == null ) { requestType = Constants . REQUEST_TYPE_GET ; } PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_PATH + " SET " + Constants . PATH_PROFILE_REQUEST_TYPE + " = ?" + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setInt ( 1 , requestType ) ; statement . setInt ( 2 , pathId ) ; statement . executeUpdate ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Sets the request type for this ID . Defaults to GET |
28,005 | public void setGlobal ( int pathId , Boolean global ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_PATH + " SET " + Constants . PATH_PROFILE_GLOBAL + " = ? " + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setBoolean ( 1 , global ) ; statement . setInt ( 2 , pathId ) ; statement . executeUpdate ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Sets the global setting for this ID |
28,006 | public List < EndpointOverride > getPaths ( int profileId , String clientUUID , String [ ] filters ) throws Exception { ArrayList < EndpointOverride > properties = new ArrayList < EndpointOverride > ( ) ; PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { String queryString = this . getPathSelectString ( ) ; queryString += " AND " + Constants . DB_TABLE_PATH + "." + Constants . GENERIC_PROFILE_ID + "=? " + " ORDER BY " + Constants . PATH_PROFILE_PATH_ORDER + " ASC" ; statement = sqlConnection . prepareStatement ( queryString ) ; statement . setString ( 1 , clientUUID ) ; statement . setInt ( 2 , profileId ) ; results = statement . executeQuery ( ) ; while ( results . next ( ) ) { EndpointOverride endpoint = this . getEndpointOverrideFromResultSet ( results ) ; endpoint . setFilters ( filters ) ; properties . add ( endpoint ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } return properties ; } | Returns an array of all endpoints |
28,007 | public void setCustomRequest ( int pathId , String customRequest , String clientUUID ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { int profileId = EditService . getProfileIdFromPathID ( pathId ) ; statement = sqlConnection . prepareStatement ( "UPDATE " + Constants . DB_TABLE_REQUEST_RESPONSE + " SET " + Constants . REQUEST_RESPONSE_CUSTOM_REQUEST + "= ?" + " WHERE " + Constants . GENERIC_PROFILE_ID + "= ?" + " AND " + Constants . GENERIC_CLIENT_UUID + "= ?" + " AND " + Constants . REQUEST_RESPONSE_PATH_ID + "= ?" ) ; statement . setString ( 1 , customRequest ) ; statement . setInt ( 2 , profileId ) ; statement . setString ( 3 , clientUUID ) ; statement . setInt ( 4 , pathId ) ; statement . executeUpdate ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Set the value for a custom request |
28,008 | public void clearResponseSettings ( int pathId , String clientUUID ) throws Exception { logger . info ( "clearing response settings" ) ; this . setResponseEnabled ( pathId , false , clientUUID ) ; OverrideService . getInstance ( ) . disableAllOverrides ( pathId , clientUUID , Constants . OVERRIDE_TYPE_RESPONSE ) ; EditService . getInstance ( ) . updateRepeatNumber ( Constants . OVERRIDE_TYPE_RESPONSE , pathId , clientUUID ) ; } | Clear all overrides reset repeat counts for a response path |
28,009 | public void clearRequestSettings ( int pathId , String clientUUID ) throws Exception { this . setRequestEnabled ( pathId , false , clientUUID ) ; OverrideService . getInstance ( ) . disableAllOverrides ( pathId , clientUUID , Constants . OVERRIDE_TYPE_REQUEST ) ; EditService . getInstance ( ) . updateRepeatNumber ( Constants . OVERRIDE_TYPE_REQUEST , pathId , clientUUID ) ; } | Clear all overrides reset repeat counts for a request path |
28,010 | public List < EndpointOverride > getSelectedPaths ( int overrideType , Client client , Profile profile , String uri , Integer requestType , boolean pathTest ) throws Exception { List < EndpointOverride > selectPaths = new ArrayList < EndpointOverride > ( ) ; List < EndpointOverride > paths = new ArrayList < EndpointOverride > ( ) ; if ( client . getIsActive ( ) ) { paths = getPaths ( profile . getId ( ) , client . getUUID ( ) , null ) ; } boolean foundRealPath = false ; logger . info ( "Checking uri: {}" , uri ) ; for ( EndpointOverride path : paths ) { if ( requestType != - 1 && path . getRequestType ( ) != requestType && path . getRequestType ( ) != Constants . REQUEST_TYPE_ALL ) { continue ; } try { Pattern pattern = Pattern . compile ( path . getPath ( ) ) ; Matcher matcher = pattern . matcher ( uri ) ; if ( matcher . find ( ) ) { if ( pathTest || ( path . getEnabledEndpoints ( ) . size ( ) > 0 && ( ( overrideType == Constants . OVERRIDE_TYPE_RESPONSE && path . getResponseEnabled ( ) ) || ( overrideType == Constants . OVERRIDE_TYPE_REQUEST && path . getRequestEnabled ( ) ) ) ) ) { if ( ! foundRealPath || path . getGlobal ( ) ) { selectPaths . add ( path ) ; } } if ( ! path . getGlobal ( ) ) { foundRealPath = true ; } } } catch ( PatternSyntaxException pse ) { } } return selectPaths ; } | Obtain matching paths for a request |
28,011 | public boolean isActive ( int profileId ) { boolean active = false ; PreparedStatement queryStatement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { queryStatement = sqlConnection . prepareStatement ( "SELECT " + Constants . CLIENT_IS_ACTIVE + " FROM " + Constants . DB_TABLE_CLIENT + " WHERE " + Constants . GENERIC_CLIENT_UUID + "= '-1' " + " AND " + Constants . GENERIC_PROFILE_ID + "= ? " ) ; queryStatement . setInt ( 1 , profileId ) ; logger . info ( queryStatement . toString ( ) ) ; ResultSet results = queryStatement . executeQuery ( ) ; if ( results . next ( ) ) { active = results . getBoolean ( Constants . CLIENT_IS_ACTIVE ) ; } } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( queryStatement != null ) { queryStatement . close ( ) ; } } catch ( Exception e ) { } } return active ; } | Returns true if the default profile for the specified uuid is active |
28,012 | public List < Profile > findAllProfiles ( ) throws Exception { ArrayList < Profile > allProfiles = new ArrayList < > ( ) ; PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "SELECT * FROM " + Constants . DB_TABLE_PROFILE ) ; results = statement . executeQuery ( ) ; while ( results . next ( ) ) { allProfiles . add ( this . getProfileFromResultSet ( results ) ) ; } } catch ( Exception e ) { throw e ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } return allProfiles ; } | Returns a collection of all profiles |
28,013 | public Profile findProfile ( int profileId ) throws Exception { Profile profile = null ; PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "SELECT * FROM " + Constants . DB_TABLE_PROFILE + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setInt ( 1 , profileId ) ; results = statement . executeQuery ( ) ; if ( results . next ( ) ) { profile = this . getProfileFromResultSet ( results ) ; } } catch ( Exception e ) { throw e ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } return profile ; } | Returns a specific profile |
28,014 | private Profile getProfileFromResultSet ( ResultSet result ) throws Exception { Profile profile = new Profile ( ) ; profile . setId ( result . getInt ( Constants . GENERIC_ID ) ) ; Clob clobProfileName = result . getClob ( Constants . PROFILE_PROFILE_NAME ) ; String profileName = clobProfileName . getSubString ( 1 , ( int ) clobProfileName . length ( ) ) ; profile . setName ( profileName ) ; return profile ; } | Creates a Profile object from a SQL resultset |
28,015 | public Profile add ( String profileName ) throws Exception { Profile profile = new Profile ( ) ; int id = - 1 ; PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { Clob clobProfileName = sqlService . toClob ( profileName , sqlConnection ) ; statement = sqlConnection . prepareStatement ( "INSERT INTO " + Constants . DB_TABLE_PROFILE + "(" + Constants . PROFILE_PROFILE_NAME + ") " + " VALUES (?)" , PreparedStatement . RETURN_GENERATED_KEYS ) ; statement . setClob ( 1 , clobProfileName ) ; statement . executeUpdate ( ) ; results = statement . getGeneratedKeys ( ) ; if ( results . next ( ) ) { id = results . getInt ( 1 ) ; } else { throw new Exception ( "Could not add client" ) ; } results . close ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "INSERT INTO " + Constants . DB_TABLE_CLIENT + "(" + Constants . CLIENT_CLIENT_UUID + "," + Constants . CLIENT_IS_ACTIVE + "," + Constants . CLIENT_PROFILE_ID + ") " + " VALUES (?, ?, ?)" ) ; statement . setString ( 1 , Constants . PROFILE_CLIENT_DEFAULT_ID ) ; statement . setBoolean ( 2 , false ) ; statement . setInt ( 3 , id ) ; statement . executeUpdate ( ) ; profile . setName ( profileName ) ; profile . setId ( id ) ; } catch ( SQLException e ) { throw e ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } return profile ; } | Add a new profile with the profileName given . |
28,016 | public void remove ( int profileId ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { statement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_PROFILE + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setInt ( 1 , profileId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_SERVERS + " WHERE " + Constants . GENERIC_PROFILE_ID + " = ?" ) ; statement . setInt ( 1 , profileId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_PATH + " WHERE " + Constants . GENERIC_PROFILE_ID + " = ?" ) ; statement . setInt ( 1 , profileId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_ENABLED_OVERRIDE + " WHERE " + Constants . GENERIC_PROFILE_ID + " = ?" ) ; statement . setInt ( 1 , profileId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_CLIENT + " WHERE " + Constants . GENERIC_PROFILE_ID + " = ?" ) ; statement . setInt ( 1 , profileId ) ; statement . executeUpdate ( ) ; statement . close ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Deletes data associated with the given profile ID |
28,017 | public String getNamefromId ( int id ) { return ( String ) sqlService . getFromTable ( Constants . PROFILE_PROFILE_NAME , Constants . GENERIC_ID , id , Constants . DB_TABLE_PROFILE ) ; } | Obtain the profile name associated with a profile ID |
28,018 | public Integer getIdFromName ( String profileName ) { PreparedStatement query = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { query = sqlConnection . prepareStatement ( "SELECT * FROM " + Constants . DB_TABLE_PROFILE + " WHERE " + Constants . PROFILE_PROFILE_NAME + " = ?" ) ; query . setString ( 1 , profileName ) ; results = query . executeQuery ( ) ; if ( results . next ( ) ) { Object toReturn = results . getObject ( Constants . GENERIC_ID ) ; query . close ( ) ; return ( Integer ) toReturn ; } query . close ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( query != null ) { query . close ( ) ; } } catch ( Exception e ) { } } return null ; } | Obtain the ID associated with a profile name |
28,019 | public static Integer convertPathIdentifier ( String identifier , Integer profileId ) throws Exception { Integer pathId = - 1 ; try { pathId = Integer . parseInt ( identifier ) ; } catch ( NumberFormatException ne ) { if ( profileId == null ) throw new Exception ( "A profileId must be specified" ) ; pathId = PathOverrideService . getInstance ( ) . getPathId ( identifier , profileId ) ; } return pathId ; } | Obtain the path ID for a profile |
28,020 | public static Integer convertProfileIdentifier ( String profileIdentifier ) throws Exception { Integer profileId = - 1 ; if ( profileIdentifier == null ) { throw new Exception ( "A profileIdentifier must be specified" ) ; } else { try { profileId = Integer . parseInt ( profileIdentifier ) ; } catch ( NumberFormatException ne ) { profileId = ProfileService . getInstance ( ) . getIdFromName ( profileIdentifier ) ; } } logger . info ( "Profile id is {}" , profileId ) ; return profileId ; } | Obtain the profile identifier . |
28,021 | public static Integer convertOverrideIdentifier ( String overrideIdentifier ) throws Exception { Integer overrideId = - 1 ; try { boolean isNegative = false ; if ( overrideIdentifier . startsWith ( "-" ) ) { isNegative = true ; overrideIdentifier = overrideIdentifier . substring ( 1 ) ; } overrideId = Integer . parseInt ( overrideIdentifier ) ; if ( isNegative ) { overrideId = 0 - overrideId ; } } catch ( NumberFormatException ne ) { String className = null ; String methodName = null ; int lastDot = overrideIdentifier . lastIndexOf ( "." ) ; className = overrideIdentifier . substring ( 0 , lastDot ) ; methodName = overrideIdentifier . substring ( lastDot + 1 ) ; overrideId = OverrideService . getInstance ( ) . getOverrideIdForMethod ( className , methodName ) ; } return overrideId ; } | Obtain override ID |
28,022 | public static Identifiers convertProfileAndPathIdentifier ( String profileIdentifier , String pathIdentifier ) throws Exception { Identifiers id = new Identifiers ( ) ; Integer profileId = null ; try { profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; } catch ( Exception e ) { } Integer pathId = convertPathIdentifier ( pathIdentifier , profileId ) ; id . setProfileId ( profileId ) ; id . setPathId ( pathId ) ; return id ; } | Obtain the IDs of profile and path as Identifiers |
28,023 | public JSONObject getPathFromEndpoint ( String pathValue , String requestType ) throws Exception { int type = getRequestTypeFromString ( requestType ) ; String url = BASE_PATH ; JSONObject response = new JSONObject ( doGet ( url , null ) ) ; JSONArray paths = response . getJSONArray ( "paths" ) ; for ( int i = 0 ; i < paths . length ( ) ; i ++ ) { JSONObject path = paths . getJSONObject ( i ) ; if ( path . getString ( "path" ) . equals ( pathValue ) && path . getInt ( "requestType" ) == type ) { return path ; } } return null ; } | Retrieves the path using the endpoint value |
28,024 | public static boolean setDefaultCustomResponse ( String pathValue , String requestType , String customData ) { try { JSONObject profile = getDefaultProfile ( ) ; String profileName = profile . getString ( "name" ) ; PathValueClient client = new PathValueClient ( profileName , false ) ; return client . setCustomResponse ( pathValue , requestType , customData ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Sets a custom response on an endpoint using default profile and client |
28,025 | public static boolean removeDefaultCustomResponse ( String pathValue , String requestType ) { try { JSONObject profile = getDefaultProfile ( ) ; String profileName = profile . getString ( "name" ) ; PathValueClient client = new PathValueClient ( profileName , false ) ; return client . removeCustomResponse ( pathValue , requestType ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Remove any overrides for an endpoint on the default profile client |
28,026 | public boolean removeCustomResponse ( String pathValue , String requestType ) { try { JSONObject path = getPathFromEndpoint ( pathValue , requestType ) ; if ( path == null ) { return false ; } String pathId = path . getString ( "pathId" ) ; return resetResponseOverride ( pathId ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Remove any overrides for an endpoint |
28,027 | public boolean setCustomResponse ( String pathValue , String requestType , String customData ) { try { JSONObject path = getPathFromEndpoint ( pathValue , requestType ) ; if ( path == null ) { String pathName = pathValue ; createPath ( pathName , pathValue , requestType ) ; path = getPathFromEndpoint ( pathValue , requestType ) ; } String pathId = path . getString ( "pathId" ) ; resetResponseOverride ( pathId ) ; setCustomResponse ( pathId , customData ) ; return toggleResponseOverride ( pathId , true ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Sets a custom response on an endpoint |
28,028 | @ RequestMapping ( value = "/api/profile/{profileIdentifier}/clients" , method = RequestMethod . GET ) public HashMap < String , Object > getClientList ( Model model , @ PathVariable ( "profileIdentifier" ) String profileIdentifier ) throws Exception { Integer profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; return Utils . getJQGridJSON ( clientService . findAllClients ( profileId ) , "clients" ) ; } | Returns information about all clients for a profile |
28,029 | @ RequestMapping ( value = "/api/profile/{profileIdentifier}/clients/{clientUUID}" , method = RequestMethod . GET ) public HashMap < String , Object > getClient ( Model model , @ PathVariable ( "profileIdentifier" ) String profileIdentifier , @ PathVariable ( "clientUUID" ) String clientUUID ) throws Exception { Integer profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; HashMap < String , Object > valueHash = new HashMap < String , Object > ( ) ; valueHash . put ( "client" , clientService . findClient ( clientUUID , profileId ) ) ; return valueHash ; } | Returns information for a specific client |
28,030 | @ RequestMapping ( value = "/api/profile/{profileIdentifier}/clients" , method = RequestMethod . POST ) public HashMap < String , Object > addClient ( Model model , @ PathVariable ( "profileIdentifier" ) String profileIdentifier , @ RequestParam ( required = false ) String friendlyName ) throws Exception { Integer profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; if ( null != clientService . findClientFromFriendlyName ( profileId , friendlyName ) ) { throw new Exception ( "Cannot add client. Friendly name already in use." ) ; } Client client = clientService . add ( profileId ) ; if ( friendlyName != null ) { clientService . setFriendlyName ( profileId , client . getUUID ( ) , friendlyName ) ; client . setFriendlyName ( friendlyName ) ; } HashMap < String , Object > valueHash = new HashMap < String , Object > ( ) ; valueHash . put ( "client" , client ) ; return valueHash ; } | Returns a new client id for the profileIdentifier |
28,031 | @ RequestMapping ( value = "/api/profile/{profileIdentifier}/clients/{clientUUID}" , method = RequestMethod . POST ) public HashMap < String , Object > updateClient ( Model model , @ PathVariable ( "profileIdentifier" ) String profileIdentifier , @ PathVariable ( "clientUUID" ) String clientUUID , @ RequestParam ( required = false ) Boolean active , @ RequestParam ( required = false ) String friendlyName , @ RequestParam ( required = false ) Boolean reset ) throws Exception { Integer profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; if ( active != null ) { logger . info ( "Active: {}" , active ) ; clientService . updateActive ( profileId , clientUUID , active ) ; } if ( friendlyName != null ) { clientService . setFriendlyName ( profileId , clientUUID , friendlyName ) ; } if ( reset != null && reset ) { clientService . reset ( profileId , clientUUID ) ; } HashMap < String , Object > valueHash = new HashMap < String , Object > ( ) ; valueHash . put ( "client" , clientService . findClient ( clientUUID , profileId ) ) ; return valueHash ; } | Update properties for a specific client id |
28,032 | @ RequestMapping ( value = "/api/profile/{profileIdentifier}/clients/{clientUUID}" , method = RequestMethod . DELETE ) public HashMap < String , Object > deleteClient ( Model model , @ PathVariable ( "profileIdentifier" ) String profileIdentifier , @ PathVariable ( "clientUUID" ) String clientUUID ) throws Exception { logger . info ( "Attempting to remove the following client: {}" , clientUUID ) ; if ( clientUUID . compareTo ( Constants . PROFILE_CLIENT_DEFAULT_ID ) == 0 ) throw new Exception ( "Default client cannot be deleted" ) ; Integer profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; clientService . remove ( profileId , clientUUID ) ; HashMap < String , Object > valueHash = new HashMap < String , Object > ( ) ; valueHash . put ( "clients" , clientService . findAllClients ( profileId ) ) ; return valueHash ; } | Deletes a specific client id for a profile |
28,033 | @ RequestMapping ( value = "/api/profile/{profileIdentifier}/clients/delete" , method = RequestMethod . POST ) public HashMap < String , Object > deleteClient ( Model model , @ RequestParam ( "profileIdentifier" ) String profileIdentifier , @ RequestParam ( "clientUUID" ) String [ ] clientUUID ) throws Exception { logger . info ( "Attempting to remove clients from the profile: " , profileIdentifier ) ; logger . info ( "Attempting to remove the following clients: {}" , Arrays . toString ( clientUUID ) ) ; HashMap < String , Object > valueHash = new HashMap < String , Object > ( ) ; Integer profileId = ControllerUtils . convertProfileIdentifier ( profileIdentifier ) ; for ( int i = 0 ; i < clientUUID . length ; i ++ ) { if ( clientUUID [ i ] . compareTo ( Constants . PROFILE_CLIENT_DEFAULT_ID ) == 0 ) throw new Exception ( "Default client cannot be deleted" ) ; clientService . remove ( profileId , clientUUID [ i ] ) ; } valueHash . put ( "clients" , clientService . findAllClients ( profileId ) ) ; return valueHash ; } | Bulk delete clients from a profile . |
28,034 | @ RequestMapping ( value = "/api/plugins" , method = RequestMethod . GET ) public HashMap < String , Object > getPluginInformation ( ) { return pluginInformation ( ) ; } | Obtain plugin information |
28,035 | @ RequestMapping ( value = "/api/plugins" , method = RequestMethod . POST ) public HashMap < String , Object > addPluginPath ( Model model , Plugin add ) throws Exception { PluginManager . getInstance ( ) . addPluginPath ( add . getPath ( ) ) ; return pluginInformation ( ) ; } | Add a plugin path |
28,036 | public static void addOverrideToPath ( ) throws Exception { Client client = new Client ( "ProfileName" , false ) ; client . addMethodToResponseOverride ( "Test Path" , "com.groupon.odo.sample.Common.delay" ) ; client . setMethodArguments ( "Test Path" , "com.groupon.odo.sample.Common.delay" , 1 , "100" ) ; } | Demonstrates how to add an override to an existing path |
28,037 | public static void getHistory ( ) throws Exception { Client client = new Client ( "ProfileName" , false ) ; History [ ] history = client . refreshHistory ( 100 , 0 ) ; client . clearHistory ( ) ; } | Demonstrates obtaining the request history data from a test run |
28,038 | @ RequestMapping ( value = "/profiles" , method = RequestMethod . GET ) public String list ( Model model ) { Profile profiles = new Profile ( ) ; model . addAttribute ( "addNewProfile" , profiles ) ; model . addAttribute ( "version" , Constants . VERSION ) ; logger . info ( "Loading initial page" ) ; return "profiles" ; } | This is the profiles page . this is the regular page when the url is typed in |
28,039 | @ RequestMapping ( value = "/api/profile" , method = RequestMethod . GET ) public HashMap < String , Object > getList ( Model model ) throws Exception { logger . info ( "Using a GET request to list profiles" ) ; return Utils . getJQGridJSON ( profileService . findAllProfiles ( ) , "profiles" ) ; } | Obtain collection of profiles |
28,040 | @ RequestMapping ( value = "/api/profile" , method = RequestMethod . POST ) public HashMap < String , Object > addProfile ( Model model , String name ) throws Exception { logger . info ( "Should be adding the profile name when I hit the enter button={}" , name ) ; return Utils . getJQGridJSON ( profileService . add ( name ) , "profile" ) ; } | Add profile to database return collection of profile data . Called when enter is hit in the UI instead of submit button |
28,041 | @ RequestMapping ( value = "/api/profile" , method = RequestMethod . DELETE ) public HashMap < String , Object > deleteProfile ( Model model , int id ) throws Exception { profileService . remove ( id ) ; return Utils . getJQGridJSON ( profileService . findAllProfiles ( ) , "profiles" ) ; } | Delete a profile |
28,042 | public void cullHistory ( final int profileId , final String clientUUID , final int limit ) throws Exception { if ( threadActive ) { return ; } threadActive = true ; Thread t1 = new Thread ( new Runnable ( ) { public void run ( ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { String sqlQuery = "SELECT COUNT(" + Constants . GENERIC_ID + ") FROM " + Constants . DB_TABLE_HISTORY + " " ; if ( profileId != - 1 ) { sqlQuery += "WHERE " + Constants . GENERIC_PROFILE_ID + "=" + profileId + " " ; } if ( clientUUID != null && clientUUID . compareTo ( "" ) != 0 ) { sqlQuery += "AND " + Constants . GENERIC_CLIENT_UUID + "='" + clientUUID + "' " ; } sqlQuery += ";" ; Statement query = sqlConnection . createStatement ( ) ; ResultSet results = query . executeQuery ( sqlQuery ) ; if ( results . next ( ) ) { if ( results . getInt ( "COUNT(" + Constants . GENERIC_ID + ")" ) < ( limit + 10000 ) ) { return ; } } statement = sqlConnection . prepareStatement ( "SELECT " + Constants . GENERIC_ID + " FROM " + Constants . DB_TABLE_HISTORY + " WHERE " + Constants . CLIENT_CLIENT_UUID + " = \'" + clientUUID + "\'" + " AND " + Constants . CLIENT_PROFILE_ID + " = " + profileId + " ORDER BY " + Constants . GENERIC_ID + " ASC LIMIT 1" ) ; ResultSet resultSet = statement . executeQuery ( ) ; if ( resultSet . next ( ) ) { int currentSpot = resultSet . getInt ( Constants . GENERIC_ID ) + 100 ; int finalDelete = currentSpot + 10000 ; while ( currentSpot < finalDelete ) { PreparedStatement deleteStatement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_HISTORY + " WHERE " + Constants . CLIENT_CLIENT_UUID + " = \'" + clientUUID + "\'" + " AND " + Constants . CLIENT_PROFILE_ID + " = " + profileId + " AND " + Constants . GENERIC_ID + " < " + currentSpot ) ; deleteStatement . executeUpdate ( ) ; currentSpot += 100 ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { try { threadActive = false ; if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } } ) ; t1 . start ( ) ; } | Removes old entries in the history table for the given profile and client UUID |
28,043 | public int getHistoryCount ( int profileId , String clientUUID , HashMap < String , String [ ] > searchFilter ) { int count = 0 ; Statement query = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { String sqlQuery = "SELECT COUNT(" + Constants . GENERIC_ID + ") FROM " + Constants . DB_TABLE_HISTORY + " " ; if ( profileId != - 1 ) { sqlQuery += "WHERE " + Constants . GENERIC_PROFILE_ID + "=" + profileId + " " ; } if ( clientUUID != null && clientUUID . compareTo ( "" ) != 0 ) { sqlQuery += "AND " + Constants . GENERIC_CLIENT_UUID + "='" + clientUUID + "' " ; } sqlQuery += ";" ; logger . info ( "Query: {}" , sqlQuery ) ; query = sqlConnection . createStatement ( ) ; results = query . executeQuery ( sqlQuery ) ; if ( results . next ( ) ) { count = results . getInt ( 1 ) ; } query . close ( ) ; } catch ( Exception e ) { } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( query != null ) { query . close ( ) ; } } catch ( Exception e ) { } } return count ; } | Returns the number of history entries for a client |
28,044 | public History getHistoryForID ( int id ) { History history = null ; PreparedStatement query = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { query = sqlConnection . prepareStatement ( "SELECT * FROM " + Constants . DB_TABLE_HISTORY + " WHERE " + Constants . GENERIC_ID + "=?" ) ; query . setInt ( 1 , id ) ; logger . info ( "Query: {}" , query . toString ( ) ) ; results = query . executeQuery ( ) ; if ( results . next ( ) ) { history = historyFromSQLResult ( results , true , ScriptService . getInstance ( ) . getScripts ( Constants . SCRIPT_TYPE_HISTORY ) ) ; } query . close ( ) ; } catch ( Exception e ) { } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( query != null ) { query . close ( ) ; } } catch ( Exception e ) { } } return history ; } | Get history for a specific database ID |
28,045 | public void clearHistory ( int profileId , String clientUUID ) { PreparedStatement query = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { String sqlQuery = "DELETE FROM " + Constants . DB_TABLE_HISTORY + " " ; if ( profileId != - 1 ) { sqlQuery += "WHERE " + Constants . GENERIC_PROFILE_ID + "=" + profileId ; } if ( clientUUID != null && clientUUID . compareTo ( "" ) != 0 ) { sqlQuery += " AND " + Constants . GENERIC_CLIENT_UUID + "='" + clientUUID + "'" ; } sqlQuery += ";" ; logger . info ( "Query: {}" , sqlQuery ) ; query = sqlConnection . prepareStatement ( sqlQuery ) ; query . executeUpdate ( ) ; } catch ( Exception e ) { } finally { try { if ( query != null ) { query . close ( ) ; } } catch ( Exception e ) { } } } | Clear history for a client |
28,046 | public void destroy ( ) throws Exception { if ( _clientId == null ) { return ; } String uri = BASE_PROFILE + uriEncode ( _profileName ) + "/" + BASE_CLIENTS + "/" + _clientId ; try { doDelete ( uri , null ) ; } catch ( Exception e ) { throw new Exception ( "Could not delete a proxy client" ) ; } } | Call when you are done with the client |
28,047 | public void setHostName ( String hostName ) { if ( hostName == null || hostName . contains ( ":" ) ) { return ; } ODO_HOST = hostName ; BASE_URL = "http://" + ODO_HOST + ":" + API_PORT + "/" + API_BASE + "/" ; } | Set the host running the Odo instance to configure |
28,048 | public static void setDefaultHostName ( String hostName ) { if ( hostName == null || hostName . contains ( ":" ) ) { return ; } DEFAULT_BASE_URL = "http://" + hostName + ":" + DEFAULT_API_PORT + "/" + API_BASE + "/" ; } | Set the default host running the Odo instance to configure . Allows default profile methods and PathValueClient to operate on remote hosts |
28,049 | public History [ ] filterHistory ( String ... filters ) throws Exception { BasicNameValuePair [ ] params ; if ( filters . length > 0 ) { params = new BasicNameValuePair [ filters . length ] ; for ( int i = 0 ; i < filters . length ; i ++ ) { params [ i ] = new BasicNameValuePair ( "source_uri[]" , filters [ i ] ) ; } } else { return refreshHistory ( ) ; } return constructHistory ( params ) ; } | Retrieve the request History based on the specified filters . If no filter is specified return the default size history . |
28,050 | public History [ ] refreshHistory ( int limit , int offset ) throws Exception { BasicNameValuePair [ ] params = { new BasicNameValuePair ( "limit" , String . valueOf ( limit ) ) , new BasicNameValuePair ( "offset" , String . valueOf ( offset ) ) } ; return constructHistory ( params ) ; } | refresh the most recent history entries |
28,051 | public void clearHistory ( ) throws Exception { String uri ; try { uri = HISTORY + uriEncode ( _profileName ) ; doDelete ( uri , null ) ; } catch ( Exception e ) { throw new Exception ( "Could not delete proxy history" ) ; } } | Delete the proxy history for the active profile |
28,052 | public boolean toggleProfile ( Boolean enabled ) { BasicNameValuePair [ ] params = { new BasicNameValuePair ( "active" , enabled . toString ( ) ) } ; try { String uri = BASE_PROFILE + uriEncode ( this . _profileName ) + "/" + BASE_CLIENTS + "/" ; if ( _clientId == null ) { uri += "-1" ; } else { uri += _clientId ; } JSONObject response = new JSONObject ( doPost ( uri , params ) ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; return false ; } return true ; } | Turn this profile on or off |
28,053 | public boolean setCustomResponse ( String pathName , String customResponse ) throws Exception { int nextOrdinal = this . getNextOrdinalForMethodId ( - 1 , pathName ) ; this . addMethodToResponseOverride ( pathName , "-1" ) ; return this . setMethodArguments ( pathName , "-1" , nextOrdinal , customResponse ) ; } | Set a custom response for this path |
28,054 | public boolean addMethodToResponseOverride ( String pathName , String methodName ) { try { Integer overrideId = getOverrideIdForMethodName ( methodName ) ; BasicNameValuePair [ ] params = { new BasicNameValuePair ( "addOverride" , overrideId . toString ( ) ) , new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) } ; JSONObject response = new JSONObject ( doPost ( BASE_PATH + uriEncode ( pathName ) , params ) ) ; JSONArray enabled = response . getJSONArray ( "enabledEndpoints" ) ; for ( int x = 0 ; x < enabled . length ( ) ; x ++ ) { if ( enabled . getJSONObject ( x ) . getInt ( "overrideId" ) == overrideId ) { return true ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Add a method to the enabled response overrides for a path |
28,055 | public boolean setOverrideRepeatCount ( String pathName , String methodName , Integer ordinal , Integer repeatCount ) { try { String methodId = getOverrideIdForMethodName ( methodName ) . toString ( ) ; BasicNameValuePair [ ] params = { new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) , new BasicNameValuePair ( "ordinal" , ordinal . toString ( ) ) , new BasicNameValuePair ( "repeatNumber" , repeatCount . toString ( ) ) } ; JSONObject response = new JSONObject ( doPost ( BASE_PATH + uriEncode ( pathName ) + "/" + methodId , params ) ) ; return true ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Set the repeat count of an override at ordinal index |
28,056 | public boolean setMethodArguments ( String pathName , String methodName , Integer ordinal , Object ... arguments ) { try { BasicNameValuePair [ ] params = new BasicNameValuePair [ arguments . length + 2 ] ; int x = 0 ; for ( Object argument : arguments ) { params [ x ] = new BasicNameValuePair ( "arguments[]" , argument . toString ( ) ) ; x ++ ; } params [ x ] = new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) ; params [ x + 1 ] = new BasicNameValuePair ( "ordinal" , ordinal . toString ( ) ) ; JSONObject response = new JSONObject ( doPost ( BASE_PATH + uriEncode ( pathName ) + "/" + methodName , params ) ) ; return true ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | Set the method arguments for an enabled method override |
28,057 | public void createPath ( String pathName , String pathValue , String requestType ) { try { int type = getRequestTypeFromString ( requestType ) ; String url = BASE_PATH ; BasicNameValuePair [ ] params = { new BasicNameValuePair ( "pathName" , pathName ) , new BasicNameValuePair ( "path" , pathValue ) , new BasicNameValuePair ( "requestType" , String . valueOf ( type ) ) , new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) } ; JSONObject response = new JSONObject ( doPost ( BASE_PATH , params ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } | Create a new path |
28,058 | protected static boolean setCustomForDefaultClient ( String profileName , String pathName , Boolean isResponse , String customData ) { try { Client client = new Client ( profileName , false ) ; client . toggleProfile ( true ) ; client . setCustom ( isResponse , pathName , customData ) ; if ( isResponse ) { client . toggleResponseOverride ( pathName , true ) ; } else { client . toggleRequestOverride ( pathName , true ) ; } return true ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | set custom response or request for a profile s default client ensures profile and path are enabled |
28,059 | public static boolean setCustomRequestForDefaultClient ( String profileName , String pathName , String customData ) { try { return setCustomForDefaultClient ( profileName , pathName , false , customData ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | set custom request for profile s default client |
28,060 | public static boolean setCustomResponseForDefaultClient ( String profileName , String pathName , String customData ) { try { return setCustomForDefaultClient ( profileName , pathName , true , customData ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | set custom response for profile s default client |
28,061 | public static boolean setCustomRequestForDefaultProfile ( String pathName , String customData ) { try { return setCustomForDefaultProfile ( pathName , false , customData ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | set custom request for the default profile s default client |
28,062 | public static boolean setCustomResponseForDefaultProfile ( String pathName , String customData ) { try { return setCustomForDefaultProfile ( pathName , true , customData ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return false ; } | set custom response for the default profile s default client |
28,063 | protected static JSONObject getDefaultProfile ( ) throws Exception { String uri = DEFAULT_BASE_URL + BASE_PROFILE ; try { JSONObject response = new JSONObject ( doGet ( uri , 60000 ) ) ; JSONArray profiles = response . getJSONArray ( "profiles" ) ; if ( profiles . length ( ) > 0 ) { return profiles . getJSONObject ( 0 ) ; } } catch ( Exception e ) { throw new Exception ( "Could not create a proxy client" ) ; } return null ; } | get the default profile |
28,064 | private Integer getNextOrdinalForMethodId ( int methodId , String pathName ) throws Exception { String pathInfo = doGet ( BASE_PATH + uriEncode ( pathName ) , new BasicNameValuePair [ 0 ] ) ; JSONObject pathResponse = new JSONObject ( pathInfo ) ; JSONArray enabledEndpoints = pathResponse . getJSONArray ( "enabledEndpoints" ) ; int lastOrdinal = 0 ; for ( int x = 0 ; x < enabledEndpoints . length ( ) ; x ++ ) { if ( enabledEndpoints . getJSONObject ( x ) . getInt ( "overrideId" ) == methodId ) { lastOrdinal ++ ; } } return lastOrdinal + 1 ; } | Get the next available ordinal for a method ID |
28,065 | protected int getRequestTypeFromString ( String requestType ) { if ( "GET" . equals ( requestType ) ) { return REQUEST_TYPE_GET ; } if ( "POST" . equals ( requestType ) ) { return REQUEST_TYPE_POST ; } if ( "PUT" . equals ( requestType ) ) { return REQUEST_TYPE_PUT ; } if ( "DELETE" . equals ( requestType ) ) { return REQUEST_TYPE_DELETE ; } return REQUEST_TYPE_ALL ; } | Convert a request type string to value |
28,066 | public ServerRedirect addServerMapping ( String sourceHost , String destinationHost , String hostHeader ) { JSONObject response = null ; ArrayList < BasicNameValuePair > params = new ArrayList < BasicNameValuePair > ( ) ; params . add ( new BasicNameValuePair ( "srcUrl" , sourceHost ) ) ; params . add ( new BasicNameValuePair ( "destUrl" , destinationHost ) ) ; params . add ( new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) ) ; if ( hostHeader != null ) { params . add ( new BasicNameValuePair ( "hostHeader" , hostHeader ) ) ; } try { BasicNameValuePair paramArray [ ] = new BasicNameValuePair [ params . size ( ) ] ; params . toArray ( paramArray ) ; response = new JSONObject ( doPost ( BASE_SERVER , paramArray ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return getServerRedirectFromJSON ( response ) ; } | Add a new server mapping to current profile |
28,067 | public List < ServerRedirect > deleteServerMapping ( int serverMappingId ) { ArrayList < ServerRedirect > servers = new ArrayList < ServerRedirect > ( ) ; try { JSONArray serverArray = new JSONArray ( doDelete ( BASE_SERVER + "/" + serverMappingId , null ) ) ; for ( int i = 0 ; i < serverArray . length ( ) ; i ++ ) { JSONObject jsonServer = serverArray . getJSONObject ( i ) ; ServerRedirect server = getServerRedirectFromJSON ( jsonServer ) ; if ( server != null ) { servers . add ( server ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return servers ; } | Remove a server mapping from current profile by ID |
28,068 | public List < ServerRedirect > getServerMappings ( ) { ArrayList < ServerRedirect > servers = new ArrayList < ServerRedirect > ( ) ; try { JSONObject response = new JSONObject ( doGet ( BASE_SERVER , null ) ) ; JSONArray serverArray = response . getJSONArray ( "servers" ) ; for ( int i = 0 ; i < serverArray . length ( ) ; i ++ ) { JSONObject jsonServer = serverArray . getJSONObject ( i ) ; ServerRedirect server = getServerRedirectFromJSON ( jsonServer ) ; if ( server != null ) { servers . add ( server ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return servers ; } | Get a list of all active server mappings defined for current profile |
28,069 | public ServerRedirect updateServerRedirectHost ( int serverMappingId , String hostHeader ) { ServerRedirect redirect = new ServerRedirect ( ) ; BasicNameValuePair [ ] params = { new BasicNameValuePair ( "hostHeader" , hostHeader ) , new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) } ; try { JSONObject response = new JSONObject ( doPost ( BASE_SERVER + "/" + serverMappingId + "/host" , params ) ) ; redirect = getServerRedirectFromJSON ( response ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return redirect ; } | Update server mapping s host header |
28,070 | public ServerGroup addServerGroup ( String groupName ) { ServerGroup group = new ServerGroup ( ) ; BasicNameValuePair [ ] params = { new BasicNameValuePair ( "name" , groupName ) , new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) } ; try { JSONObject response = new JSONObject ( doPost ( BASE_SERVERGROUP , params ) ) ; group = getServerGroupFromJSON ( response ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return group ; } | Create a new server group |
28,071 | public List < ServerGroup > getServerGroups ( ) { ArrayList < ServerGroup > groups = new ArrayList < ServerGroup > ( ) ; try { JSONObject response = new JSONObject ( doGet ( BASE_SERVERGROUP , null ) ) ; JSONArray serverArray = response . getJSONArray ( "servergroups" ) ; for ( int i = 0 ; i < serverArray . length ( ) ; i ++ ) { JSONObject jsonServerGroup = serverArray . getJSONObject ( i ) ; ServerGroup group = getServerGroupFromJSON ( jsonServerGroup ) ; groups . add ( group ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return groups ; } | Get the collection of the server groups |
28,072 | public ServerGroup updateServerGroupName ( int serverGroupId , String name ) { ServerGroup serverGroup = null ; BasicNameValuePair [ ] params = { new BasicNameValuePair ( "name" , name ) , new BasicNameValuePair ( "profileIdentifier" , this . _profileName ) } ; try { JSONObject response = new JSONObject ( doPost ( BASE_SERVERGROUP + "/" + serverGroupId , params ) ) ; serverGroup = getServerGroupFromJSON ( response ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } return serverGroup ; } | Update the server group s name |
28,073 | public boolean uploadConfigurationAndProfile ( String fileName , String odoImport ) { File file = new File ( fileName ) ; MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder . create ( ) ; FileBody fileBody = new FileBody ( file , ContentType . MULTIPART_FORM_DATA ) ; multipartEntityBuilder . setMode ( HttpMultipartMode . BROWSER_COMPATIBLE ) ; multipartEntityBuilder . addPart ( "fileData" , fileBody ) ; multipartEntityBuilder . addTextBody ( "odoImport" , odoImport ) ; try { JSONObject response = new JSONObject ( doMultipartPost ( BASE_BACKUP_PROFILE + "/" + uriEncode ( this . _profileName ) + "/" + this . _clientId , multipartEntityBuilder ) ) ; if ( response . length ( ) == 0 ) { return true ; } else { return false ; } } catch ( Exception e ) { return false ; } } | Upload file and set odo overrides and configuration of odo |
28,074 | public JSONObject exportConfigurationAndProfile ( String oldExport ) { try { BasicNameValuePair [ ] params = { new BasicNameValuePair ( "oldExport" , oldExport ) } ; String url = BASE_BACKUP_PROFILE + "/" + uriEncode ( this . _profileName ) + "/" + this . _clientId ; return new JSONObject ( doGet ( url , new BasicNameValuePair [ ] { } ) ) ; } catch ( Exception e ) { return new JSONObject ( ) ; } } | Export the odo overrides setup and odo configuration |
28,075 | private List < Group > getGroups ( ) throws Exception { List < Group > groups = new ArrayList < Group > ( ) ; List < Group > sourceGroups = PathOverrideService . getInstance ( ) . findAllGroups ( ) ; for ( Group sourceGroup : sourceGroups ) { Group group = new Group ( ) ; ArrayList < Method > methods = new ArrayList < Method > ( ) ; for ( Method sourceMethod : EditService . getInstance ( ) . getMethodsFromGroupId ( sourceGroup . getId ( ) , null ) ) { Method method = new Method ( ) ; method . setClassName ( sourceMethod . getClassName ( ) ) ; method . setMethodName ( sourceMethod . getMethodName ( ) ) ; methods . add ( method ) ; } group . setMethods ( methods ) ; group . setName ( sourceGroup . getName ( ) ) ; groups . add ( group ) ; } return groups ; } | Get all Groups |
28,076 | public SingleProfileBackup getProfileBackupData ( int profileID , String clientUUID ) throws Exception { SingleProfileBackup singleProfileBackup = new SingleProfileBackup ( ) ; List < PathOverride > enabledPaths = new ArrayList < > ( ) ; List < EndpointOverride > paths = PathOverrideService . getInstance ( ) . getPaths ( profileID , clientUUID , null ) ; for ( EndpointOverride override : paths ) { if ( override . getRequestEnabled ( ) || override . getResponseEnabled ( ) ) { PathOverride pathOverride = new PathOverride ( ) ; pathOverride . setPathName ( override . getPathName ( ) ) ; if ( override . getRequestEnabled ( ) ) { pathOverride . setRequestEnabled ( true ) ; } if ( override . getResponseEnabled ( ) ) { pathOverride . setResponseEnabled ( true ) ; } pathOverride . setEnabledEndpoints ( override . getEnabledEndpoints ( ) ) ; enabledPaths . add ( pathOverride ) ; } } singleProfileBackup . setEnabledPaths ( enabledPaths ) ; Client backupClient = ClientService . getInstance ( ) . findClient ( clientUUID , profileID ) ; ServerGroup activeServerGroup = ServerRedirectService . getInstance ( ) . getServerGroup ( backupClient . getActiveServerGroup ( ) , profileID ) ; singleProfileBackup . setActiveServerGroup ( activeServerGroup ) ; return singleProfileBackup ; } | Get the active overrides with parameters and the active server group for a client |
28,077 | public Backup getBackupData ( ) throws Exception { Backup backupData = new Backup ( ) ; backupData . setGroups ( getGroups ( ) ) ; backupData . setProfiles ( getProfiles ( ) ) ; ArrayList < Script > scripts = new ArrayList < Script > ( ) ; Collections . addAll ( scripts , ScriptService . getInstance ( ) . getScripts ( ) ) ; backupData . setScripts ( scripts ) ; return backupData ; } | Return the structured backup data |
28,078 | private MBeanServer getServerForName ( String name ) { try { MBeanServer mbeanServer = null ; final ObjectName objectNameQuery = new ObjectName ( name + ":type=Service,*" ) ; for ( final MBeanServer server : MBeanServerFactory . findMBeanServer ( null ) ) { if ( server . queryNames ( objectNameQuery , null ) . size ( ) > 0 ) { mbeanServer = server ; break ; } } return mbeanServer ; } catch ( Exception e ) { } return null ; } | Returns an MBeanServer with the specified name |
28,079 | @ SuppressWarnings ( "unchecked" ) private void setProxyRequestHeaders ( HttpServletRequest httpServletRequest , HttpMethod httpMethodProxyRequest ) throws Exception { RequestInformation requestInfo = requestInformation . get ( ) ; String hostName = HttpUtilities . getHostNameFromURL ( httpServletRequest . getRequestURL ( ) . toString ( ) ) ; Boolean stripTransferEncoding = false ; Enumeration < String > enumerationOfHeaderNames = httpServletRequest . getHeaderNames ( ) ; while ( enumerationOfHeaderNames . hasMoreElements ( ) ) { String stringHeaderName = enumerationOfHeaderNames . nextElement ( ) ; if ( stringHeaderName . equalsIgnoreCase ( STRING_CONTENT_LENGTH_HEADER_NAME ) ) { continue ; } if ( stringHeaderName . equalsIgnoreCase ( "ODO-POST-TYPE" ) && httpServletRequest . getHeader ( "ODO-POST-TYPE" ) . startsWith ( "content-length:" ) ) { stripTransferEncoding = true ; } logger . info ( "Current header: {}" , stringHeaderName ) ; Enumeration < String > enumerationOfHeaderValues = httpServletRequest . getHeaders ( stringHeaderName ) ; while ( enumerationOfHeaderValues . hasMoreElements ( ) ) { String stringHeaderValue = enumerationOfHeaderValues . nextElement ( ) ; if ( stringHeaderName . equalsIgnoreCase ( STRING_HOST_HEADER_NAME ) && requestInfo . handle ) { String hostValue = getHostHeaderForHost ( hostName ) ; if ( hostValue != null ) { stringHeaderValue = hostValue ; } } Header header = new Header ( stringHeaderName , stringHeaderValue ) ; httpMethodProxyRequest . addRequestHeader ( header ) ; } } if ( stripTransferEncoding ) { httpMethodProxyRequest . removeRequestHeader ( "transfer-encoding" ) ; String contentLengthHint = httpServletRequest . getHeader ( "ODO-POST-TYPE" ) ; String [ ] contentLengthParts = contentLengthHint . split ( ":" ) ; httpMethodProxyRequest . addRequestHeader ( "content-length" , contentLengthParts [ 1 ] ) ; httpMethodProxyRequest . removeRequestHeader ( "ODO-POST-TYPE" ) ; } if ( ! requestInfo . handle ) { return ; } processRequestHeaderOverrides ( httpMethodProxyRequest ) ; } | Retrieves all of the headers from the servlet request and sets them on the proxy request |
28,080 | private void processRequestHeaderOverrides ( HttpMethod httpMethodProxyRequest ) throws Exception { RequestInformation requestInfo = requestInformation . get ( ) ; for ( EndpointOverride selectedPath : requestInfo . selectedRequestPaths ) { List < EnabledEndpoint > points = selectedPath . getEnabledEndpoints ( ) ; for ( EnabledEndpoint endpoint : points ) { if ( endpoint . getOverrideId ( ) == Constants . PLUGIN_REQUEST_HEADER_OVERRIDE_ADD ) { httpMethodProxyRequest . addRequestHeader ( endpoint . getArguments ( ) [ 0 ] . toString ( ) , endpoint . getArguments ( ) [ 1 ] . toString ( ) ) ; requestInfo . modified = true ; } else if ( endpoint . getOverrideId ( ) == Constants . PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE ) { httpMethodProxyRequest . removeRequestHeader ( endpoint . getArguments ( ) [ 0 ] . toString ( ) ) ; requestInfo . modified = true ; } } } } | Apply any applicable header overrides to request |
28,081 | private String getHostHeaderForHost ( String hostName ) { List < ServerRedirect > servers = serverRedirectService . tableServers ( requestInformation . get ( ) . client . getId ( ) ) ; for ( ServerRedirect server : servers ) { if ( server . getSrcUrl ( ) . compareTo ( hostName ) == 0 ) { String hostHeader = server . getHostHeader ( ) ; if ( hostHeader == null || hostHeader . length ( ) == 0 ) { return null ; } return hostHeader ; } } return null ; } | Obtain host header value for a hostname |
28,082 | private void processClientId ( HttpServletRequest httpServletRequest , History history ) { if ( httpServletRequest . getHeader ( Constants . PROFILE_CLIENT_HEADER_NAME ) != null && ! httpServletRequest . getHeader ( Constants . PROFILE_CLIENT_HEADER_NAME ) . equals ( "" ) ) { history . setClientUUID ( httpServletRequest . getHeader ( Constants . PROFILE_CLIENT_HEADER_NAME ) ) ; } else { history . setClientUUID ( Constants . PROFILE_CLIENT_DEFAULT_ID ) ; } logger . info ( "Client UUID is: {}" , history . getClientUUID ( ) ) ; } | Apply the matching client UUID for the request |
28,083 | private JSONArray getApplicablePathNames ( String requestUrl , Integer requestType ) throws Exception { RequestInformation requestInfo = requestInformation . get ( ) ; List < EndpointOverride > applicablePaths ; JSONArray pathNames = new JSONArray ( ) ; applicablePaths = PathOverrideService . getInstance ( ) . getSelectedPaths ( Constants . OVERRIDE_TYPE_REQUEST , requestInfo . client , requestInfo . profile , requestUrl + "?" + requestInfo . originalRequestInfo . getQueryString ( ) , requestType , true ) ; for ( EndpointOverride path : applicablePaths ) { JSONObject pathName = new JSONObject ( ) ; pathName . put ( "name" , path . getPathName ( ) ) ; pathNames . put ( pathName ) ; } return pathNames ; } | Get the names of the paths that would apply to the request |
28,084 | private String getDestinationHostName ( String hostName ) { List < ServerRedirect > servers = serverRedirectService . tableServers ( requestInformation . get ( ) . client . getId ( ) ) ; for ( ServerRedirect server : servers ) { if ( server . getSrcUrl ( ) . compareTo ( hostName ) == 0 ) { if ( server . getDestUrl ( ) != null && server . getDestUrl ( ) . compareTo ( "" ) != 0 ) { return server . getDestUrl ( ) ; } else { logger . warn ( "Using source URL as destination URL since no destination was specified for: {}" , server . getSrcUrl ( ) ) ; } break ; } } return hostName ; } | Obtain the destination hostname for a source host |
28,085 | private void processVirtualHostName ( HttpMethod httpMethodProxyRequest , HttpServletRequest httpServletRequest ) { String virtualHostName ; if ( httpMethodProxyRequest . getRequestHeader ( STRING_HOST_HEADER_NAME ) != null ) { virtualHostName = HttpUtilities . removePortFromHostHeaderString ( httpMethodProxyRequest . getRequestHeader ( STRING_HOST_HEADER_NAME ) . getValue ( ) ) ; } else { virtualHostName = HttpUtilities . getHostNameFromURL ( httpServletRequest . getRequestURL ( ) . toString ( ) ) ; } httpMethodProxyRequest . getParams ( ) . setVirtualHost ( virtualHostName ) ; } | Set virtual host so the server can direct the request . Value is the host header if it is set otherwise use the hostname from the original request . |
28,086 | private void cullDisabledPaths ( ) throws Exception { ArrayList < EndpointOverride > removePaths = new ArrayList < EndpointOverride > ( ) ; RequestInformation requestInfo = requestInformation . get ( ) ; for ( EndpointOverride selectedPath : requestInfo . selectedResponsePaths ) { if ( selectedPath != null && selectedPath . getRepeatNumber ( ) == 0 ) { removePaths . add ( selectedPath ) ; } else if ( selectedPath != null && selectedPath . getRepeatNumber ( ) != - 1 ) { selectedPath . updateRepeatNumber ( selectedPath . getRepeatNumber ( ) - 1 ) ; } } for ( EndpointOverride removePath : removePaths ) { requestInfo . selectedResponsePaths . remove ( removePath ) ; } } | Remove paths with no active overrides |
28,087 | private ArrayList < String > getRemoveHeaders ( ) throws Exception { ArrayList < String > headersToRemove = new ArrayList < String > ( ) ; for ( EndpointOverride selectedPath : requestInformation . get ( ) . selectedResponsePaths ) { List < EnabledEndpoint > points = selectedPath . getEnabledEndpoints ( ) ; for ( EnabledEndpoint endpoint : points ) { if ( endpoint . getRepeatNumber ( ) == 0 ) { continue ; } if ( endpoint . getOverrideId ( ) == Constants . PLUGIN_RESPONSE_HEADER_OVERRIDE_REMOVE ) { headersToRemove . add ( endpoint . getArguments ( ) [ 0 ] . toString ( ) ) ; endpoint . decrementRepeatNumber ( ) ; } } } return headersToRemove ; } | Obtain collection of headers to remove |
28,088 | private void executeProxyRequest ( HttpMethod httpMethodProxyRequest , HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse , History history ) { try { RequestInformation requestInfo = requestInformation . get ( ) ; processVirtualHostName ( httpMethodProxyRequest , httpServletRequest ) ; cullDisabledPaths ( ) ; if ( httpServletRequest . getHeader ( Constants . ODO_PROXY_HEADER ) != null ) { logger . error ( "Request has looped back into the proxy. This will not be executed: {}" , httpServletRequest . getRequestURL ( ) ) ; return ; } httpMethodProxyRequest . addRequestHeader ( Constants . ODO_PROXY_HEADER , "proxied" ) ; requestInfo . blockRequest = hasRequestBlock ( ) ; PluginResponse responseWrapper = new PluginResponse ( httpServletResponse ) ; requestInfo . jsonpCallback = stripJSONPToOutstr ( httpServletRequest , responseWrapper ) ; if ( ! requestInfo . blockRequest ) { logger . info ( "Sending request to server" ) ; history . setModified ( requestInfo . modified ) ; history . setRequestSent ( true ) ; executeRequest ( httpMethodProxyRequest , httpServletRequest , responseWrapper , history ) ; } else { history . setRequestSent ( false ) ; } logOriginalResponseHistory ( responseWrapper , history ) ; applyResponseOverrides ( responseWrapper , httpServletRequest , httpMethodProxyRequest , history ) ; history . setModified ( requestInfo . modified ) ; logRequestHistory ( httpMethodProxyRequest , responseWrapper , history ) ; writeResponseOutput ( responseWrapper , requestInfo . jsonpCallback ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } | Execute a request through Odo processing |
28,089 | private void executeRequest ( HttpMethod httpMethodProxyRequest , HttpServletRequest httpServletRequest , PluginResponse httpServletResponse , History history ) throws Exception { int intProxyResponseCode = 999 ; HttpClient httpClient = new HttpClient ( ) ; HttpState state = new HttpState ( ) ; try { httpMethodProxyRequest . setFollowRedirects ( false ) ; ArrayList < String > headersToRemove = getRemoveHeaders ( ) ; httpClient . getParams ( ) . setSoTimeout ( 60000 ) ; httpServletRequest . setAttribute ( "com.groupon.odo.removeHeaders" , headersToRemove ) ; HttpMethodRetryHandler noretryhandler = new HttpMethodRetryHandler ( ) { public boolean retryMethod ( final HttpMethod method , final IOException exception , int executionCount ) { return false ; } } ; httpMethodProxyRequest . getParams ( ) . setParameter ( HttpMethodParams . RETRY_HANDLER , noretryhandler ) ; intProxyResponseCode = httpClient . executeMethod ( httpMethodProxyRequest . getHostConfiguration ( ) , httpMethodProxyRequest , state ) ; } catch ( Exception e ) { httpServletResponse . setStatus ( 504 ) ; httpServletResponse . setHeader ( Constants . HEADER_STATUS , "504" ) ; httpServletResponse . flushBuffer ( ) ; return ; } logger . info ( "Response code: {}, {}" , intProxyResponseCode , HttpUtilities . getURL ( httpMethodProxyRequest . getURI ( ) . toString ( ) ) ) ; httpServletResponse . setStatus ( intProxyResponseCode ) ; Header [ ] headerArrayResponse = httpMethodProxyRequest . getResponseHeaders ( ) ; for ( Header header : headerArrayResponse ) { if ( header . getName ( ) . toLowerCase ( ) . equals ( "transfer-encoding" ) ) { continue ; } httpServletResponse . setHeader ( header . getName ( ) , header . getValue ( ) ) ; } if ( intProxyResponseCode != HttpServletResponse . SC_NOT_MODIFIED && intProxyResponseCode != HttpServletResponse . SC_NO_CONTENT ) { httpServletResponse . resetBuffer ( ) ; httpServletResponse . getOutputStream ( ) . write ( httpMethodProxyRequest . getResponseBody ( ) ) ; } for ( Cookie cookie : state . getCookies ( ) ) { javax . servlet . http . Cookie servletCookie = new javax . servlet . http . Cookie ( cookie . getName ( ) , cookie . getValue ( ) ) ; if ( cookie . getPath ( ) != null ) { servletCookie . setPath ( cookie . getPath ( ) ) ; } if ( cookie . getDomain ( ) != null ) { servletCookie . setDomain ( cookie . getDomain ( ) ) ; } if ( cookie . getExpiryDate ( ) != null ) { servletCookie . setMaxAge ( ( int ) ( ( cookie . getExpiryDate ( ) . getTime ( ) - System . currentTimeMillis ( ) ) / 1000 ) ) ; } servletCookie . setSecure ( cookie . getSecure ( ) ) ; servletCookie . setVersion ( cookie . getVersion ( ) ) ; if ( cookie . getComment ( ) != null ) { servletCookie . setComment ( cookie . getComment ( ) ) ; } httpServletResponse . addCookie ( servletCookie ) ; } } | Execute a request |
28,090 | private void processRedirect ( String stringStatusCode , HttpMethod httpMethodProxyRequest , HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse ) throws Exception { String stringLocation = httpMethodProxyRequest . getResponseHeader ( STRING_LOCATION_HEADER ) . getValue ( ) ; if ( stringLocation == null ) { throw new ServletException ( "Received status code: " + stringStatusCode + " but no " + STRING_LOCATION_HEADER + " header was found in the response" ) ; } String stringMyHostName = httpServletRequest . getServerName ( ) ; if ( httpServletRequest . getServerPort ( ) != 80 ) { stringMyHostName += ":" + httpServletRequest . getServerPort ( ) ; } stringMyHostName += httpServletRequest . getContextPath ( ) ; httpServletResponse . sendRedirect ( stringLocation . replace ( getProxyHostAndPort ( ) + this . getProxyPath ( ) , stringMyHostName ) ) ; } | Execute a redirected request |
28,091 | private void logOriginalRequestHistory ( String requestType , HttpServletRequest request , History history ) { logger . info ( "Storing original request history" ) ; history . setRequestType ( requestType ) ; history . setOriginalRequestHeaders ( HttpUtilities . getHeaders ( request ) ) ; history . setOriginalRequestURL ( request . getRequestURL ( ) . toString ( ) ) ; history . setOriginalRequestParams ( request . getQueryString ( ) == null ? "" : request . getQueryString ( ) ) ; logger . info ( "Done storing" ) ; } | Log original incoming request |
28,092 | private void logOriginalResponseHistory ( PluginResponse httpServletResponse , History history ) throws URIException { RequestInformation requestInfo = requestInformation . get ( ) ; if ( requestInfo . handle && requestInfo . client . getIsActive ( ) ) { logger . info ( "Storing original response history" ) ; history . setOriginalResponseHeaders ( HttpUtilities . getHeaders ( httpServletResponse ) ) ; history . setOriginalResponseCode ( Integer . toString ( httpServletResponse . getStatus ( ) ) ) ; history . setOriginalResponseContentType ( httpServletResponse . getContentType ( ) ) ; history . setOriginalResponseData ( httpServletResponse . getContentString ( ) ) ; logger . info ( "Done storing" ) ; } } | Log original response |
28,093 | private void logRequestHistory ( HttpMethod httpMethodProxyRequest , PluginResponse httpServletResponse , History history ) { try { if ( requestInformation . get ( ) . handle && requestInformation . get ( ) . client . getIsActive ( ) ) { logger . info ( "Storing history" ) ; String createdDate ; SimpleDateFormat sdf = new SimpleDateFormat ( ) ; sdf . setTimeZone ( new SimpleTimeZone ( 0 , "GMT" ) ) ; sdf . applyPattern ( "dd MMM yyyy HH:mm:ss" ) ; createdDate = sdf . format ( new Date ( ) ) + " GMT" ; history . setCreatedAt ( createdDate ) ; history . setRequestURL ( HttpUtilities . getURL ( httpMethodProxyRequest . getURI ( ) . toString ( ) ) ) ; history . setRequestParams ( httpMethodProxyRequest . getQueryString ( ) == null ? "" : httpMethodProxyRequest . getQueryString ( ) ) ; history . setRequestHeaders ( HttpUtilities . getHeaders ( httpMethodProxyRequest ) ) ; history . setResponseHeaders ( HttpUtilities . getHeaders ( httpServletResponse ) ) ; history . setResponseCode ( Integer . toString ( httpServletResponse . getStatus ( ) ) ) ; history . setResponseContentType ( httpServletResponse . getContentType ( ) ) ; history . setResponseData ( httpServletResponse . getContentString ( ) ) ; history . setResponseBodyDecoded ( httpServletResponse . isContentDecoded ( ) ) ; HistoryService . getInstance ( ) . addHistory ( history ) ; logger . info ( "Done storing" ) ; } } catch ( URIException e ) { e . printStackTrace ( ) ; } } | Log modified request |
28,094 | public void handleConnectOriginal ( String pathInContext , String pathParams , HttpRequest request , HttpResponse response ) throws HttpException , IOException { URI uri = request . getURI ( ) ; try { LOG . fine ( "CONNECT: " + uri ) ; InetAddrPort addrPort ; if ( uri . toString ( ) . endsWith ( ".selenium.doesnotexist:443" ) ) { addrPort = new InetAddrPort ( 443 ) ; } else { addrPort = new InetAddrPort ( uri . toString ( ) ) ; } if ( isForbidden ( HttpMessage . __SSL_SCHEME , addrPort . getHost ( ) , addrPort . getPort ( ) , false ) ) { sendForbid ( request , response , uri ) ; } else { HttpConnection http_connection = request . getHttpConnection ( ) ; http_connection . forceClose ( ) ; HttpServer server = http_connection . getHttpServer ( ) ; SslListener listener = getSslRelayOrCreateNewOdo ( uri , addrPort , server ) ; int port = listener . getPort ( ) ; int timeoutMs = 30000 ; Object maybesocket = http_connection . getConnection ( ) ; if ( maybesocket instanceof Socket ) { Socket s = ( Socket ) maybesocket ; timeoutMs = s . getSoTimeout ( ) ; } HttpTunnel tunnel = newHttpTunnel ( request , response , InetAddress . getByName ( null ) , port , timeoutMs ) ; if ( tunnel != null ) { if ( _tunnelTimeoutMs > 0 ) { tunnel . getSocket ( ) . setSoTimeout ( _tunnelTimeoutMs ) ; if ( maybesocket instanceof Socket ) { Socket s = ( Socket ) maybesocket ; s . setSoTimeout ( _tunnelTimeoutMs ) ; } } tunnel . setTimeoutMs ( timeoutMs ) ; customizeConnection ( pathInContext , pathParams , request , tunnel . getSocket ( ) ) ; request . getHttpConnection ( ) . setHttpTunnel ( tunnel ) ; response . setStatus ( HttpResponse . __200_OK ) ; response . setContentLength ( 0 ) ; } request . setHandled ( true ) ; } } catch ( Exception e ) { LOG . fine ( "error during handleConnect" , e ) ; response . sendError ( HttpResponse . __500_Internal_Server_Error , e . toString ( ) ) ; } } | Copied from original SeleniumProxyHandler Changed SslRelay to SslListener and getSslRelayOrCreateNew to getSslRelayOrCreateNewOdo No other changes to the function |
28,095 | protected X509Certificate wireUpSslWithCyberVilliansCAOdo ( String host , SslListener listener ) { host = requestOriginalHostName . get ( ) ; try { String escapedHost = host . replace ( '*' , '_' ) ; KeyStoreManager keyStoreManager = Utils . getKeyStoreManager ( escapedHost ) ; keyStoreManager . getKeyStore ( ) . deleteEntry ( KeyStoreManager . _caPrivKeyAlias ) ; keyStoreManager . persist ( ) ; listener . setKeystore ( new File ( "seleniumSslSupport" + File . separator + escapedHost + File . separator + "cybervillainsCA.jks" ) . getAbsolutePath ( ) ) ; return keyStoreManager . getCertificateByAlias ( escapedHost ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } | This function wires up a SSL Listener with the cyber villians root CA and cert with the correct CNAME for the request |
28,096 | private void startRelayWithPortTollerance ( HttpServer server , SslListener relay , int tries ) throws Exception { if ( tries >= 5 ) { throw new BindException ( "Unable to bind to several ports, most recently " + relay . getPort ( ) + ". Giving up" ) ; } try { if ( server . isStarted ( ) ) { relay . start ( ) ; } else { throw new RuntimeException ( "Can't start SslRelay: server is not started (perhaps it was just shut down?)" ) ; } } catch ( BindException e ) { LOG . info ( "Unable to bind to port %d, going to try port %d now" , relay . getPort ( ) , relay . getPort ( ) + 1 ) ; relay . setPort ( relay . getPort ( ) + 1 ) ; startRelayWithPortTollerance ( server , relay , tries + 1 ) ; } } | END ODO CHANGES |
28,097 | private static OkHttpClient getUnsafeOkHttpClient ( ) { try { final TrustManager [ ] trustAllCerts = new TrustManager [ ] { new X509TrustManager ( ) { public void checkClientTrusted ( java . security . cert . X509Certificate [ ] chain , String authType ) throws CertificateException { } public void checkServerTrusted ( java . security . cert . X509Certificate [ ] chain , String authType ) throws CertificateException { } public java . security . cert . X509Certificate [ ] getAcceptedIssuers ( ) { return null ; } } } ; final SSLContext sslContext = SSLContext . getInstance ( "SSL" ) ; sslContext . init ( null , trustAllCerts , new java . security . SecureRandom ( ) ) ; final SSLSocketFactory sslSocketFactory = sslContext . getSocketFactory ( ) ; OkHttpClient okHttpClient = new OkHttpClient ( ) ; okHttpClient . setSslSocketFactory ( sslSocketFactory ) ; okHttpClient . setHostnameVerifier ( new HostnameVerifier ( ) { public boolean verify ( String hostname , SSLSession session ) { return true ; } } ) ; return okHttpClient ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } | Returns a OkHttpClient that ignores SSL cert errors |
28,098 | public void cleanup ( ) { synchronized ( _sslMap ) { for ( SslRelayOdo relay : _sslMap . values ( ) ) { if ( relay . getHttpServer ( ) != null && relay . isStarted ( ) ) { relay . getHttpServer ( ) . removeListener ( relay ) ; } } sslRelays . clear ( ) ; } } | Cleanup function to remove all allocated listeners |
28,099 | public void removeOverride ( int overrideId , int pathId , Integer ordinal , String clientUUID ) { PreparedStatement statement = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { int enabledId = getEnabledEndpoint ( pathId , overrideId , ordinal , clientUUID ) . getId ( ) ; statement = sqlConnection . prepareStatement ( "DELETE FROM " + Constants . DB_TABLE_ENABLED_OVERRIDE + " WHERE " + Constants . GENERIC_ID + " = ?" ) ; statement . setInt ( 1 , enabledId ) ; statement . executeUpdate ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } } | Remove specified override id from enabled overrides for path |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.