repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PathOverrideService.java | PathOverrideService.getSelectedPaths | public List<EndpointOverride> getSelectedPaths(int overrideType, Client client, Profile profile, String uri,
Integer requestType, boolean pathTest) throws Exception {
List<EndpointOverride> selectPaths = new ArrayList<EndpointOverride>();
// get the paths for the current active client profile
// this returns paths in priority order
List<EndpointOverride> paths = new ArrayList<EndpointOverride>();
if (client.getIsActive()) {
paths = getPaths(
profile.getId(),
client.getUUID(), null);
}
boolean foundRealPath = false;
logger.info("Checking uri: {}", uri);
// it should now be ordered by priority, i updated tableOverrides to
// return the paths in priority order
for (EndpointOverride path : paths) {
// first see if the request types match..
// and if the path request type is not ALL
// if they do not then skip this path
// If requestType is -1 we evaluate all(probably called by the path tester)
if (requestType != -1 && path.getRequestType() != requestType && path.getRequestType() != Constants.REQUEST_TYPE_ALL) {
continue;
}
// first see if we get a match
try {
Pattern pattern = Pattern.compile(path.getPath());
Matcher matcher = pattern.matcher(uri);
// we won't select the path if there aren't any enabled endpoints in it
// this works since the paths are returned in priority order
if (matcher.find()) {
// now see if this path has anything enabled in it
// Only go into the if:
// 1. There are enabled items in this path
// 2. Caller was looking for ResponseOverride and Response is enabled OR looking for RequestOverride
// 3. If pathTest is true then the rest of the conditions are not evaluated. The path tester ignores enabled states so everything is returned.
// and request is enabled
if (pathTest ||
(path.getEnabledEndpoints().size() > 0 &&
((overrideType == Constants.OVERRIDE_TYPE_RESPONSE && path.getResponseEnabled()) ||
(overrideType == Constants.OVERRIDE_TYPE_REQUEST && path.getRequestEnabled())))) {
// if we haven't already seen a non global path
// or if this is a global path
// then add it to the list
if (!foundRealPath || path.getGlobal()) {
selectPaths.add(path);
}
}
// we set this no matter what if a path matched and it was not the global path
// this stops us from adding further non global matches to the list
if (!path.getGlobal()) {
foundRealPath = true;
}
}
} catch (PatternSyntaxException pse) {
// nothing to do but keep iterating over the list
// this indicates an invalid regex
}
}
return selectPaths;
} | java | public List<EndpointOverride> getSelectedPaths(int overrideType, Client client, Profile profile, String uri,
Integer requestType, boolean pathTest) throws Exception {
List<EndpointOverride> selectPaths = new ArrayList<EndpointOverride>();
// get the paths for the current active client profile
// this returns paths in priority order
List<EndpointOverride> paths = new ArrayList<EndpointOverride>();
if (client.getIsActive()) {
paths = getPaths(
profile.getId(),
client.getUUID(), null);
}
boolean foundRealPath = false;
logger.info("Checking uri: {}", uri);
// it should now be ordered by priority, i updated tableOverrides to
// return the paths in priority order
for (EndpointOverride path : paths) {
// first see if the request types match..
// and if the path request type is not ALL
// if they do not then skip this path
// If requestType is -1 we evaluate all(probably called by the path tester)
if (requestType != -1 && path.getRequestType() != requestType && path.getRequestType() != Constants.REQUEST_TYPE_ALL) {
continue;
}
// first see if we get a match
try {
Pattern pattern = Pattern.compile(path.getPath());
Matcher matcher = pattern.matcher(uri);
// we won't select the path if there aren't any enabled endpoints in it
// this works since the paths are returned in priority order
if (matcher.find()) {
// now see if this path has anything enabled in it
// Only go into the if:
// 1. There are enabled items in this path
// 2. Caller was looking for ResponseOverride and Response is enabled OR looking for RequestOverride
// 3. If pathTest is true then the rest of the conditions are not evaluated. The path tester ignores enabled states so everything is returned.
// and request is enabled
if (pathTest ||
(path.getEnabledEndpoints().size() > 0 &&
((overrideType == Constants.OVERRIDE_TYPE_RESPONSE && path.getResponseEnabled()) ||
(overrideType == Constants.OVERRIDE_TYPE_REQUEST && path.getRequestEnabled())))) {
// if we haven't already seen a non global path
// or if this is a global path
// then add it to the list
if (!foundRealPath || path.getGlobal()) {
selectPaths.add(path);
}
}
// we set this no matter what if a path matched and it was not the global path
// this stops us from adding further non global matches to the list
if (!path.getGlobal()) {
foundRealPath = true;
}
}
} catch (PatternSyntaxException pse) {
// nothing to do but keep iterating over the list
// this indicates an invalid regex
}
}
return selectPaths;
} | [
"public",
"List",
"<",
"EndpointOverride",
">",
"getSelectedPaths",
"(",
"int",
"overrideType",
",",
"Client",
"client",
",",
"Profile",
"profile",
",",
"String",
"uri",
",",
"Integer",
"requestType",
",",
"boolean",
"pathTest",
")",
"throws",
"Exception",
"{",
... | Obtain matching paths for a request
@param overrideType type of override
@param client Client
@param profile Profile
@param uri URI
@param requestType type of request
@param pathTest If true this will also match disabled paths
@return Collection of matching endpoints
@throws Exception exception | [
"Obtain",
"matching",
"paths",
"for",
"a",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PathOverrideService.java#L1526-L1593 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.isActive | 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;
} | java | 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;
} | [
"public",
"boolean",
"isActive",
"(",
"int",
"profileId",
")",
"{",
"boolean",
"active",
"=",
"false",
";",
"PreparedStatement",
"queryStatement",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
"... | Returns true if the default profile for the specified uuid is active
@return true if active, otherwise false | [
"Returns",
"true",
"if",
"the",
"default",
"profile",
"for",
"the",
"specified",
"uuid",
"is",
"active"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L61-L89 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.findAllProfiles | 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;
} | java | 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;
} | [
"public",
"List",
"<",
"Profile",
">",
"findAllProfiles",
"(",
")",
"throws",
"Exception",
"{",
"ArrayList",
"<",
"Profile",
">",
"allProfiles",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"PreparedStatement",
"statement",
"=",
"null",
";",
"ResultSet",
"r... | Returns a collection of all profiles
@return Collection of all Profiles
@throws Exception exception | [
"Returns",
"a",
"collection",
"of",
"all",
"profiles"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L97-L125 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.findProfile | 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;
} | java | 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;
} | [
"public",
"Profile",
"findProfile",
"(",
"int",
"profileId",
")",
"throws",
"Exception",
"{",
"Profile",
"profile",
"=",
"null",
";",
"PreparedStatement",
"statement",
"=",
"null",
";",
"ResultSet",
"results",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlCo... | Returns a specific profile
@param profileId ID of profile
@return Selected profile if found, null if not found
@throws Exception exception | [
"Returns",
"a",
"specific",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L134-L166 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.getProfileFromResultSet | 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;
} | java | 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;
} | [
"private",
"Profile",
"getProfileFromResultSet",
"(",
"ResultSet",
"result",
")",
"throws",
"Exception",
"{",
"Profile",
"profile",
"=",
"new",
"Profile",
"(",
")",
";",
"profile",
".",
"setId",
"(",
"result",
".",
"getInt",
"(",
"Constants",
".",
"GENERIC_ID"... | Creates a Profile object from a SQL resultset
@param result resultset containing the profile
@return Profile
@throws Exception exception | [
"Creates",
"a",
"Profile",
"object",
"from",
"a",
"SQL",
"resultset"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L175-L182 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.add | 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 {
// something went wrong
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;
} | java | 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 {
// something went wrong
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;
} | [
"public",
"Profile",
"add",
"(",
"String",
"profileName",
")",
"throws",
"Exception",
"{",
"Profile",
"profile",
"=",
"new",
"Profile",
"(",
")",
";",
"int",
"id",
"=",
"-",
"1",
";",
"PreparedStatement",
"statement",
"=",
"null",
";",
"ResultSet",
"result... | Add a new profile with the profileName given.
@param profileName name of new profile
@return newly created profile
@throws Exception exception | [
"Add",
"a",
"new",
"profile",
"with",
"the",
"profileName",
"given",
"."
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L191-L247 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.remove | 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();
//also want to delete what is in the server redirect table
statement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?");
statement.setInt(1, profileId);
statement.executeUpdate();
statement.close();
//also want to delete the path_profile table
statement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_PATH +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?");
statement.setInt(1, profileId);
statement.executeUpdate();
statement.close();
//and the enabled overrides table
statement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?");
statement.setInt(1, profileId);
statement.executeUpdate();
statement.close();
//and delete all the clients associated with this profile including the default client
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) {
}
}
} | java | 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();
//also want to delete what is in the server redirect table
statement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?");
statement.setInt(1, profileId);
statement.executeUpdate();
statement.close();
//also want to delete the path_profile table
statement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_PATH +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?");
statement.setInt(1, profileId);
statement.executeUpdate();
statement.close();
//and the enabled overrides table
statement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?");
statement.setInt(1, profileId);
statement.executeUpdate();
statement.close();
//and delete all the clients associated with this profile including the default client
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) {
}
}
} | [
"public",
"void",
"remove",
"(",
"int",
"profileId",
")",
"{",
"PreparedStatement",
"statement",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
")",
"{",
"statement",
"=",
"sqlConnection",
".",
... | Deletes data associated with the given profile ID
@param profileId ID of profile | [
"Deletes",
"data",
"associated",
"with",
"the",
"given",
"profile",
"ID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L256-L299 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.getNamefromId | public String getNamefromId(int id) {
return (String) sqlService.getFromTable(
Constants.PROFILE_PROFILE_NAME, Constants.GENERIC_ID,
id, Constants.DB_TABLE_PROFILE);
} | java | public String getNamefromId(int id) {
return (String) sqlService.getFromTable(
Constants.PROFILE_PROFILE_NAME, Constants.GENERIC_ID,
id, Constants.DB_TABLE_PROFILE);
} | [
"public",
"String",
"getNamefromId",
"(",
"int",
"id",
")",
"{",
"return",
"(",
"String",
")",
"sqlService",
".",
"getFromTable",
"(",
"Constants",
".",
"PROFILE_PROFILE_NAME",
",",
"Constants",
".",
"GENERIC_ID",
",",
"id",
",",
"Constants",
".",
"DB_TABLE_PR... | Obtain the profile name associated with a profile ID
@param id ID of profile
@return Name of corresponding profile | [
"Obtain",
"the",
"profile",
"name",
"associated",
"with",
"a",
"profile",
"ID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L307-L311 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java | ProfileService.getIdFromName | 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;
} | java | 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;
} | [
"public",
"Integer",
"getIdFromName",
"(",
"String",
"profileName",
")",
"{",
"PreparedStatement",
"query",
"=",
"null",
";",
"ResultSet",
"results",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
... | Obtain the ID associated with a profile name
@param profileName profile name
@return ID of profile | [
"Obtain",
"the",
"ID",
"associated",
"with",
"a",
"profile",
"name"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ProfileService.java#L321-L353 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java | ControllerUtils.convertPathIdentifier | public static Integer convertPathIdentifier(String identifier, Integer profileId) throws Exception {
Integer pathId = -1;
try {
pathId = Integer.parseInt(identifier);
} catch (NumberFormatException ne) {
// this is OK.. just means it's not a #
if (profileId == null)
throw new Exception("A profileId must be specified");
pathId = PathOverrideService.getInstance().getPathId(identifier, profileId);
}
return pathId;
} | java | public static Integer convertPathIdentifier(String identifier, Integer profileId) throws Exception {
Integer pathId = -1;
try {
pathId = Integer.parseInt(identifier);
} catch (NumberFormatException ne) {
// this is OK.. just means it's not a #
if (profileId == null)
throw new Exception("A profileId must be specified");
pathId = PathOverrideService.getInstance().getPathId(identifier, profileId);
}
return pathId;
} | [
"public",
"static",
"Integer",
"convertPathIdentifier",
"(",
"String",
"identifier",
",",
"Integer",
"profileId",
")",
"throws",
"Exception",
"{",
"Integer",
"pathId",
"=",
"-",
"1",
";",
"try",
"{",
"pathId",
"=",
"Integer",
".",
"parseInt",
"(",
"identifier"... | Obtain the path ID for a profile
@param identifier Can be the path ID, or friendly name
@param profileId
@return
@throws Exception | [
"Obtain",
"the",
"path",
"ID",
"for",
"a",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java#L36-L49 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java | ControllerUtils.convertProfileIdentifier | 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) {
// this is OK.. just means it's not a #
// try to get it by name instead
profileId = ProfileService.getInstance().getIdFromName(profileIdentifier);
}
}
logger.info("Profile id is {}", profileId);
return profileId;
} | java | 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) {
// this is OK.. just means it's not a #
// try to get it by name instead
profileId = ProfileService.getInstance().getIdFromName(profileIdentifier);
}
}
logger.info("Profile id is {}", profileId);
return profileId;
} | [
"public",
"static",
"Integer",
"convertProfileIdentifier",
"(",
"String",
"profileIdentifier",
")",
"throws",
"Exception",
"{",
"Integer",
"profileId",
"=",
"-",
"1",
";",
"if",
"(",
"profileIdentifier",
"==",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
... | Obtain the profile identifier.
@param profileIdentifier Can be profile ID, or friendly name
@return
@throws Exception | [
"Obtain",
"the",
"profile",
"identifier",
"."
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java#L58-L74 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java | ControllerUtils.convertOverrideIdentifier | public static Integer convertOverrideIdentifier(String overrideIdentifier) throws Exception {
Integer overrideId = -1;
try {
// there is an issue with parseInt where it does not parse negative values correctly
boolean isNegative = false;
if (overrideIdentifier.startsWith("-")) {
isNegative = true;
overrideIdentifier = overrideIdentifier.substring(1);
}
overrideId = Integer.parseInt(overrideIdentifier);
if (isNegative) {
overrideId = 0 - overrideId;
}
} catch (NumberFormatException ne) {
// this is OK.. just means it's not a #
// split into two parts
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;
} | java | public static Integer convertOverrideIdentifier(String overrideIdentifier) throws Exception {
Integer overrideId = -1;
try {
// there is an issue with parseInt where it does not parse negative values correctly
boolean isNegative = false;
if (overrideIdentifier.startsWith("-")) {
isNegative = true;
overrideIdentifier = overrideIdentifier.substring(1);
}
overrideId = Integer.parseInt(overrideIdentifier);
if (isNegative) {
overrideId = 0 - overrideId;
}
} catch (NumberFormatException ne) {
// this is OK.. just means it's not a #
// split into two parts
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;
} | [
"public",
"static",
"Integer",
"convertOverrideIdentifier",
"(",
"String",
"overrideIdentifier",
")",
"throws",
"Exception",
"{",
"Integer",
"overrideId",
"=",
"-",
"1",
";",
"try",
"{",
"// there is an issue with parseInt where it does not parse negative values correctly",
"... | Obtain override ID
@param overrideIdentifier can be the override ID or class name
@return
@throws Exception | [
"Obtain",
"override",
"ID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java#L83-L112 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java | ControllerUtils.convertProfileAndPathIdentifier | 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) {
// this is OK for this since it isn't always needed
}
Integer pathId = convertPathIdentifier(pathIdentifier, profileId);
id.setProfileId(profileId);
id.setPathId(pathId);
return id;
} | java | 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) {
// this is OK for this since it isn't always needed
}
Integer pathId = convertPathIdentifier(pathIdentifier, profileId);
id.setProfileId(profileId);
id.setPathId(pathId);
return id;
} | [
"public",
"static",
"Identifiers",
"convertProfileAndPathIdentifier",
"(",
"String",
"profileIdentifier",
",",
"String",
"pathIdentifier",
")",
"throws",
"Exception",
"{",
"Identifiers",
"id",
"=",
"new",
"Identifiers",
"(",
")",
";",
"Integer",
"profileId",
"=",
"n... | Obtain the IDs of profile and path as Identifiers
@param profileIdentifier actual ID or friendly name of profile
@param pathIdentifier actual ID or friendly name of path
@return
@throws Exception | [
"Obtain",
"the",
"IDs",
"of",
"profile",
"and",
"path",
"as",
"Identifiers"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ControllerUtils.java#L122-L137 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/PathValueClient.java | PathValueClient.getPathFromEndpoint | 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;
} | java | 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;
} | [
"public",
"JSONObject",
"getPathFromEndpoint",
"(",
"String",
"pathValue",
",",
"String",
"requestType",
")",
"throws",
"Exception",
"{",
"int",
"type",
"=",
"getRequestTypeFromString",
"(",
"requestType",
")",
";",
"String",
"url",
"=",
"BASE_PATH",
";",
"JSONObj... | Retrieves the path using the endpoint value
@param pathValue - path (endpoint) value
@param requestType - "GET", "POST", etc
@return Path or null
@throws Exception exception | [
"Retrieves",
"the",
"path",
"using",
"the",
"endpoint",
"value"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/PathValueClient.java#L43-L55 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/PathValueClient.java | PathValueClient.setDefaultCustomResponse | 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;
} | java | 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;
} | [
"public",
"static",
"boolean",
"setDefaultCustomResponse",
"(",
"String",
"pathValue",
",",
"String",
"requestType",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"JSONObject",
"profile",
"=",
"getDefaultProfile",
"(",
")",
";",
"String",
"profileName",
"=",
... | Sets a custom response on an endpoint using default profile and client
@param pathValue path (endpoint) value
@param requestType path request type. "GET", "POST", etc
@param customData custom response data
@return true if success, false otherwise | [
"Sets",
"a",
"custom",
"response",
"on",
"an",
"endpoint",
"using",
"default",
"profile",
"and",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/PathValueClient.java#L65-L75 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/PathValueClient.java | PathValueClient.removeDefaultCustomResponse | 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;
} | java | 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;
} | [
"public",
"static",
"boolean",
"removeDefaultCustomResponse",
"(",
"String",
"pathValue",
",",
"String",
"requestType",
")",
"{",
"try",
"{",
"JSONObject",
"profile",
"=",
"getDefaultProfile",
"(",
")",
";",
"String",
"profileName",
"=",
"profile",
".",
"getString... | Remove any overrides for an endpoint on the default profile, client
@param pathValue path (endpoint) value
@param requestType path request type. "GET", "POST", etc
@return true if success, false otherwise | [
"Remove",
"any",
"overrides",
"for",
"an",
"endpoint",
"on",
"the",
"default",
"profile",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/PathValueClient.java#L84-L94 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/PathValueClient.java | PathValueClient.removeCustomResponse | 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;
} | java | 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;
} | [
"public",
"boolean",
"removeCustomResponse",
"(",
"String",
"pathValue",
",",
"String",
"requestType",
")",
"{",
"try",
"{",
"JSONObject",
"path",
"=",
"getPathFromEndpoint",
"(",
"pathValue",
",",
"requestType",
")",
";",
"if",
"(",
"path",
"==",
"null",
")",... | Remove any overrides for an endpoint
@param pathValue path (endpoint) value
@param requestType path request type. "GET", "POST", etc
@return true if success, false otherwise | [
"Remove",
"any",
"overrides",
"for",
"an",
"endpoint"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/PathValueClient.java#L103-L115 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/PathValueClient.java | PathValueClient.setCustomResponse | 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;
} | java | 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;
} | [
"public",
"boolean",
"setCustomResponse",
"(",
"String",
"pathValue",
",",
"String",
"requestType",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"JSONObject",
"path",
"=",
"getPathFromEndpoint",
"(",
"pathValue",
",",
"requestType",
")",
";",
"if",
"(",
... | Sets a custom response on an endpoint
@param pathValue path (endpoint) value
@param requestType path request type. "GET", "POST", etc
@param customData custom response data
@return true if success, false otherwise | [
"Sets",
"a",
"custom",
"response",
"on",
"an",
"endpoint"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/PathValueClient.java#L125-L141 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java | ClientController.getClientList | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients", method = RequestMethod.GET)
public
@ResponseBody
HashMap<String, Object> getClientList(Model model,
@PathVariable("profileIdentifier") String profileIdentifier) throws Exception {
Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
return Utils.getJQGridJSON(clientService.findAllClients(profileId), "clients");
} | java | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients", method = RequestMethod.GET)
public
@ResponseBody
HashMap<String, Object> getClientList(Model model,
@PathVariable("profileIdentifier") String profileIdentifier) throws Exception {
Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
return Utils.getJQGridJSON(clientService.findAllClients(profileId), "clients");
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile/{profileIdentifier}/clients\"",
",",
"method",
"=",
"RequestMethod",
".",
"GET",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"getClientList",
"(",
"Model",
"model",
","... | Returns information about all clients for a profile
@param model
@param profileIdentifier
@return
@throws Exception | [
"Returns",
"information",
"about",
"all",
"clients",
"for",
"a",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java#L65-L73 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java | ClientController.getClient | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.GET)
public
@ResponseBody
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;
} | java | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.GET)
public
@ResponseBody
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;
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile/{profileIdentifier}/clients/{clientUUID}\"",
",",
"method",
"=",
"RequestMethod",
".",
"GET",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"getClient",
"(",
"Model",
"mode... | Returns information for a specific client
@param model
@param profileIdentifier
@param clientUUID
@return
@throws Exception | [
"Returns",
"information",
"for",
"a",
"specific",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java#L84-L94 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java | ClientController.addClient | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients", method = RequestMethod.POST)
public
@ResponseBody
HashMap<String, Object> addClient(Model model,
@PathVariable("profileIdentifier") String profileIdentifier,
@RequestParam(required = false) String friendlyName) throws Exception {
Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
// make sure client with this name does not already exist
if (null != clientService.findClientFromFriendlyName(profileId, friendlyName)) {
throw new Exception("Cannot add client. Friendly name already in use.");
}
Client client = clientService.add(profileId);
// set friendly name if it was specified
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;
} | java | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients", method = RequestMethod.POST)
public
@ResponseBody
HashMap<String, Object> addClient(Model model,
@PathVariable("profileIdentifier") String profileIdentifier,
@RequestParam(required = false) String friendlyName) throws Exception {
Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
// make sure client with this name does not already exist
if (null != clientService.findClientFromFriendlyName(profileId, friendlyName)) {
throw new Exception("Cannot add client. Friendly name already in use.");
}
Client client = clientService.add(profileId);
// set friendly name if it was specified
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;
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile/{profileIdentifier}/clients\"",
",",
"method",
"=",
"RequestMethod",
".",
"POST",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"addClient",
"(",
"Model",
"model",
",",
... | Returns a new client id for the profileIdentifier
@param model
@param profileIdentifier
@return json with a new client_id
@throws Exception | [
"Returns",
"a",
"new",
"client",
"id",
"for",
"the",
"profileIdentifier"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java#L104-L128 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java | ClientController.updateClient | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.POST)
public
@ResponseBody
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;
} | java | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.POST)
public
@ResponseBody
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;
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile/{profileIdentifier}/clients/{clientUUID}\"",
",",
"method",
"=",
"RequestMethod",
".",
"POST",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"updateClient",
"(",
"Model",
"... | Update properties for a specific client id
@param model
@param profileIdentifier
@param clientUUID
@param active - true false depending on if the client should be active
@param reset - true to reset the state of a client(clears settings for all paths and disables the client)
@return
@throws Exception | [
"Update",
"properties",
"for",
"a",
"specific",
"client",
"id"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java#L141-L168 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java | ClientController.deleteClient | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.DELETE)
public
@ResponseBody
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;
} | java | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/{clientUUID}", method = RequestMethod.DELETE)
public
@ResponseBody
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;
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile/{profileIdentifier}/clients/{clientUUID}\"",
",",
"method",
"=",
"RequestMethod",
".",
"DELETE",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"deleteClient",
"(",
"Model",
... | Deletes a specific client id for a profile
@param model
@param profileIdentifier
@param clientUUID
@return returns the table of the remaining clients or an exception if deletion failed for some reason
@throws Exception | [
"Deletes",
"a",
"specific",
"client",
"id",
"for",
"a",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java#L195-L211 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java | ClientController.deleteClient | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/delete", method = RequestMethod.POST)
public
@ResponseBody
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;
} | java | @RequestMapping(value = "/api/profile/{profileIdentifier}/clients/delete", method = RequestMethod.POST)
public
@ResponseBody
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;
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile/{profileIdentifier}/clients/delete\"",
",",
"method",
"=",
"RequestMethod",
".",
"POST",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"deleteClient",
"(",
"Model",
"model"... | Bulk delete clients from a profile.
@param model
@param profileIdentifier
@param clientUUID
@return returns the table of the remaining clients or an exception if deletion failed for some reason
@throws Exception | [
"Bulk",
"delete",
"clients",
"from",
"a",
"profile",
"."
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ClientController.java#L222-L245 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/PluginController.java | PluginController.getPluginInformation | @RequestMapping(value = "/api/plugins", method = RequestMethod.GET)
public
@ResponseBody
HashMap<String, Object> getPluginInformation() {
return pluginInformation();
} | java | @RequestMapping(value = "/api/plugins", method = RequestMethod.GET)
public
@ResponseBody
HashMap<String, Object> getPluginInformation() {
return pluginInformation();
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/plugins\"",
",",
"method",
"=",
"RequestMethod",
".",
"GET",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"getPluginInformation",
"(",
")",
"{",
"return",
"pluginInformation",... | Obtain plugin information
@return | [
"Obtain",
"plugin",
"information"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/PluginController.java#L41-L46 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/PluginController.java | PluginController.addPluginPath | @RequestMapping(value = "/api/plugins", method = RequestMethod.POST)
public
@ResponseBody
HashMap<String, Object> addPluginPath(Model model, Plugin add) throws Exception {
PluginManager.getInstance().addPluginPath(add.getPath());
return pluginInformation();
} | java | @RequestMapping(value = "/api/plugins", method = RequestMethod.POST)
public
@ResponseBody
HashMap<String, Object> addPluginPath(Model model, Plugin add) throws Exception {
PluginManager.getInstance().addPluginPath(add.getPath());
return pluginInformation();
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/plugins\"",
",",
"method",
"=",
"RequestMethod",
".",
"POST",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"addPluginPath",
"(",
"Model",
"model",
",",
"Plugin",
"add",
")... | Add a plugin path
@param model
@param add
@return
@throws Exception | [
"Add",
"a",
"plugin",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/PluginController.java#L66-L73 | train |
groupon/odo | examples/api-usage/src/main/java/com/groupon/odo/sample/SampleClient.java | SampleClient.addOverrideToPath | public static void addOverrideToPath() throws Exception {
Client client = new Client("ProfileName", false);
// Use the fully qualified name for a plugin override.
client.addMethodToResponseOverride("Test Path", "com.groupon.odo.sample.Common.delay");
// The third argument is the ordinal - the nth instance of this override added to this path
// The final arguments count and type are determined by the override. "delay" used in this sample
// has a single int argument - # of milliseconds delay to simulate
client.setMethodArguments("Test Path", "com.groupon.odo.sample.Common.delay", 1, "100");
} | java | public static void addOverrideToPath() throws Exception {
Client client = new Client("ProfileName", false);
// Use the fully qualified name for a plugin override.
client.addMethodToResponseOverride("Test Path", "com.groupon.odo.sample.Common.delay");
// The third argument is the ordinal - the nth instance of this override added to this path
// The final arguments count and type are determined by the override. "delay" used in this sample
// has a single int argument - # of milliseconds delay to simulate
client.setMethodArguments("Test Path", "com.groupon.odo.sample.Common.delay", 1, "100");
} | [
"public",
"static",
"void",
"addOverrideToPath",
"(",
")",
"throws",
"Exception",
"{",
"Client",
"client",
"=",
"new",
"Client",
"(",
"\"ProfileName\"",
",",
"false",
")",
";",
"// Use the fully qualified name for a plugin override.",
"client",
".",
"addMethodToResponse... | Demonstrates how to add an override to an existing path | [
"Demonstrates",
"how",
"to",
"add",
"an",
"override",
"to",
"an",
"existing",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/examples/api-usage/src/main/java/com/groupon/odo/sample/SampleClient.java#L42-L52 | train |
groupon/odo | examples/api-usage/src/main/java/com/groupon/odo/sample/SampleClient.java | SampleClient.getHistory | public static void getHistory() throws Exception{
Client client = new Client("ProfileName", false);
// Obtain the 100 history entries starting from offset 0
History[] history = client.refreshHistory(100, 0);
client.clearHistory();
} | java | public static void getHistory() throws Exception{
Client client = new Client("ProfileName", false);
// Obtain the 100 history entries starting from offset 0
History[] history = client.refreshHistory(100, 0);
client.clearHistory();
} | [
"public",
"static",
"void",
"getHistory",
"(",
")",
"throws",
"Exception",
"{",
"Client",
"client",
"=",
"new",
"Client",
"(",
"\"ProfileName\"",
",",
"false",
")",
";",
"// Obtain the 100 history entries starting from offset 0",
"History",
"[",
"]",
"history",
"=",... | Demonstrates obtaining the request history data from a test run | [
"Demonstrates",
"obtaining",
"the",
"request",
"history",
"data",
"from",
"a",
"test",
"run"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/examples/api-usage/src/main/java/com/groupon/odo/sample/SampleClient.java#L99-L106 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java | ProfileController.list | @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";
} | java | @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";
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/profiles\"",
",",
"method",
"=",
"RequestMethod",
".",
"GET",
")",
"public",
"String",
"list",
"(",
"Model",
"model",
")",
"{",
"Profile",
"profiles",
"=",
"new",
"Profile",
"(",
")",
";",
"model",
".",
"addA... | This is the profiles page. this is the 'regular' page when the url is typed in | [
"This",
"is",
"the",
"profiles",
"page",
".",
"this",
"is",
"the",
"regular",
"page",
"when",
"the",
"url",
"is",
"typed",
"in"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java#L50-L58 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java | ProfileController.getList | @RequestMapping(value = "/api/profile", method = RequestMethod.GET)
public
@ResponseBody
HashMap<String, Object> getList(Model model) throws Exception {
logger.info("Using a GET request to list profiles");
return Utils.getJQGridJSON(profileService.findAllProfiles(), "profiles");
} | java | @RequestMapping(value = "/api/profile", method = RequestMethod.GET)
public
@ResponseBody
HashMap<String, Object> getList(Model model) throws Exception {
logger.info("Using a GET request to list profiles");
return Utils.getJQGridJSON(profileService.findAllProfiles(), "profiles");
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile\"",
",",
"method",
"=",
"RequestMethod",
".",
"GET",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"getList",
"(",
"Model",
"model",
")",
"throws",
"Exception",
"{"... | Obtain collection of profiles
@param model
@return
@throws Exception | [
"Obtain",
"collection",
"of",
"profiles"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java#L67-L73 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java | ProfileController.addProfile | @RequestMapping(value = "/api/profile", method = RequestMethod.POST)
public
@ResponseBody
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");
} | java | @RequestMapping(value = "/api/profile", method = RequestMethod.POST)
public
@ResponseBody
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");
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile\"",
",",
"method",
"=",
"RequestMethod",
".",
"POST",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"addProfile",
"(",
"Model",
"model",
",",
"String",
"name",
")",... | Add profile to database, return collection of profile data. Called when 'enter' is hit in the UI
instead of 'submit' button
@param model
@param name
@return
@throws Exception | [
"Add",
"profile",
"to",
"database",
"return",
"collection",
"of",
"profile",
"data",
".",
"Called",
"when",
"enter",
"is",
"hit",
"in",
"the",
"UI",
"instead",
"of",
"submit",
"button"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java#L84-L90 | train |
groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java | ProfileController.deleteProfile | @RequestMapping(value = "/api/profile", method = RequestMethod.DELETE)
public
@ResponseBody
HashMap<String, Object> deleteProfile(Model model, int id) throws Exception {
profileService.remove(id);
return Utils.getJQGridJSON(profileService.findAllProfiles(), "profiles");
} | java | @RequestMapping(value = "/api/profile", method = RequestMethod.DELETE)
public
@ResponseBody
HashMap<String, Object> deleteProfile(Model model, int id) throws Exception {
profileService.remove(id);
return Utils.getJQGridJSON(profileService.findAllProfiles(), "profiles");
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/profile\"",
",",
"method",
"=",
"RequestMethod",
".",
"DELETE",
")",
"public",
"@",
"ResponseBody",
"HashMap",
"<",
"String",
",",
"Object",
">",
"deleteProfile",
"(",
"Model",
"model",
",",
"int",
"id",
")",... | Delete a profile
@param model
@param id
@return
@throws Exception | [
"Delete",
"a",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ProfileController.java#L100-L106 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java | HistoryService.cullHistory | public void cullHistory(final int profileId, final String clientUUID, final int limit) throws Exception {
//Allow only 1 delete thread to run
if (threadActive) {
return;
}
threadActive = true;
//Create a thread so proxy will continue to work during long delete
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
String sqlQuery = "SELECT COUNT(" + Constants.GENERIC_ID + ") FROM " + Constants.DB_TABLE_HISTORY + " ";
// see if profileId is set or not (-1)
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;
}
}
//Find the last item in the table
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;
//Delete 100 items at a time until 10000 are deleted
//Do this so table is unlocked frequently to allow other proxy items to access it
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();
} | java | public void cullHistory(final int profileId, final String clientUUID, final int limit) throws Exception {
//Allow only 1 delete thread to run
if (threadActive) {
return;
}
threadActive = true;
//Create a thread so proxy will continue to work during long delete
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
String sqlQuery = "SELECT COUNT(" + Constants.GENERIC_ID + ") FROM " + Constants.DB_TABLE_HISTORY + " ";
// see if profileId is set or not (-1)
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;
}
}
//Find the last item in the table
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;
//Delete 100 items at a time until 10000 are deleted
//Do this so table is unlocked frequently to allow other proxy items to access it
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();
} | [
"public",
"void",
"cullHistory",
"(",
"final",
"int",
"profileId",
",",
"final",
"String",
"clientUUID",
",",
"final",
"int",
"limit",
")",
"throws",
"Exception",
"{",
"//Allow only 1 delete thread to run",
"if",
"(",
"threadActive",
")",
"{",
"return",
";",
"}"... | Removes old entries in the history table for the given profile and client UUID
@param profileId ID of profile
@param clientUUID UUID of client
@param limit Maximum number of history entries to remove
@throws Exception exception | [
"Removes",
"old",
"entries",
"in",
"the",
"history",
"table",
"for",
"the",
"given",
"profile",
"and",
"client",
"UUID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java#L81-L151 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java | HistoryService.getHistoryCount | 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 + " ";
// see if profileId is set or not (-1)
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;
} | java | 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 + " ";
// see if profileId is set or not (-1)
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;
} | [
"public",
"int",
"getHistoryCount",
"(",
"int",
"profileId",
",",
"String",
"clientUUID",
",",
"HashMap",
"<",
"String",
",",
"String",
"[",
"]",
">",
"searchFilter",
")",
"{",
"int",
"count",
"=",
"0",
";",
"Statement",
"query",
"=",
"null",
";",
"Resul... | Returns the number of history entries for a client
@param profileId ID of profile
@param clientUUID UUID of client
@param searchFilter unused
@return number of history entries | [
"Returns",
"the",
"number",
"of",
"history",
"entries",
"for",
"a",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java#L311-L357 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java | HistoryService.getHistoryForID | 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;
} | java | 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;
} | [
"public",
"History",
"getHistoryForID",
"(",
"int",
"id",
")",
"{",
"History",
"history",
"=",
"null",
";",
"PreparedStatement",
"query",
"=",
"null",
";",
"ResultSet",
"results",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
... | Get history for a specific database ID
@param id ID of history entry
@return History entry | [
"Get",
"history",
"for",
"a",
"specific",
"database",
"ID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java#L478-L510 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java | HistoryService.clearHistory | public void clearHistory(int profileId, String clientUUID) {
PreparedStatement query = null;
try (Connection sqlConnection = sqlService.getConnection()) {
String sqlQuery = "DELETE FROM " + Constants.DB_TABLE_HISTORY + " ";
// see if profileId is null or not (-1)
if (profileId != -1) {
sqlQuery += "WHERE " + Constants.GENERIC_PROFILE_ID + "=" + profileId;
}
// see if clientUUID is null or not
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) {
}
}
} | java | public void clearHistory(int profileId, String clientUUID) {
PreparedStatement query = null;
try (Connection sqlConnection = sqlService.getConnection()) {
String sqlQuery = "DELETE FROM " + Constants.DB_TABLE_HISTORY + " ";
// see if profileId is null or not (-1)
if (profileId != -1) {
sqlQuery += "WHERE " + Constants.GENERIC_PROFILE_ID + "=" + profileId;
}
// see if clientUUID is null or not
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) {
}
}
} | [
"public",
"void",
"clearHistory",
"(",
"int",
"profileId",
",",
"String",
"clientUUID",
")",
"{",
"PreparedStatement",
"query",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
")",
"{",
"String",
... | Clear history for a client
@param profileId ID of profile
@param clientUUID UUID of client | [
"Clear",
"history",
"for",
"a",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/HistoryService.java#L518-L548 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.destroy | public void destroy() throws Exception {
if (_clientId == null) {
return;
}
// delete the clientId here
String uri = BASE_PROFILE + uriEncode(_profileName) + "/" + BASE_CLIENTS + "/" + _clientId;
try {
doDelete(uri, null);
} catch (Exception e) {
// some sort of error
throw new Exception("Could not delete a proxy client");
}
} | java | public void destroy() throws Exception {
if (_clientId == null) {
return;
}
// delete the clientId here
String uri = BASE_PROFILE + uriEncode(_profileName) + "/" + BASE_CLIENTS + "/" + _clientId;
try {
doDelete(uri, null);
} catch (Exception e) {
// some sort of error
throw new Exception("Could not delete a proxy client");
}
} | [
"public",
"void",
"destroy",
"(",
")",
"throws",
"Exception",
"{",
"if",
"(",
"_clientId",
"==",
"null",
")",
"{",
"return",
";",
"}",
"// delete the clientId here",
"String",
"uri",
"=",
"BASE_PROFILE",
"+",
"uriEncode",
"(",
"_profileName",
")",
"+",
"\"/\... | Call when you are done with the client
@throws Exception | [
"Call",
"when",
"you",
"are",
"done",
"with",
"the",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L145-L158 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setHostName | public void setHostName(String hostName) {
if (hostName == null || hostName.contains(":")) {
return;
}
ODO_HOST = hostName;
BASE_URL = "http://" + ODO_HOST + ":" + API_PORT + "/" + API_BASE + "/";
} | java | public void setHostName(String hostName) {
if (hostName == null || hostName.contains(":")) {
return;
}
ODO_HOST = hostName;
BASE_URL = "http://" + ODO_HOST + ":" + API_PORT + "/" + API_BASE + "/";
} | [
"public",
"void",
"setHostName",
"(",
"String",
"hostName",
")",
"{",
"if",
"(",
"hostName",
"==",
"null",
"||",
"hostName",
".",
"contains",
"(",
"\":\"",
")",
")",
"{",
"return",
";",
"}",
"ODO_HOST",
"=",
"hostName",
";",
"BASE_URL",
"=",
"\"http://\"... | Set the host running the Odo instance to configure
@param hostName name of host | [
"Set",
"the",
"host",
"running",
"the",
"Odo",
"instance",
"to",
"configure"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L195-L201 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setDefaultHostName | public static void setDefaultHostName(String hostName) {
if (hostName == null || hostName.contains(":")) {
return;
}
DEFAULT_BASE_URL = "http://" + hostName + ":" + DEFAULT_API_PORT + "/" + API_BASE + "/";
} | java | public static void setDefaultHostName(String hostName) {
if (hostName == null || hostName.contains(":")) {
return;
}
DEFAULT_BASE_URL = "http://" + hostName + ":" + DEFAULT_API_PORT + "/" + API_BASE + "/";
} | [
"public",
"static",
"void",
"setDefaultHostName",
"(",
"String",
"hostName",
")",
"{",
"if",
"(",
"hostName",
"==",
"null",
"||",
"hostName",
".",
"contains",
"(",
"\":\"",
")",
")",
"{",
"return",
";",
"}",
"DEFAULT_BASE_URL",
"=",
"\"http://\"",
"+",
"ho... | Set the default host running the Odo instance to configure. Allows default profile methods and PathValueClient to
operate on remote hosts
@param hostName name of host | [
"Set",
"the",
"default",
"host",
"running",
"the",
"Odo",
"instance",
"to",
"configure",
".",
"Allows",
"default",
"profile",
"methods",
"and",
"PathValueClient",
"to",
"operate",
"on",
"remote",
"hosts"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L209-L214 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.filterHistory | 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);
} | java | 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);
} | [
"public",
"History",
"[",
"]",
"filterHistory",
"(",
"String",
"...",
"filters",
")",
"throws",
"Exception",
"{",
"BasicNameValuePair",
"[",
"]",
"params",
";",
"if",
"(",
"filters",
".",
"length",
">",
"0",
")",
"{",
"params",
"=",
"new",
"BasicNameValueP... | Retrieve the request History based on the specified filters.
If no filter is specified, return the default size history.
@param filters filters to be applied
@return array of History items
@throws Exception exception | [
"Retrieve",
"the",
"request",
"History",
"based",
"on",
"the",
"specified",
"filters",
".",
"If",
"no",
"filter",
"is",
"specified",
"return",
"the",
"default",
"size",
"history",
"."
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L224-L236 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.refreshHistory | 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);
} | java | 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);
} | [
"public",
"History",
"[",
"]",
"refreshHistory",
"(",
"int",
"limit",
",",
"int",
"offset",
")",
"throws",
"Exception",
"{",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"{",
"new",
"BasicNameValuePair",
"(",
"\"limit\"",
",",
"String",
".",
"valueOf",
"("... | refresh the most recent history entries
@param limit number of entries to populate
@param offset number of most recent entries to skip
@return populated history entries
@throws Exception exception | [
"refresh",
"the",
"most",
"recent",
"history",
"entries"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L366-L372 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.clearHistory | 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");
}
} | java | 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");
}
} | [
"public",
"void",
"clearHistory",
"(",
")",
"throws",
"Exception",
"{",
"String",
"uri",
";",
"try",
"{",
"uri",
"=",
"HISTORY",
"+",
"uriEncode",
"(",
"_profileName",
")",
";",
"doDelete",
"(",
"uri",
",",
"null",
")",
";",
"}",
"catch",
"(",
"Excepti... | Delete the proxy history for the active profile
@throws Exception exception | [
"Delete",
"the",
"proxy",
"history",
"for",
"the",
"active",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L379-L387 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.toggleProfile | public boolean toggleProfile(Boolean enabled) {
// TODO: make this return values properly
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) {
// some sort of error
System.out.println(e.getMessage());
return false;
}
return true;
} | java | public boolean toggleProfile(Boolean enabled) {
// TODO: make this return values properly
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) {
// some sort of error
System.out.println(e.getMessage());
return false;
}
return true;
} | [
"public",
"boolean",
"toggleProfile",
"(",
"Boolean",
"enabled",
")",
"{",
"// TODO: make this return values properly",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"{",
"new",
"BasicNameValuePair",
"(",
"\"active\"",
",",
"enabled",
".",
"toString",
"(",
")",
")"... | Turn this profile on or off
@param enabled true or false
@return true on success, false otherwise | [
"Turn",
"this",
"profile",
"on",
"or",
"off"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L403-L422 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setCustomResponse | public boolean setCustomResponse(String pathName, String customResponse) throws Exception {
// figure out the new ordinal
int nextOrdinal = this.getNextOrdinalForMethodId(-1, pathName);
// add override
this.addMethodToResponseOverride(pathName, "-1");
// set argument
return this.setMethodArguments(pathName, "-1", nextOrdinal, customResponse);
} | java | public boolean setCustomResponse(String pathName, String customResponse) throws Exception {
// figure out the new ordinal
int nextOrdinal = this.getNextOrdinalForMethodId(-1, pathName);
// add override
this.addMethodToResponseOverride(pathName, "-1");
// set argument
return this.setMethodArguments(pathName, "-1", nextOrdinal, customResponse);
} | [
"public",
"boolean",
"setCustomResponse",
"(",
"String",
"pathName",
",",
"String",
"customResponse",
")",
"throws",
"Exception",
"{",
"// figure out the new ordinal",
"int",
"nextOrdinal",
"=",
"this",
".",
"getNextOrdinalForMethodId",
"(",
"-",
"1",
",",
"pathName",... | Set a custom response for this path
@param pathName name of path
@param customResponse value of custom response
@return true if success, false otherwise
@throws Exception exception | [
"Set",
"a",
"custom",
"response",
"for",
"this",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L568-L577 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.addMethodToResponseOverride | public boolean addMethodToResponseOverride(String pathName, String methodName) {
// need to find out the ID for the method
// TODO: change api for adding methods to take the name instead of ID
try {
Integer overrideId = getOverrideIdForMethodName(methodName);
// now post to path api to add this is a selected override
BasicNameValuePair[] params = {
new BasicNameValuePair("addOverride", overrideId.toString()),
new BasicNameValuePair("profileIdentifier", this._profileName)
};
JSONObject response = new JSONObject(doPost(BASE_PATH + uriEncode(pathName), params));
// check enabled endpoints array to see if this overrideID exists
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;
} | java | public boolean addMethodToResponseOverride(String pathName, String methodName) {
// need to find out the ID for the method
// TODO: change api for adding methods to take the name instead of ID
try {
Integer overrideId = getOverrideIdForMethodName(methodName);
// now post to path api to add this is a selected override
BasicNameValuePair[] params = {
new BasicNameValuePair("addOverride", overrideId.toString()),
new BasicNameValuePair("profileIdentifier", this._profileName)
};
JSONObject response = new JSONObject(doPost(BASE_PATH + uriEncode(pathName), params));
// check enabled endpoints array to see if this overrideID exists
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;
} | [
"public",
"boolean",
"addMethodToResponseOverride",
"(",
"String",
"pathName",
",",
"String",
"methodName",
")",
"{",
"// need to find out the ID for the method",
"// TODO: change api for adding methods to take the name instead of ID",
"try",
"{",
"Integer",
"overrideId",
"=",
"g... | Add a method to the enabled response overrides for a path
@param pathName name of path
@param methodName name of method
@return true if success, false otherwise | [
"Add",
"a",
"method",
"to",
"the",
"enabled",
"response",
"overrides",
"for",
"a",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L617-L641 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setOverrideRepeatCount | 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;
} | java | 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;
} | [
"public",
"boolean",
"setOverrideRepeatCount",
"(",
"String",
"pathName",
",",
"String",
"methodName",
",",
"Integer",
"ordinal",
",",
"Integer",
"repeatCount",
")",
"{",
"try",
"{",
"String",
"methodId",
"=",
"getOverrideIdForMethodName",
"(",
"methodName",
")",
... | Set the repeat count of an override at ordinal index
@param pathName Path name
@param methodName Fully qualified method name
@param ordinal 1-based index of the override within the overrides of type methodName
@param repeatCount new repeat count to set
@return true if success, false otherwise | [
"Set",
"the",
"repeat",
"count",
"of",
"an",
"override",
"at",
"ordinal",
"index"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L652-L667 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setMethodArguments | 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;
} | java | 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;
} | [
"public",
"boolean",
"setMethodArguments",
"(",
"String",
"pathName",
",",
"String",
"methodName",
",",
"Integer",
"ordinal",
",",
"Object",
"...",
"arguments",
")",
"{",
"try",
"{",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"new",
"BasicNameValuePair",
"["... | Set the method arguments for an enabled method override
@param pathName Path name
@param methodName Fully qualified method name
@param ordinal 1-based index of the override within the overrides of type methodName
@param arguments Array of arguments to set(specify all arguments)
@return true if success, false otherwise | [
"Set",
"the",
"method",
"arguments",
"for",
"an",
"enabled",
"method",
"override"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L704-L723 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.createPath | 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();
}
} | java | 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();
}
} | [
"public",
"void",
"createPath",
"(",
"String",
"pathName",
",",
"String",
"pathValue",
",",
"String",
"requestType",
")",
"{",
"try",
"{",
"int",
"type",
"=",
"getRequestTypeFromString",
"(",
"requestType",
")",
";",
"String",
"url",
"=",
"BASE_PATH",
";",
"... | Create a new path
@param pathName friendly name of path
@param pathValue path value or regex
@param requestType path request type. "GET", "POST", etc | [
"Create",
"a",
"new",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L767-L782 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setCustomForDefaultClient | 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;
} | java | 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;
} | [
"protected",
"static",
"boolean",
"setCustomForDefaultClient",
"(",
"String",
"profileName",
",",
"String",
"pathName",
",",
"Boolean",
"isResponse",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"Client",
"client",
"=",
"new",
"Client",
"(",
"profileName",
... | set custom response or request for a profile's default client, ensures profile and path are enabled
@param profileName profileName to modift, default client is used
@param pathName friendly name of path
@param isResponse true if response, false for request
@param customData custom response/request data
@return true if success, false otherwise | [
"set",
"custom",
"response",
"or",
"request",
"for",
"a",
"profile",
"s",
"default",
"client",
"ensures",
"profile",
"and",
"path",
"are",
"enabled"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L793-L808 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setCustomRequestForDefaultClient | public static boolean setCustomRequestForDefaultClient(String profileName, String pathName, String customData) {
try {
return setCustomForDefaultClient(profileName, pathName, false, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | java | public static boolean setCustomRequestForDefaultClient(String profileName, String pathName, String customData) {
try {
return setCustomForDefaultClient(profileName, pathName, false, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | [
"public",
"static",
"boolean",
"setCustomRequestForDefaultClient",
"(",
"String",
"profileName",
",",
"String",
"pathName",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"return",
"setCustomForDefaultClient",
"(",
"profileName",
",",
"pathName",
",",
"false",
"... | set custom request for profile's default client
@param profileName profileName to modify
@param pathName friendly name of path
@param customData custom request data
@return true if success, false otherwise | [
"set",
"custom",
"request",
"for",
"profile",
"s",
"default",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L818-L825 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setCustomResponseForDefaultClient | public static boolean setCustomResponseForDefaultClient(String profileName, String pathName, String customData) {
try {
return setCustomForDefaultClient(profileName, pathName, true, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | java | public static boolean setCustomResponseForDefaultClient(String profileName, String pathName, String customData) {
try {
return setCustomForDefaultClient(profileName, pathName, true, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | [
"public",
"static",
"boolean",
"setCustomResponseForDefaultClient",
"(",
"String",
"profileName",
",",
"String",
"pathName",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"return",
"setCustomForDefaultClient",
"(",
"profileName",
",",
"pathName",
",",
"true",
"... | set custom response for profile's default client
@param profileName profileName to modify
@param pathName friendly name of path
@param customData custom request data
@return true if success, false otherwise | [
"set",
"custom",
"response",
"for",
"profile",
"s",
"default",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L835-L842 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setCustomRequestForDefaultProfile | public static boolean setCustomRequestForDefaultProfile(String pathName, String customData) {
try {
return setCustomForDefaultProfile(pathName, false, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | java | public static boolean setCustomRequestForDefaultProfile(String pathName, String customData) {
try {
return setCustomForDefaultProfile(pathName, false, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | [
"public",
"static",
"boolean",
"setCustomRequestForDefaultProfile",
"(",
"String",
"pathName",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"return",
"setCustomForDefaultProfile",
"(",
"pathName",
",",
"false",
",",
"customData",
")",
";",
"}",
"catch",
"(",... | set custom request for the default profile's default client
@param pathName friendly name of path
@param customData custom response/request data
@return true if success, false otherwise | [
"set",
"custom",
"request",
"for",
"the",
"default",
"profile",
"s",
"default",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L871-L878 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.setCustomResponseForDefaultProfile | public static boolean setCustomResponseForDefaultProfile(String pathName, String customData) {
try {
return setCustomForDefaultProfile(pathName, true, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | java | public static boolean setCustomResponseForDefaultProfile(String pathName, String customData) {
try {
return setCustomForDefaultProfile(pathName, true, customData);
} catch (Exception e) {
e.printStackTrace();
}
return false;
} | [
"public",
"static",
"boolean",
"setCustomResponseForDefaultProfile",
"(",
"String",
"pathName",
",",
"String",
"customData",
")",
"{",
"try",
"{",
"return",
"setCustomForDefaultProfile",
"(",
"pathName",
",",
"true",
",",
"customData",
")",
";",
"}",
"catch",
"(",... | set custom response for the default profile's default client
@param pathName friendly name of path
@param customData custom response/request data
@return true if success, false otherwise | [
"set",
"custom",
"response",
"for",
"the",
"default",
"profile",
"s",
"default",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L887-L894 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.getDefaultProfile | 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) {
// some sort of error
throw new Exception("Could not create a proxy client");
}
return null;
} | java | 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) {
// some sort of error
throw new Exception("Could not create a proxy client");
}
return null;
} | [
"protected",
"static",
"JSONObject",
"getDefaultProfile",
"(",
")",
"throws",
"Exception",
"{",
"String",
"uri",
"=",
"DEFAULT_BASE_URL",
"+",
"BASE_PROFILE",
";",
"try",
"{",
"JSONObject",
"response",
"=",
"new",
"JSONObject",
"(",
"doGet",
"(",
"uri",
",",
"... | get the default profile
@return representation of default profile
@throws Exception exception | [
"get",
"the",
"default",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L902-L917 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.getNextOrdinalForMethodId | 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;
} | java | 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;
} | [
"private",
"Integer",
"getNextOrdinalForMethodId",
"(",
"int",
"methodId",
",",
"String",
"pathName",
")",
"throws",
"Exception",
"{",
"String",
"pathInfo",
"=",
"doGet",
"(",
"BASE_PATH",
"+",
"uriEncode",
"(",
"pathName",
")",
",",
"new",
"BasicNameValuePair",
... | Get the next available ordinal for a method ID
@param methodId ID of method
@return value of next ordinal
@throws Exception exception | [
"Get",
"the",
"next",
"available",
"ordinal",
"for",
"a",
"method",
"ID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L932-L944 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.getRequestTypeFromString | 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;
} | java | 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;
} | [
"protected",
"int",
"getRequestTypeFromString",
"(",
"String",
"requestType",
")",
"{",
"if",
"(",
"\"GET\"",
".",
"equals",
"(",
"requestType",
")",
")",
"{",
"return",
"REQUEST_TYPE_GET",
";",
"}",
"if",
"(",
"\"POST\"",
".",
"equals",
"(",
"requestType",
... | Convert a request type string to value
@param requestType String value of request type GET/POST/PUT/DELETE
@return Matching REQUEST_TYPE. Defaults to ALL | [
"Convert",
"a",
"request",
"type",
"string",
"to",
"value"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L957-L971 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.addServerMapping | 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);
} | java | 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);
} | [
"public",
"ServerRedirect",
"addServerMapping",
"(",
"String",
"sourceHost",
",",
"String",
"destinationHost",
",",
"String",
"hostHeader",
")",
"{",
"JSONObject",
"response",
"=",
"null",
";",
"ArrayList",
"<",
"BasicNameValuePair",
">",
"params",
"=",
"new",
"Ar... | Add a new server mapping to current profile
@param sourceHost source hostname
@param destinationHost destination hostname
@param hostHeader host header
@return ServerRedirect | [
"Add",
"a",
"new",
"server",
"mapping",
"to",
"current",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1011-L1031 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.deleteServerMapping | 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;
} | java | 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;
} | [
"public",
"List",
"<",
"ServerRedirect",
">",
"deleteServerMapping",
"(",
"int",
"serverMappingId",
")",
"{",
"ArrayList",
"<",
"ServerRedirect",
">",
"servers",
"=",
"new",
"ArrayList",
"<",
"ServerRedirect",
">",
"(",
")",
";",
"try",
"{",
"JSONArray",
"serv... | Remove a server mapping from current profile by ID
@param serverMappingId server mapping ID
@return Collection of updated ServerRedirects | [
"Remove",
"a",
"server",
"mapping",
"from",
"current",
"profile",
"by",
"ID"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1039-L1056 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.getServerMappings | 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;
} | java | 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;
} | [
"public",
"List",
"<",
"ServerRedirect",
">",
"getServerMappings",
"(",
")",
"{",
"ArrayList",
"<",
"ServerRedirect",
">",
"servers",
"=",
"new",
"ArrayList",
"<",
"ServerRedirect",
">",
"(",
")",
";",
"try",
"{",
"JSONObject",
"response",
"=",
"new",
"JSONO... | Get a list of all active server mappings defined for current profile
@return Collection of ServerRedirects | [
"Get",
"a",
"list",
"of",
"all",
"active",
"server",
"mappings",
"defined",
"for",
"current",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1063-L1081 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.updateServerRedirectHost | 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;
} | java | 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;
} | [
"public",
"ServerRedirect",
"updateServerRedirectHost",
"(",
"int",
"serverMappingId",
",",
"String",
"hostHeader",
")",
"{",
"ServerRedirect",
"redirect",
"=",
"new",
"ServerRedirect",
"(",
")",
";",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"{",
"new",
"Bas... | Update server mapping's host header
@param serverMappingId ID of server mapping
@param hostHeader value of host header
@return updated ServerRedirect | [
"Update",
"server",
"mapping",
"s",
"host",
"header"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1159-L1173 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.addServerGroup | 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;
} | java | 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;
} | [
"public",
"ServerGroup",
"addServerGroup",
"(",
"String",
"groupName",
")",
"{",
"ServerGroup",
"group",
"=",
"new",
"ServerGroup",
"(",
")",
";",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"{",
"new",
"BasicNameValuePair",
"(",
"\"name\"",
",",
"groupName",... | Create a new server group
@param groupName name of server group
@return Created ServerGroup | [
"Create",
"a",
"new",
"server",
"group"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1205-L1220 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.getServerGroups | 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;
} | java | 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;
} | [
"public",
"List",
"<",
"ServerGroup",
">",
"getServerGroups",
"(",
")",
"{",
"ArrayList",
"<",
"ServerGroup",
">",
"groups",
"=",
"new",
"ArrayList",
"<",
"ServerGroup",
">",
"(",
")",
";",
"try",
"{",
"JSONObject",
"response",
"=",
"new",
"JSONObject",
"(... | Get the collection of the server groups
@return Collection of active server groups | [
"Get",
"the",
"collection",
"of",
"the",
"server",
"groups"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1249-L1265 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.updateServerGroupName | 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;
} | java | 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;
} | [
"public",
"ServerGroup",
"updateServerGroupName",
"(",
"int",
"serverGroupId",
",",
"String",
"name",
")",
"{",
"ServerGroup",
"serverGroup",
"=",
"null",
";",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"{",
"new",
"BasicNameValuePair",
"(",
"\"name\"",
",",
... | Update the server group's name
@param serverGroupId ID of server group
@param name new name of server group
@return updated ServerGroup | [
"Update",
"the",
"server",
"group",
"s",
"name"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1274-L1288 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.uploadConfigurationAndProfile | 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;
}
} | java | 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;
}
} | [
"public",
"boolean",
"uploadConfigurationAndProfile",
"(",
"String",
"fileName",
",",
"String",
"odoImport",
")",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"fileName",
")",
";",
"MultipartEntityBuilder",
"multipartEntityBuilder",
"=",
"MultipartEntityBuilder",
"."... | Upload file and set odo overrides and configuration of odo
@param fileName File containing configuration
@param odoImport Import odo configuration in addition to overrides
@return If upload was successful | [
"Upload",
"file",
"and",
"set",
"odo",
"overrides",
"and",
"configuration",
"of",
"odo"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1347-L1364 | train |
groupon/odo | client/src/main/java/com/groupon/odo/client/Client.java | Client.exportConfigurationAndProfile | 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();
}
} | java | 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();
}
} | [
"public",
"JSONObject",
"exportConfigurationAndProfile",
"(",
"String",
"oldExport",
")",
"{",
"try",
"{",
"BasicNameValuePair",
"[",
"]",
"params",
"=",
"{",
"new",
"BasicNameValuePair",
"(",
"\"oldExport\"",
",",
"oldExport",
")",
"}",
";",
"String",
"url",
"=... | Export the odo overrides setup and odo configuration
@param oldExport Whether this is a backup from scratch or backing up because user will upload after (matches API)
@return The odo configuration and overrides in JSON format, can be written to a file after | [
"Export",
"the",
"odo",
"overrides",
"setup",
"and",
"odo",
"configuration"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/client/src/main/java/com/groupon/odo/client/Client.java#L1372-L1382 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java | BackupService.getGroups | private List<Group> getGroups() throws Exception {
List<Group> groups = new ArrayList<Group>();
List<Group> sourceGroups = PathOverrideService.getInstance().findAllGroups();
// loop through the groups
for (Group sourceGroup : sourceGroups) {
Group group = new Group();
// add all methods
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;
} | java | private List<Group> getGroups() throws Exception {
List<Group> groups = new ArrayList<Group>();
List<Group> sourceGroups = PathOverrideService.getInstance().findAllGroups();
// loop through the groups
for (Group sourceGroup : sourceGroups) {
Group group = new Group();
// add all methods
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;
} | [
"private",
"List",
"<",
"Group",
">",
"getGroups",
"(",
")",
"throws",
"Exception",
"{",
"List",
"<",
"Group",
">",
"groups",
"=",
"new",
"ArrayList",
"<",
"Group",
">",
"(",
")",
";",
"List",
"<",
"Group",
">",
"sourceGroups",
"=",
"PathOverrideService"... | Get all Groups
@return
@throws Exception | [
"Get",
"all",
"Groups"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java#L77-L100 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java | BackupService.getProfileBackupData | 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;
} | java | 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;
} | [
"public",
"SingleProfileBackup",
"getProfileBackupData",
"(",
"int",
"profileID",
",",
"String",
"clientUUID",
")",
"throws",
"Exception",
"{",
"SingleProfileBackup",
"singleProfileBackup",
"=",
"new",
"SingleProfileBackup",
"(",
")",
";",
"List",
"<",
"PathOverride",
... | Get the active overrides with parameters and the active server group for a client
@param profileID Id of profile to get configuration for
@param clientUUID Client Id to export configuration
@return SingleProfileBackup containing active overrides and active server group
@throws Exception exception | [
"Get",
"the",
"active",
"overrides",
"with",
"parameters",
"and",
"the",
"active",
"server",
"group",
"for",
"a",
"client"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java#L133-L160 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java | BackupService.getBackupData | 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;
} | java | 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;
} | [
"public",
"Backup",
"getBackupData",
"(",
")",
"throws",
"Exception",
"{",
"Backup",
"backupData",
"=",
"new",
"Backup",
"(",
")",
";",
"backupData",
".",
"setGroups",
"(",
"getGroups",
"(",
")",
")",
";",
"backupData",
".",
"setProfiles",
"(",
"getProfiles"... | Return the structured backup data
@return Backup of current configuration
@throws Exception exception | [
"Return",
"the",
"structured",
"backup",
"data"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java#L188-L198 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java | BackupService.getServerForName | 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;
// we found it, bail out
break;
}
}
return mbeanServer;
} catch (Exception e) {
}
return null;
} | java | 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;
// we found it, bail out
break;
}
}
return mbeanServer;
} catch (Exception e) {
}
return null;
} | [
"private",
"MBeanServer",
"getServerForName",
"(",
"String",
"name",
")",
"{",
"try",
"{",
"MBeanServer",
"mbeanServer",
"=",
"null",
";",
"final",
"ObjectName",
"objectNameQuery",
"=",
"new",
"ObjectName",
"(",
"name",
"+",
"\":type=Service,*\"",
")",
";",
"for... | Returns an MBeanServer with the specified name
@param name
@return | [
"Returns",
"an",
"MBeanServer",
"with",
"the",
"specified",
"name"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/BackupService.java#L396-L414 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.setProxyRequestHeaders | @SuppressWarnings("unchecked")
private void setProxyRequestHeaders(HttpServletRequest httpServletRequest,
HttpMethod httpMethodProxyRequest) throws Exception {
RequestInformation requestInfo = requestInformation.get();
String hostName = HttpUtilities.getHostNameFromURL(httpServletRequest.getRequestURL().toString());
// Get an Enumeration of all of the header names sent by the client
Boolean stripTransferEncoding = false;
Enumeration<String> enumerationOfHeaderNames = httpServletRequest.getHeaderNames();
while (enumerationOfHeaderNames.hasMoreElements()) {
String stringHeaderName = enumerationOfHeaderNames.nextElement();
if (stringHeaderName.equalsIgnoreCase(STRING_CONTENT_LENGTH_HEADER_NAME)) {
// don't add this header
continue;
}
// The forwarding proxy may supply a POST encoding hint in ODO-POST-TYPE
if (stringHeaderName.equalsIgnoreCase("ODO-POST-TYPE") &&
httpServletRequest.getHeader("ODO-POST-TYPE").startsWith("content-length:")) {
stripTransferEncoding = true;
}
logger.info("Current header: {}", stringHeaderName);
// As per the Java Servlet API 2.5 documentation:
// Some headers, such as Accept-Language can be sent by clients
// as several headers each with a different value rather than
// sending the header as a comma separated list.
// Thus, we get an Enumeration of the header values sent by the
// client
Enumeration<String> enumerationOfHeaderValues = httpServletRequest.getHeaders(stringHeaderName);
while (enumerationOfHeaderValues.hasMoreElements()) {
String stringHeaderValue = enumerationOfHeaderValues.nextElement();
// In case the proxy host is running multiple virtual servers,
// rewrite the Host header to ensure that we get content from
// the correct virtual server
if (stringHeaderName.equalsIgnoreCase(STRING_HOST_HEADER_NAME) &&
requestInfo.handle) {
String hostValue = getHostHeaderForHost(hostName);
if (hostValue != null) {
stringHeaderValue = hostValue;
}
}
Header header = new Header(stringHeaderName, stringHeaderValue);
// Set the same header on the proxy request
httpMethodProxyRequest.addRequestHeader(header);
}
}
// this strips transfer encoding headers and adds in the appropriate content-length header
// based on the hint provided in the ODO-POST-TYPE header(sent from BrowserMobProxyHandler)
if (stripTransferEncoding) {
httpMethodProxyRequest.removeRequestHeader("transfer-encoding");
// add content length back in based on the ODO information
String contentLengthHint = httpServletRequest.getHeader("ODO-POST-TYPE");
String[] contentLengthParts = contentLengthHint.split(":");
httpMethodProxyRequest.addRequestHeader("content-length", contentLengthParts[1]);
// remove the odo-post-type header
httpMethodProxyRequest.removeRequestHeader("ODO-POST-TYPE");
}
// bail if we aren't fully handling this request
if (!requestInfo.handle) {
return;
}
// deal with header overrides for the request
processRequestHeaderOverrides(httpMethodProxyRequest);
} | java | @SuppressWarnings("unchecked")
private void setProxyRequestHeaders(HttpServletRequest httpServletRequest,
HttpMethod httpMethodProxyRequest) throws Exception {
RequestInformation requestInfo = requestInformation.get();
String hostName = HttpUtilities.getHostNameFromURL(httpServletRequest.getRequestURL().toString());
// Get an Enumeration of all of the header names sent by the client
Boolean stripTransferEncoding = false;
Enumeration<String> enumerationOfHeaderNames = httpServletRequest.getHeaderNames();
while (enumerationOfHeaderNames.hasMoreElements()) {
String stringHeaderName = enumerationOfHeaderNames.nextElement();
if (stringHeaderName.equalsIgnoreCase(STRING_CONTENT_LENGTH_HEADER_NAME)) {
// don't add this header
continue;
}
// The forwarding proxy may supply a POST encoding hint in ODO-POST-TYPE
if (stringHeaderName.equalsIgnoreCase("ODO-POST-TYPE") &&
httpServletRequest.getHeader("ODO-POST-TYPE").startsWith("content-length:")) {
stripTransferEncoding = true;
}
logger.info("Current header: {}", stringHeaderName);
// As per the Java Servlet API 2.5 documentation:
// Some headers, such as Accept-Language can be sent by clients
// as several headers each with a different value rather than
// sending the header as a comma separated list.
// Thus, we get an Enumeration of the header values sent by the
// client
Enumeration<String> enumerationOfHeaderValues = httpServletRequest.getHeaders(stringHeaderName);
while (enumerationOfHeaderValues.hasMoreElements()) {
String stringHeaderValue = enumerationOfHeaderValues.nextElement();
// In case the proxy host is running multiple virtual servers,
// rewrite the Host header to ensure that we get content from
// the correct virtual server
if (stringHeaderName.equalsIgnoreCase(STRING_HOST_HEADER_NAME) &&
requestInfo.handle) {
String hostValue = getHostHeaderForHost(hostName);
if (hostValue != null) {
stringHeaderValue = hostValue;
}
}
Header header = new Header(stringHeaderName, stringHeaderValue);
// Set the same header on the proxy request
httpMethodProxyRequest.addRequestHeader(header);
}
}
// this strips transfer encoding headers and adds in the appropriate content-length header
// based on the hint provided in the ODO-POST-TYPE header(sent from BrowserMobProxyHandler)
if (stripTransferEncoding) {
httpMethodProxyRequest.removeRequestHeader("transfer-encoding");
// add content length back in based on the ODO information
String contentLengthHint = httpServletRequest.getHeader("ODO-POST-TYPE");
String[] contentLengthParts = contentLengthHint.split(":");
httpMethodProxyRequest.addRequestHeader("content-length", contentLengthParts[1]);
// remove the odo-post-type header
httpMethodProxyRequest.removeRequestHeader("ODO-POST-TYPE");
}
// bail if we aren't fully handling this request
if (!requestInfo.handle) {
return;
}
// deal with header overrides for the request
processRequestHeaderOverrides(httpMethodProxyRequest);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"private",
"void",
"setProxyRequestHeaders",
"(",
"HttpServletRequest",
"httpServletRequest",
",",
"HttpMethod",
"httpMethodProxyRequest",
")",
"throws",
"Exception",
"{",
"RequestInformation",
"requestInfo",
"=",
"request... | Retrieves all of the headers from the servlet request and sets them on
the proxy request
@param httpServletRequest The request object representing the client's request to the
servlet engine
@param httpMethodProxyRequest The request that we are about to send to the proxy host | [
"Retrieves",
"all",
"of",
"the",
"headers",
"from",
"the",
"servlet",
"request",
"and",
"sets",
"them",
"on",
"the",
"proxy",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L410-L480 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.processRequestHeaderOverrides | 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;
}
}
}
} | java | 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;
}
}
}
} | [
"private",
"void",
"processRequestHeaderOverrides",
"(",
"HttpMethod",
"httpMethodProxyRequest",
")",
"throws",
"Exception",
"{",
"RequestInformation",
"requestInfo",
"=",
"requestInformation",
".",
"get",
"(",
")",
";",
"for",
"(",
"EndpointOverride",
"selectedPath",
"... | Apply any applicable header overrides to request
@param httpMethodProxyRequest
@throws Exception | [
"Apply",
"any",
"applicable",
"header",
"overrides",
"to",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L488-L503 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.getHostHeaderForHost | 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;
} | java | 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;
} | [
"private",
"String",
"getHostHeaderForHost",
"(",
"String",
"hostName",
")",
"{",
"List",
"<",
"ServerRedirect",
">",
"servers",
"=",
"serverRedirectService",
".",
"tableServers",
"(",
"requestInformation",
".",
"get",
"(",
")",
".",
"client",
".",
"getId",
"(",... | Obtain host header value for a hostname
@param hostName
@return | [
"Obtain",
"host",
"header",
"value",
"for",
"a",
"hostname"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L511-L523 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.processClientId | private void processClientId(HttpServletRequest httpServletRequest, History history) {
// get the client id from the request header if applicable.. otherwise set to default
// also set the client uuid in the history object
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());
} | java | private void processClientId(HttpServletRequest httpServletRequest, History history) {
// get the client id from the request header if applicable.. otherwise set to default
// also set the client uuid in the history object
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());
} | [
"private",
"void",
"processClientId",
"(",
"HttpServletRequest",
"httpServletRequest",
",",
"History",
"history",
")",
"{",
"// get the client id from the request header if applicable.. otherwise set to default",
"// also set the client uuid in the history object",
"if",
"(",
"httpServ... | Apply the matching client UUID for the request
@param httpServletRequest
@param history | [
"Apply",
"the",
"matching",
"client",
"UUID",
"for",
"the",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L531-L541 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.getApplicablePathNames | private JSONArray getApplicablePathNames (String requestUrl, Integer requestType) throws Exception {
RequestInformation requestInfo = requestInformation.get();
List<EndpointOverride> applicablePaths;
JSONArray pathNames = new JSONArray();
// Get all paths that match the request
applicablePaths = PathOverrideService.getInstance().getSelectedPaths(Constants.OVERRIDE_TYPE_REQUEST, requestInfo.client,
requestInfo.profile,
requestUrl + "?" + requestInfo.originalRequestInfo.getQueryString(),
requestType, true);
// Extract just the path name from each path
for (EndpointOverride path : applicablePaths) {
JSONObject pathName = new JSONObject();
pathName.put("name", path.getPathName());
pathNames.put(pathName);
}
return pathNames;
} | java | private JSONArray getApplicablePathNames (String requestUrl, Integer requestType) throws Exception {
RequestInformation requestInfo = requestInformation.get();
List<EndpointOverride> applicablePaths;
JSONArray pathNames = new JSONArray();
// Get all paths that match the request
applicablePaths = PathOverrideService.getInstance().getSelectedPaths(Constants.OVERRIDE_TYPE_REQUEST, requestInfo.client,
requestInfo.profile,
requestUrl + "?" + requestInfo.originalRequestInfo.getQueryString(),
requestType, true);
// Extract just the path name from each path
for (EndpointOverride path : applicablePaths) {
JSONObject pathName = new JSONObject();
pathName.put("name", path.getPathName());
pathNames.put(pathName);
}
return pathNames;
} | [
"private",
"JSONArray",
"getApplicablePathNames",
"(",
"String",
"requestUrl",
",",
"Integer",
"requestType",
")",
"throws",
"Exception",
"{",
"RequestInformation",
"requestInfo",
"=",
"requestInformation",
".",
"get",
"(",
")",
";",
"List",
"<",
"EndpointOverride",
... | Get the names of the paths that would apply to the request
@param requestUrl URL of the request
@param requestType Type of the request: GET, POST, PUT, or DELETE as integer
@return JSONArray of path names
@throws Exception | [
"Get",
"the",
"names",
"of",
"the",
"paths",
"that",
"would",
"apply",
"to",
"the",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L551-L568 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.getDestinationHostName | 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());
}
// only want to apply the first host name change found
break;
}
}
return hostName;
} | java | 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());
}
// only want to apply the first host name change found
break;
}
}
return hostName;
} | [
"private",
"String",
"getDestinationHostName",
"(",
"String",
"hostName",
")",
"{",
"List",
"<",
"ServerRedirect",
">",
"servers",
"=",
"serverRedirectService",
".",
"tableServers",
"(",
"requestInformation",
".",
"get",
"(",
")",
".",
"client",
".",
"getId",
"(... | Obtain the destination hostname for a source host
@param hostName
@return | [
"Obtain",
"the",
"destination",
"hostname",
"for",
"a",
"source",
"host"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L676-L694 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.processVirtualHostName | 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);
} | java | 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);
} | [
"private",
"void",
"processVirtualHostName",
"(",
"HttpMethod",
"httpMethodProxyRequest",
",",
"HttpServletRequest",
"httpServletRequest",
")",
"{",
"String",
"virtualHostName",
";",
"if",
"(",
"httpMethodProxyRequest",
".",
"getRequestHeader",
"(",
"STRING_HOST_HEADER_NAME",... | 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.
@param httpMethodProxyRequest
@param httpServletRequest | [
"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",
"."
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L791-L799 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.cullDisabledPaths | private void cullDisabledPaths() throws Exception {
ArrayList<EndpointOverride> removePaths = new ArrayList<EndpointOverride>();
RequestInformation requestInfo = requestInformation.get();
for (EndpointOverride selectedPath : requestInfo.selectedResponsePaths) {
// check repeat count on selectedPath
// -1 is unlimited
if (selectedPath != null && selectedPath.getRepeatNumber() == 0) {
// skip
removePaths.add(selectedPath);
} else if (selectedPath != null && selectedPath.getRepeatNumber() != -1) {
// need to decrement the #
selectedPath.updateRepeatNumber(selectedPath.getRepeatNumber() - 1);
}
}
// remove paths if we need to
for (EndpointOverride removePath : removePaths) {
requestInfo.selectedResponsePaths.remove(removePath);
}
} | java | private void cullDisabledPaths() throws Exception {
ArrayList<EndpointOverride> removePaths = new ArrayList<EndpointOverride>();
RequestInformation requestInfo = requestInformation.get();
for (EndpointOverride selectedPath : requestInfo.selectedResponsePaths) {
// check repeat count on selectedPath
// -1 is unlimited
if (selectedPath != null && selectedPath.getRepeatNumber() == 0) {
// skip
removePaths.add(selectedPath);
} else if (selectedPath != null && selectedPath.getRepeatNumber() != -1) {
// need to decrement the #
selectedPath.updateRepeatNumber(selectedPath.getRepeatNumber() - 1);
}
}
// remove paths if we need to
for (EndpointOverride removePath : removePaths) {
requestInfo.selectedResponsePaths.remove(removePath);
}
} | [
"private",
"void",
"cullDisabledPaths",
"(",
")",
"throws",
"Exception",
"{",
"ArrayList",
"<",
"EndpointOverride",
">",
"removePaths",
"=",
"new",
"ArrayList",
"<",
"EndpointOverride",
">",
"(",
")",
";",
"RequestInformation",
"requestInfo",
"=",
"requestInformatio... | Remove paths with no active overrides
@throws Exception | [
"Remove",
"paths",
"with",
"no",
"active",
"overrides"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L806-L827 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.getRemoveHeaders | private ArrayList<String> getRemoveHeaders() throws Exception {
ArrayList<String> headersToRemove = new ArrayList<String>();
for (EndpointOverride selectedPath : requestInformation.get().selectedResponsePaths) {
// check to see if there is custom override data or if we have headers to remove
List<EnabledEndpoint> points = selectedPath.getEnabledEndpoints();
for (EnabledEndpoint endpoint : points) {
// skip if repeat count is 0
if (endpoint.getRepeatNumber() == 0) {
continue;
}
if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_HEADER_OVERRIDE_REMOVE) {
// add to remove headers array
headersToRemove.add(endpoint.getArguments()[0].toString());
endpoint.decrementRepeatNumber();
}
}
}
return headersToRemove;
} | java | private ArrayList<String> getRemoveHeaders() throws Exception {
ArrayList<String> headersToRemove = new ArrayList<String>();
for (EndpointOverride selectedPath : requestInformation.get().selectedResponsePaths) {
// check to see if there is custom override data or if we have headers to remove
List<EnabledEndpoint> points = selectedPath.getEnabledEndpoints();
for (EnabledEndpoint endpoint : points) {
// skip if repeat count is 0
if (endpoint.getRepeatNumber() == 0) {
continue;
}
if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_HEADER_OVERRIDE_REMOVE) {
// add to remove headers array
headersToRemove.add(endpoint.getArguments()[0].toString());
endpoint.decrementRepeatNumber();
}
}
}
return headersToRemove;
} | [
"private",
"ArrayList",
"<",
"String",
">",
"getRemoveHeaders",
"(",
")",
"throws",
"Exception",
"{",
"ArrayList",
"<",
"String",
">",
"headersToRemove",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"for",
"(",
"EndpointOverride",
"selectedPath"... | Obtain collection of headers to remove
@return
@throws Exception | [
"Obtain",
"collection",
"of",
"headers",
"to",
"remove"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L864-L885 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.executeProxyRequest | private void executeProxyRequest(HttpMethod httpMethodProxyRequest,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, History history) {
try {
RequestInformation requestInfo = requestInformation.get();
// Execute the request
// set virtual host so the server knows how to direct the request
// If the host header exists then this uses that value
// Otherwise the hostname from the URL is used
processVirtualHostName(httpMethodProxyRequest, httpServletRequest);
cullDisabledPaths();
// check for existence of ODO_PROXY_HEADER
// finding it indicates a bad loop back through the proxy
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;
}
// set ODO_PROXY_HEADER
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);
// store history
history.setModified(requestInfo.modified);
logRequestHistory(httpMethodProxyRequest, responseWrapper, history);
writeResponseOutput(responseWrapper, requestInfo.jsonpCallback);
} catch (Exception e) {
e.printStackTrace();
}
} | java | private void executeProxyRequest(HttpMethod httpMethodProxyRequest,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, History history) {
try {
RequestInformation requestInfo = requestInformation.get();
// Execute the request
// set virtual host so the server knows how to direct the request
// If the host header exists then this uses that value
// Otherwise the hostname from the URL is used
processVirtualHostName(httpMethodProxyRequest, httpServletRequest);
cullDisabledPaths();
// check for existence of ODO_PROXY_HEADER
// finding it indicates a bad loop back through the proxy
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;
}
// set ODO_PROXY_HEADER
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);
// store history
history.setModified(requestInfo.modified);
logRequestHistory(httpMethodProxyRequest, responseWrapper, history);
writeResponseOutput(responseWrapper, requestInfo.jsonpCallback);
} catch (Exception e) {
e.printStackTrace();
}
} | [
"private",
"void",
"executeProxyRequest",
"(",
"HttpMethod",
"httpMethodProxyRequest",
",",
"HttpServletRequest",
"httpServletRequest",
",",
"HttpServletResponse",
"httpServletResponse",
",",
"History",
"history",
")",
"{",
"try",
"{",
"RequestInformation",
"requestInfo",
"... | Execute a request through Odo processing
@param httpMethodProxyRequest
@param httpServletRequest
@param httpServletResponse
@param history | [
"Execute",
"a",
"request",
"through",
"Odo",
"processing"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L895-L947 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.executeRequest | private void executeRequest(HttpMethod httpMethodProxyRequest,
HttpServletRequest httpServletRequest,
PluginResponse httpServletResponse,
History history) throws Exception {
int intProxyResponseCode = 999;
// Create a default HttpClient
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);
// exception handling for httpclient
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) {
// Return a gateway timeout
httpServletResponse.setStatus(504);
httpServletResponse.setHeader(Constants.HEADER_STATUS, "504");
httpServletResponse.flushBuffer();
return;
}
logger.info("Response code: {}, {}", intProxyResponseCode,
HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString()));
// Pass the response code back to the client
httpServletResponse.setStatus(intProxyResponseCode);
// Pass response headers back to the client
Header[] headerArrayResponse = httpMethodProxyRequest.getResponseHeaders();
for (Header header : headerArrayResponse) {
// remove transfer-encoding header. The http libraries will handle this encoding
if (header.getName().toLowerCase().equals("transfer-encoding")) {
continue;
}
httpServletResponse.setHeader(header.getName(), header.getValue());
}
// there is no data for a HTTP 304 or 204
if (intProxyResponseCode != HttpServletResponse.SC_NOT_MODIFIED &&
intProxyResponseCode != HttpServletResponse.SC_NO_CONTENT) {
// Send the content to the client
httpServletResponse.resetBuffer();
httpServletResponse.getOutputStream().write(httpMethodProxyRequest.getResponseBody());
}
// copy cookies to servlet response
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());
}
// convert expiry date to max age
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);
}
} | java | private void executeRequest(HttpMethod httpMethodProxyRequest,
HttpServletRequest httpServletRequest,
PluginResponse httpServletResponse,
History history) throws Exception {
int intProxyResponseCode = 999;
// Create a default HttpClient
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);
// exception handling for httpclient
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) {
// Return a gateway timeout
httpServletResponse.setStatus(504);
httpServletResponse.setHeader(Constants.HEADER_STATUS, "504");
httpServletResponse.flushBuffer();
return;
}
logger.info("Response code: {}, {}", intProxyResponseCode,
HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString()));
// Pass the response code back to the client
httpServletResponse.setStatus(intProxyResponseCode);
// Pass response headers back to the client
Header[] headerArrayResponse = httpMethodProxyRequest.getResponseHeaders();
for (Header header : headerArrayResponse) {
// remove transfer-encoding header. The http libraries will handle this encoding
if (header.getName().toLowerCase().equals("transfer-encoding")) {
continue;
}
httpServletResponse.setHeader(header.getName(), header.getValue());
}
// there is no data for a HTTP 304 or 204
if (intProxyResponseCode != HttpServletResponse.SC_NOT_MODIFIED &&
intProxyResponseCode != HttpServletResponse.SC_NO_CONTENT) {
// Send the content to the client
httpServletResponse.resetBuffer();
httpServletResponse.getOutputStream().write(httpMethodProxyRequest.getResponseBody());
}
// copy cookies to servlet response
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());
}
// convert expiry date to max age
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);
}
} | [
"private",
"void",
"executeRequest",
"(",
"HttpMethod",
"httpMethodProxyRequest",
",",
"HttpServletRequest",
"httpServletRequest",
",",
"PluginResponse",
"httpServletResponse",
",",
"History",
"history",
")",
"throws",
"Exception",
"{",
"int",
"intProxyResponseCode",
"=",
... | Execute a request
@param httpMethodProxyRequest
@param httpServletRequest
@param httpServletResponse
@param history
@throws Exception | [
"Execute",
"a",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L958-L1047 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.processRedirect | private void processRedirect(String stringStatusCode,
HttpMethod httpMethodProxyRequest,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
// Check if the proxy response is a redirect
// The following code is adapted from
// org.tigris.noodle.filters.CheckForRedirect
// Hooray for open source software
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");
}
// Modify the redirect to go to this proxy servlet rather than the proxied host
String stringMyHostName = httpServletRequest.getServerName();
if (httpServletRequest.getServerPort() != 80) {
stringMyHostName += ":" + httpServletRequest.getServerPort();
}
stringMyHostName += httpServletRequest.getContextPath();
httpServletResponse.sendRedirect(stringLocation.replace(
getProxyHostAndPort() + this.getProxyPath(),
stringMyHostName));
} | java | private void processRedirect(String stringStatusCode,
HttpMethod httpMethodProxyRequest,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
// Check if the proxy response is a redirect
// The following code is adapted from
// org.tigris.noodle.filters.CheckForRedirect
// Hooray for open source software
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");
}
// Modify the redirect to go to this proxy servlet rather than the proxied host
String stringMyHostName = httpServletRequest.getServerName();
if (httpServletRequest.getServerPort() != 80) {
stringMyHostName += ":" + httpServletRequest.getServerPort();
}
stringMyHostName += httpServletRequest.getContextPath();
httpServletResponse.sendRedirect(stringLocation.replace(
getProxyHostAndPort() + this.getProxyPath(),
stringMyHostName));
} | [
"private",
"void",
"processRedirect",
"(",
"String",
"stringStatusCode",
",",
"HttpMethod",
"httpMethodProxyRequest",
",",
"HttpServletRequest",
"httpServletRequest",
",",
"HttpServletResponse",
"httpServletResponse",
")",
"throws",
"Exception",
"{",
"// Check if the proxy resp... | Execute a redirected request
@param stringStatusCode
@param httpMethodProxyRequest
@param httpServletRequest
@param httpServletResponse
@throws Exception | [
"Execute",
"a",
"redirected",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L1058-L1083 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.logOriginalRequestHistory | 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");
} | java | 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");
} | [
"private",
"void",
"logOriginalRequestHistory",
"(",
"String",
"requestType",
",",
"HttpServletRequest",
"request",
",",
"History",
"history",
")",
"{",
"logger",
".",
"info",
"(",
"\"Storing original request history\"",
")",
";",
"history",
".",
"setRequestType",
"("... | Log original incoming request
@param requestType
@param request
@param history | [
"Log",
"original",
"incoming",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L1092-L1100 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.logOriginalResponseHistory | 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");
}
} | java | 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");
}
} | [
"private",
"void",
"logOriginalResponseHistory",
"(",
"PluginResponse",
"httpServletResponse",
",",
"History",
"history",
")",
"throws",
"URIException",
"{",
"RequestInformation",
"requestInfo",
"=",
"requestInformation",
".",
"get",
"(",
")",
";",
"if",
"(",
"request... | Log original response
@param httpServletResponse
@param history
@throws URIException | [
"Log",
"original",
"response"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L1109-L1120 | train |
groupon/odo | proxyserver/src/main/java/com/groupon/odo/Proxy.java | Proxy.logRequestHistory | 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();
}
} | java | 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();
}
} | [
"private",
"void",
"logRequestHistory",
"(",
"HttpMethod",
"httpMethodProxyRequest",
",",
"PluginResponse",
"httpServletResponse",
",",
"History",
"history",
")",
"{",
"try",
"{",
"if",
"(",
"requestInformation",
".",
"get",
"(",
")",
".",
"handle",
"&&",
"request... | Log modified request
@param httpMethodProxyRequest
@param httpServletResponse
@param history | [
"Log",
"modified",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/Proxy.java#L1129-L1156 | train |
groupon/odo | browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java | BrowserMobProxyHandler.handleConnectOriginal | 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;
// When logging, we'll attempt to send messages to hosts that don't exist
if (uri.toString().endsWith(".selenium.doesnotexist:443")) {
// so we have to do set the host to be localhost (you can't new up an IAP with a non-existent hostname)
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();
// Get the timeout
int timeoutMs = 30000;
Object maybesocket = http_connection.getConnection();
if (maybesocket instanceof Socket) {
Socket s = (Socket) maybesocket;
timeoutMs = s.getSoTimeout();
}
// Create the tunnel
HttpTunnel tunnel = newHttpTunnel(request, response, InetAddress.getByName(null), port, timeoutMs);
if (tunnel != null) {
// TODO - need to setup semi-busy loop for IE.
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());
}
} | java | 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;
// When logging, we'll attempt to send messages to hosts that don't exist
if (uri.toString().endsWith(".selenium.doesnotexist:443")) {
// so we have to do set the host to be localhost (you can't new up an IAP with a non-existent hostname)
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();
// Get the timeout
int timeoutMs = 30000;
Object maybesocket = http_connection.getConnection();
if (maybesocket instanceof Socket) {
Socket s = (Socket) maybesocket;
timeoutMs = s.getSoTimeout();
}
// Create the tunnel
HttpTunnel tunnel = newHttpTunnel(request, response, InetAddress.getByName(null), port, timeoutMs);
if (tunnel != null) {
// TODO - need to setup semi-busy loop for IE.
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());
}
} | [
"public",
"void",
"handleConnectOriginal",
"(",
"String",
"pathInContext",
",",
"String",
"pathParams",
",",
"HttpRequest",
"request",
",",
"HttpResponse",
"response",
")",
"throws",
"HttpException",
",",
"IOException",
"{",
"URI",
"uri",
"=",
"request",
".",
"get... | Copied from original SeleniumProxyHandler
Changed SslRelay to SslListener and getSslRelayOrCreateNew to getSslRelayOrCreateNewOdo
No other changes to the function
@param pathInContext
@param pathParams
@param request
@param response
@throws HttpException
@throws IOException | [
"Copied",
"from",
"original",
"SeleniumProxyHandler",
"Changed",
"SslRelay",
"to",
"SslListener",
"and",
"getSslRelayOrCreateNew",
"to",
"getSslRelayOrCreateNewOdo",
"No",
"other",
"changes",
"to",
"the",
"function"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java#L380-L439 | train |
groupon/odo | browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java | BrowserMobProxyHandler.wireUpSslWithCyberVilliansCAOdo | protected X509Certificate wireUpSslWithCyberVilliansCAOdo(String host, SslListener listener) {
host = requestOriginalHostName.get();
// Add cybervillians CA(from browsermob)
try {
// see https://github.com/webmetrics/browsermob-proxy/issues/105
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);
}
} | java | protected X509Certificate wireUpSslWithCyberVilliansCAOdo(String host, SslListener listener) {
host = requestOriginalHostName.get();
// Add cybervillians CA(from browsermob)
try {
// see https://github.com/webmetrics/browsermob-proxy/issues/105
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);
}
} | [
"protected",
"X509Certificate",
"wireUpSslWithCyberVilliansCAOdo",
"(",
"String",
"host",
",",
"SslListener",
"listener",
")",
"{",
"host",
"=",
"requestOriginalHostName",
".",
"get",
"(",
")",
";",
"// Add cybervillians CA(from browsermob)",
"try",
"{",
"// see https://g... | This function wires up a SSL Listener with the cyber villians root CA and cert with the correct CNAME for the request
@param host
@param listener | [
"This",
"function",
"wires",
"up",
"a",
"SSL",
"Listener",
"with",
"the",
"cyber",
"villians",
"root",
"CA",
"and",
"cert",
"with",
"the",
"correct",
"CNAME",
"for",
"the",
"request"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java#L450-L467 | train |
groupon/odo | browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java | BrowserMobProxyHandler.startRelayWithPortTollerance | 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) {
// doh - the port is being used up, let's pick a new port
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);
}
} | java | 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) {
// doh - the port is being used up, let's pick a new port
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);
}
} | [
"private",
"void",
"startRelayWithPortTollerance",
"(",
"HttpServer",
"server",
",",
"SslListener",
"relay",
",",
"int",
"tries",
")",
"throws",
"Exception",
"{",
"if",
"(",
"tries",
">=",
"5",
")",
"{",
"throw",
"new",
"BindException",
"(",
"\"Unable to bind to... | END ODO CHANGES | [
"END",
"ODO",
"CHANGES"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java#L520-L536 | train |
groupon/odo | browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java | BrowserMobProxyHandler.getUnsafeOkHttpClient | private static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
} | java | private static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
} | [
"private",
"static",
"OkHttpClient",
"getUnsafeOkHttpClient",
"(",
")",
"{",
"try",
"{",
"// Create a trust manager that does not validate certificate chains",
"final",
"TrustManager",
"[",
"]",
"trustAllCerts",
"=",
"new",
"TrustManager",
"[",
"]",
"{",
"new",
"X509Trust... | Returns a OkHttpClient that ignores SSL cert errors
@return | [
"Returns",
"a",
"OkHttpClient",
"that",
"ignores",
"SSL",
"cert",
"errors"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java#L550-L589 | train |
groupon/odo | browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java | BrowserMobProxyHandler.cleanup | public void cleanup() {
synchronized (_sslMap) {
for (SslRelayOdo relay : _sslMap.values()) {
if (relay.getHttpServer() != null && relay.isStarted()) {
relay.getHttpServer().removeListener(relay);
}
}
sslRelays.clear();
}
} | java | public void cleanup() {
synchronized (_sslMap) {
for (SslRelayOdo relay : _sslMap.values()) {
if (relay.getHttpServer() != null && relay.isStarted()) {
relay.getHttpServer().removeListener(relay);
}
}
sslRelays.clear();
}
} | [
"public",
"void",
"cleanup",
"(",
")",
"{",
"synchronized",
"(",
"_sslMap",
")",
"{",
"for",
"(",
"SslRelayOdo",
"relay",
":",
"_sslMap",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"relay",
".",
"getHttpServer",
"(",
")",
"!=",
"null",
"&&",
"rela... | Cleanup function to remove all allocated listeners | [
"Cleanup",
"function",
"to",
"remove",
"all",
"allocated",
"listeners"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/BrowserMobProxyHandler.java#L798-L808 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.removeOverride | public void removeOverride(int overrideId, int pathId, Integer ordinal, String clientUUID) {
// TODO: reorder priorities after removal
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) {
}
}
} | java | public void removeOverride(int overrideId, int pathId, Integer ordinal, String clientUUID) {
// TODO: reorder priorities after removal
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) {
}
}
} | [
"public",
"void",
"removeOverride",
"(",
"int",
"overrideId",
",",
"int",
"pathId",
",",
"Integer",
"ordinal",
",",
"String",
"clientUUID",
")",
"{",
"// TODO: reorder priorities after removal",
"PreparedStatement",
"statement",
"=",
"null",
";",
"try",
"(",
"Connec... | Remove specified override id from enabled overrides for path
@param overrideId ID of override to remove
@param pathId ID of path containing override
@param ordinal index to the instance of the enabled override
@param clientUUID UUID of client | [
"Remove",
"specified",
"override",
"id",
"from",
"enabled",
"overrides",
"for",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L291-L312 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.increasePriority | public void increasePriority(int overrideId, int ordinal, int pathId, String clientUUID) {
logger.info("Increase priority");
int origPriority = -1;
int newPriority = -1;
int origId = 0;
int newId = 0;
PreparedStatement statement = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
results = null;
statement = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ?" +
" AND " + Constants.GENERIC_CLIENT_UUID + " = ?" +
" ORDER BY " + Constants.ENABLED_OVERRIDES_PRIORITY
);
statement.setInt(1, pathId);
statement.setString(2, clientUUID);
results = statement.executeQuery();
int ordinalCount = 0;
while (results.next()) {
if (results.getInt(Constants.ENABLED_OVERRIDES_OVERRIDE_ID) == overrideId) {
ordinalCount++;
if (ordinalCount == ordinal) {
origPriority = results.getInt(Constants.ENABLED_OVERRIDES_PRIORITY);
origId = results.getInt(Constants.GENERIC_ID);
break;
}
}
newPriority = results.getInt(Constants.ENABLED_OVERRIDES_PRIORITY);
newId = results.getInt(Constants.GENERIC_ID);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
try (Connection sqlConnection = sqlService.getConnection()) {
// update priorities
if (origPriority != -1 && newPriority != -1) {
statement = sqlConnection.prepareStatement(
"UPDATE " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" SET " + Constants.ENABLED_OVERRIDES_PRIORITY + "=?" +
" WHERE " + Constants.GENERIC_ID + "=?"
);
statement.setInt(1, origPriority);
statement.setInt(2, newId);
statement.executeUpdate();
statement.close();
statement = sqlConnection.prepareStatement(
"UPDATE " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" SET " + Constants.ENABLED_OVERRIDES_PRIORITY + "=?" +
" WHERE " + Constants.GENERIC_ID + "=?"
);
statement.setInt(1, newPriority);
statement.setInt(2, origId);
statement.executeUpdate();
}
} catch (Exception e) {
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | java | public void increasePriority(int overrideId, int ordinal, int pathId, String clientUUID) {
logger.info("Increase priority");
int origPriority = -1;
int newPriority = -1;
int origId = 0;
int newId = 0;
PreparedStatement statement = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
results = null;
statement = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ?" +
" AND " + Constants.GENERIC_CLIENT_UUID + " = ?" +
" ORDER BY " + Constants.ENABLED_OVERRIDES_PRIORITY
);
statement.setInt(1, pathId);
statement.setString(2, clientUUID);
results = statement.executeQuery();
int ordinalCount = 0;
while (results.next()) {
if (results.getInt(Constants.ENABLED_OVERRIDES_OVERRIDE_ID) == overrideId) {
ordinalCount++;
if (ordinalCount == ordinal) {
origPriority = results.getInt(Constants.ENABLED_OVERRIDES_PRIORITY);
origId = results.getInt(Constants.GENERIC_ID);
break;
}
}
newPriority = results.getInt(Constants.ENABLED_OVERRIDES_PRIORITY);
newId = results.getInt(Constants.GENERIC_ID);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
try (Connection sqlConnection = sqlService.getConnection()) {
// update priorities
if (origPriority != -1 && newPriority != -1) {
statement = sqlConnection.prepareStatement(
"UPDATE " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" SET " + Constants.ENABLED_OVERRIDES_PRIORITY + "=?" +
" WHERE " + Constants.GENERIC_ID + "=?"
);
statement.setInt(1, origPriority);
statement.setInt(2, newId);
statement.executeUpdate();
statement.close();
statement = sqlConnection.prepareStatement(
"UPDATE " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" SET " + Constants.ENABLED_OVERRIDES_PRIORITY + "=?" +
" WHERE " + Constants.GENERIC_ID + "=?"
);
statement.setInt(1, newPriority);
statement.setInt(2, origId);
statement.executeUpdate();
}
} catch (Exception e) {
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | [
"public",
"void",
"increasePriority",
"(",
"int",
"overrideId",
",",
"int",
"ordinal",
",",
"int",
"pathId",
",",
"String",
"clientUUID",
")",
"{",
"logger",
".",
"info",
"(",
"\"Increase priority\"",
")",
";",
"int",
"origPriority",
"=",
"-",
"1",
";",
"i... | Increase the priority of an overrideId
@param overrideId ID of override
@param pathId ID of path containing override
@param clientUUID UUID of client | [
"Increase",
"the",
"priority",
"of",
"an",
"overrideId"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L321-L404 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.preparePlaceHolders | private static String preparePlaceHolders(int length) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ) {
builder.append("?");
if (++i < length) {
builder.append(",");
}
}
return builder.toString();
} | java | private static String preparePlaceHolders(int length) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ) {
builder.append("?");
if (++i < length) {
builder.append(",");
}
}
return builder.toString();
} | [
"private",
"static",
"String",
"preparePlaceHolders",
"(",
"int",
"length",
")",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
")",
"{",
"builder",
".",
"app... | Creates a list of placeholders for use in a PreparedStatement
@param length number of placeholders
@return String of placeholders, seperated by comma | [
"Creates",
"a",
"list",
"of",
"placeholders",
"for",
"use",
"in",
"a",
"PreparedStatement"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L511-L520 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.disableAllOverrides | public void disableAllOverrides(int pathID, String clientUUID) {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
statement = sqlConnection.prepareStatement(
"DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ? " +
" AND " + Constants.GENERIC_CLIENT_UUID + " = ? "
);
statement.setInt(1, pathID);
statement.setString(2, clientUUID);
statement.execute();
statement.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | java | public void disableAllOverrides(int pathID, String clientUUID) {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
statement = sqlConnection.prepareStatement(
"DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ? " +
" AND " + Constants.GENERIC_CLIENT_UUID + " = ? "
);
statement.setInt(1, pathID);
statement.setString(2, clientUUID);
statement.execute();
statement.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | [
"public",
"void",
"disableAllOverrides",
"(",
"int",
"pathID",
",",
"String",
"clientUUID",
")",
"{",
"PreparedStatement",
"statement",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
")",
"{",
"s... | Disable all overrides for a specified path
@param pathID ID of path containing overrides
@param clientUUID UUID of client | [
"Disable",
"all",
"overrides",
"for",
"a",
"specified",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L528-L550 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.disableAllOverrides | public void disableAllOverrides(int pathID, String clientUUID, int overrideType) {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
ArrayList<Integer> enabledOverrides = new ArrayList<Integer>();
enabledOverrides.add(Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_ADD);
enabledOverrides.add(Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE);
enabledOverrides.add(Constants.PLUGIN_REQUEST_OVERRIDE_CUSTOM);
enabledOverrides.add(Constants.PLUGIN_REQUEST_OVERRIDE_CUSTOM_POST_BODY);
String overridePlaceholders = preparePlaceHolders(enabledOverrides.size());
statement = sqlConnection.prepareStatement(
"DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ? " +
" AND " + Constants.GENERIC_CLIENT_UUID + " = ? " +
" AND " + Constants.ENABLED_OVERRIDES_OVERRIDE_ID +
(overrideType == Constants.OVERRIDE_TYPE_RESPONSE ? " NOT" : "") +
" IN ( " + overridePlaceholders + " )"
);
statement.setInt(1, pathID);
statement.setString(2, clientUUID);
for (int i = 3; i <= enabledOverrides.size() + 2; ++i) {
statement.setInt(i, enabledOverrides.get(i - 3));
}
statement.execute();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | java | public void disableAllOverrides(int pathID, String clientUUID, int overrideType) {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
ArrayList<Integer> enabledOverrides = new ArrayList<Integer>();
enabledOverrides.add(Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_ADD);
enabledOverrides.add(Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE);
enabledOverrides.add(Constants.PLUGIN_REQUEST_OVERRIDE_CUSTOM);
enabledOverrides.add(Constants.PLUGIN_REQUEST_OVERRIDE_CUSTOM_POST_BODY);
String overridePlaceholders = preparePlaceHolders(enabledOverrides.size());
statement = sqlConnection.prepareStatement(
"DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + " = ? " +
" AND " + Constants.GENERIC_CLIENT_UUID + " = ? " +
" AND " + Constants.ENABLED_OVERRIDES_OVERRIDE_ID +
(overrideType == Constants.OVERRIDE_TYPE_RESPONSE ? " NOT" : "") +
" IN ( " + overridePlaceholders + " )"
);
statement.setInt(1, pathID);
statement.setString(2, clientUUID);
for (int i = 3; i <= enabledOverrides.size() + 2; ++i) {
statement.setInt(i, enabledOverrides.get(i - 3));
}
statement.execute();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | [
"public",
"void",
"disableAllOverrides",
"(",
"int",
"pathID",
",",
"String",
"clientUUID",
",",
"int",
"overrideType",
")",
"{",
"PreparedStatement",
"statement",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection"... | Disable all overrides for a specified path with overrideType
@param pathID ID of path containing overrides
@param clientUUID UUID of client
@param overrideType Override type identifier | [
"Disable",
"all",
"overrides",
"for",
"a",
"specified",
"path",
"with",
"overrideType"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L559-L595 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.getEnabledEndpoints | public List<EnabledEndpoint> getEnabledEndpoints(int pathId, String clientUUID, String[] filters) throws Exception {
ArrayList<EnabledEndpoint> enabledOverrides = new ArrayList<EnabledEndpoint>();
PreparedStatement query = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
query = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + "=?" +
" AND " + Constants.GENERIC_CLIENT_UUID + "=?" +
" ORDER BY " + Constants.ENABLED_OVERRIDES_PRIORITY
);
query.setInt(1, pathId);
query.setString(2, clientUUID);
results = query.executeQuery();
while (results.next()) {
EnabledEndpoint endpoint = this.getPartialEnabledEndpointFromResultset(results);
com.groupon.odo.proxylib.models.Method m = PathOverrideService.getInstance().getMethodForOverrideId(endpoint.getOverrideId());
// this is an errant entry.. perhaps a method got deleted from a plugin
// we'll also remove it from the endpoint
if (m == null) {
PathOverrideService.getInstance().removeOverride(endpoint.getOverrideId());
continue;
}
// check filters and see if any match
boolean addOverride = false;
if (filters != null) {
for (String filter : filters) {
if (m.getMethodType().endsWith(filter)) {
addOverride = true;
break;
}
}
} else {
// if there are no filters then we assume that the requester wants all enabled overrides
addOverride = true;
}
if (addOverride) {
enabledOverrides.add(endpoint);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (query != null) {
query.close();
}
} catch (Exception e) {
}
}
// now go through the ArrayList and get the method for all of the endpoints
// have to do this so we don't have overlapping SQL queries
ArrayList<EnabledEndpoint> enabledOverridesWithMethods = new ArrayList<EnabledEndpoint>();
for (EnabledEndpoint endpoint : enabledOverrides) {
if (endpoint.getOverrideId() >= 0) {
com.groupon.odo.proxylib.models.Method m = PathOverrideService.getInstance().getMethodForOverrideId(endpoint.getOverrideId());
endpoint.setMethodInformation(m);
}
enabledOverridesWithMethods.add(endpoint);
}
return enabledOverridesWithMethods;
} | java | public List<EnabledEndpoint> getEnabledEndpoints(int pathId, String clientUUID, String[] filters) throws Exception {
ArrayList<EnabledEndpoint> enabledOverrides = new ArrayList<EnabledEndpoint>();
PreparedStatement query = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
query = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + "=?" +
" AND " + Constants.GENERIC_CLIENT_UUID + "=?" +
" ORDER BY " + Constants.ENABLED_OVERRIDES_PRIORITY
);
query.setInt(1, pathId);
query.setString(2, clientUUID);
results = query.executeQuery();
while (results.next()) {
EnabledEndpoint endpoint = this.getPartialEnabledEndpointFromResultset(results);
com.groupon.odo.proxylib.models.Method m = PathOverrideService.getInstance().getMethodForOverrideId(endpoint.getOverrideId());
// this is an errant entry.. perhaps a method got deleted from a plugin
// we'll also remove it from the endpoint
if (m == null) {
PathOverrideService.getInstance().removeOverride(endpoint.getOverrideId());
continue;
}
// check filters and see if any match
boolean addOverride = false;
if (filters != null) {
for (String filter : filters) {
if (m.getMethodType().endsWith(filter)) {
addOverride = true;
break;
}
}
} else {
// if there are no filters then we assume that the requester wants all enabled overrides
addOverride = true;
}
if (addOverride) {
enabledOverrides.add(endpoint);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (query != null) {
query.close();
}
} catch (Exception e) {
}
}
// now go through the ArrayList and get the method for all of the endpoints
// have to do this so we don't have overlapping SQL queries
ArrayList<EnabledEndpoint> enabledOverridesWithMethods = new ArrayList<EnabledEndpoint>();
for (EnabledEndpoint endpoint : enabledOverrides) {
if (endpoint.getOverrideId() >= 0) {
com.groupon.odo.proxylib.models.Method m = PathOverrideService.getInstance().getMethodForOverrideId(endpoint.getOverrideId());
endpoint.setMethodInformation(m);
}
enabledOverridesWithMethods.add(endpoint);
}
return enabledOverridesWithMethods;
} | [
"public",
"List",
"<",
"EnabledEndpoint",
">",
"getEnabledEndpoints",
"(",
"int",
"pathId",
",",
"String",
"clientUUID",
",",
"String",
"[",
"]",
"filters",
")",
"throws",
"Exception",
"{",
"ArrayList",
"<",
"EnabledEndpoint",
">",
"enabledOverrides",
"=",
"new"... | Returns an array of the enabled endpoints as Integer IDs
@param pathId ID of path
@param clientUUID UUID of client
@param filters If supplied, only endpoints ending with values in filters are returned
@return Collection of endpoints
@throws Exception exception | [
"Returns",
"an",
"array",
"of",
"the",
"enabled",
"endpoints",
"as",
"Integer",
"IDs"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L606-L680 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.getCurrentMethodOrdinal | public int getCurrentMethodOrdinal(int overrideId, int pathId, String clientUUID, String[] filters) throws Exception {
int currentOrdinal = 0;
List<EnabledEndpoint> enabledEndpoints = getEnabledEndpoints(pathId, clientUUID, filters);
for (EnabledEndpoint enabledEndpoint : enabledEndpoints) {
if (enabledEndpoint.getOverrideId() == overrideId) {
currentOrdinal++;
}
}
return currentOrdinal;
} | java | public int getCurrentMethodOrdinal(int overrideId, int pathId, String clientUUID, String[] filters) throws Exception {
int currentOrdinal = 0;
List<EnabledEndpoint> enabledEndpoints = getEnabledEndpoints(pathId, clientUUID, filters);
for (EnabledEndpoint enabledEndpoint : enabledEndpoints) {
if (enabledEndpoint.getOverrideId() == overrideId) {
currentOrdinal++;
}
}
return currentOrdinal;
} | [
"public",
"int",
"getCurrentMethodOrdinal",
"(",
"int",
"overrideId",
",",
"int",
"pathId",
",",
"String",
"clientUUID",
",",
"String",
"[",
"]",
"filters",
")",
"throws",
"Exception",
"{",
"int",
"currentOrdinal",
"=",
"0",
";",
"List",
"<",
"EnabledEndpoint"... | Get the ordinal value for the last of a particular override on a path
@param overrideId Id of the override to check
@param pathId Path the override is on
@param clientUUID UUID of the client
@param filters If supplied, only endpoints ending with values in filters are returned
@return The integer ordinal
@throws Exception | [
"Get",
"the",
"ordinal",
"value",
"for",
"the",
"last",
"of",
"a",
"particular",
"override",
"on",
"a",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L692-L701 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.getPartialEnabledEndpointFromResultset | private EnabledEndpoint getPartialEnabledEndpointFromResultset(ResultSet result) throws Exception {
EnabledEndpoint endpoint = new EnabledEndpoint();
endpoint.setId(result.getInt(Constants.GENERIC_ID));
endpoint.setPathId(result.getInt(Constants.ENABLED_OVERRIDES_PATH_ID));
endpoint.setOverrideId(result.getInt(Constants.ENABLED_OVERRIDES_OVERRIDE_ID));
endpoint.setPriority(result.getInt(Constants.ENABLED_OVERRIDES_PRIORITY));
endpoint.setRepeatNumber(result.getInt(Constants.ENABLED_OVERRIDES_REPEAT_NUMBER));
endpoint.setResponseCode(result.getString(Constants.ENABLED_OVERRIDES_RESPONSE_CODE));
ArrayList<Object> args = new ArrayList<Object>();
try {
JSONArray arr = new JSONArray(result.getString(Constants.ENABLED_OVERRIDES_ARGUMENTS));
for (int x = 0; x < arr.length(); x++) {
args.add(arr.get(x));
}
} catch (Exception e) {
// ignore it.. this means the entry was null/corrupt
}
endpoint.setArguments(args.toArray(new Object[0]));
return endpoint;
} | java | private EnabledEndpoint getPartialEnabledEndpointFromResultset(ResultSet result) throws Exception {
EnabledEndpoint endpoint = new EnabledEndpoint();
endpoint.setId(result.getInt(Constants.GENERIC_ID));
endpoint.setPathId(result.getInt(Constants.ENABLED_OVERRIDES_PATH_ID));
endpoint.setOverrideId(result.getInt(Constants.ENABLED_OVERRIDES_OVERRIDE_ID));
endpoint.setPriority(result.getInt(Constants.ENABLED_OVERRIDES_PRIORITY));
endpoint.setRepeatNumber(result.getInt(Constants.ENABLED_OVERRIDES_REPEAT_NUMBER));
endpoint.setResponseCode(result.getString(Constants.ENABLED_OVERRIDES_RESPONSE_CODE));
ArrayList<Object> args = new ArrayList<Object>();
try {
JSONArray arr = new JSONArray(result.getString(Constants.ENABLED_OVERRIDES_ARGUMENTS));
for (int x = 0; x < arr.length(); x++) {
args.add(arr.get(x));
}
} catch (Exception e) {
// ignore it.. this means the entry was null/corrupt
}
endpoint.setArguments(args.toArray(new Object[0]));
return endpoint;
} | [
"private",
"EnabledEndpoint",
"getPartialEnabledEndpointFromResultset",
"(",
"ResultSet",
"result",
")",
"throws",
"Exception",
"{",
"EnabledEndpoint",
"endpoint",
"=",
"new",
"EnabledEndpoint",
"(",
")",
";",
"endpoint",
".",
"setId",
"(",
"result",
".",
"getInt",
... | This only gets half of the EnabledEndpoint from a JDBC ResultSet
Getting the method for the override id requires an additional SQL query and needs to be called after
the SQL connection is released
@param result result to scan for endpoint
@return EnabledEndpoint
@throws Exception exception | [
"This",
"only",
"gets",
"half",
"of",
"the",
"EnabledEndpoint",
"from",
"a",
"JDBC",
"ResultSet",
"Getting",
"the",
"method",
"for",
"the",
"override",
"id",
"requires",
"an",
"additional",
"SQL",
"query",
"and",
"needs",
"to",
"be",
"called",
"after",
"the"... | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L830-L852 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java | OverrideService.getOverrideIdForMethod | public Integer getOverrideIdForMethod(String className, String methodName) {
Integer overrideId = null;
PreparedStatement query = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
query = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_OVERRIDE +
" WHERE " + Constants.OVERRIDE_CLASS_NAME + " = ?" +
" AND " + Constants.OVERRIDE_METHOD_NAME + " = ?"
);
query.setString(1, className);
query.setString(2, methodName);
results = query.executeQuery();
if (results.next()) {
overrideId = results.getInt(Constants.GENERIC_ID);
}
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (query != null) {
query.close();
}
} catch (Exception e) {
}
}
return overrideId;
} | java | public Integer getOverrideIdForMethod(String className, String methodName) {
Integer overrideId = null;
PreparedStatement query = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
query = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_OVERRIDE +
" WHERE " + Constants.OVERRIDE_CLASS_NAME + " = ?" +
" AND " + Constants.OVERRIDE_METHOD_NAME + " = ?"
);
query.setString(1, className);
query.setString(2, methodName);
results = query.executeQuery();
if (results.next()) {
overrideId = results.getInt(Constants.GENERIC_ID);
}
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (query != null) {
query.close();
}
} catch (Exception e) {
}
}
return overrideId;
} | [
"public",
"Integer",
"getOverrideIdForMethod",
"(",
"String",
"className",
",",
"String",
"methodName",
")",
"{",
"Integer",
"overrideId",
"=",
"null",
";",
"PreparedStatement",
"query",
"=",
"null",
";",
"ResultSet",
"results",
"=",
"null",
";",
"try",
"(",
"... | Gets an overrideID for a class name, method name
@param className name of class
@param methodName name of method
@return override ID of method | [
"Gets",
"an",
"overrideID",
"for",
"a",
"class",
"name",
"method",
"name"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L861-L898 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java | ClientService.findAllClients | public List<Client> findAllClients(int profileId) throws Exception {
ArrayList<Client> clients = new ArrayList<Client>();
PreparedStatement query = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
query = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_CLIENT +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?"
);
query.setInt(1, profileId);
results = query.executeQuery();
while (results.next()) {
clients.add(this.getClientFromResultSet(results));
}
} catch (Exception e) {
throw e;
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (query != null) {
query.close();
}
} catch (Exception e) {
}
}
return clients;
} | java | public List<Client> findAllClients(int profileId) throws Exception {
ArrayList<Client> clients = new ArrayList<Client>();
PreparedStatement query = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
query = sqlConnection.prepareStatement(
"SELECT * FROM " + Constants.DB_TABLE_CLIENT +
" WHERE " + Constants.GENERIC_PROFILE_ID + " = ?"
);
query.setInt(1, profileId);
results = query.executeQuery();
while (results.next()) {
clients.add(this.getClientFromResultSet(results));
}
} catch (Exception e) {
throw e;
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (query != null) {
query.close();
}
} catch (Exception e) {
}
}
return clients;
} | [
"public",
"List",
"<",
"Client",
">",
"findAllClients",
"(",
"int",
"profileId",
")",
"throws",
"Exception",
"{",
"ArrayList",
"<",
"Client",
">",
"clients",
"=",
"new",
"ArrayList",
"<",
"Client",
">",
"(",
")",
";",
"PreparedStatement",
"query",
"=",
"nu... | Return all Clients for a profile
@param profileId ID of profile clients belong to
@return collection of the Clients found
@throws Exception exception | [
"Return",
"all",
"Clients",
"for",
"a",
"profile"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L60-L93 | train |
groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java | ClientService.getClient | public Client getClient(int clientId) throws Exception {
Client client = null;
PreparedStatement statement = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
String queryString = "SELECT * FROM " + Constants.DB_TABLE_CLIENT +
" WHERE " + Constants.GENERIC_ID + " = ?";
statement = sqlConnection.prepareStatement(queryString);
statement.setInt(1, clientId);
results = statement.executeQuery();
if (results.next()) {
client = this.getClientFromResultSet(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 client;
} | java | public Client getClient(int clientId) throws Exception {
Client client = null;
PreparedStatement statement = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
String queryString = "SELECT * FROM " + Constants.DB_TABLE_CLIENT +
" WHERE " + Constants.GENERIC_ID + " = ?";
statement = sqlConnection.prepareStatement(queryString);
statement.setInt(1, clientId);
results = statement.executeQuery();
if (results.next()) {
client = this.getClientFromResultSet(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 client;
} | [
"public",
"Client",
"getClient",
"(",
"int",
"clientId",
")",
"throws",
"Exception",
"{",
"Client",
"client",
"=",
"null",
";",
"PreparedStatement",
"statement",
"=",
"null",
";",
"ResultSet",
"results",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnecti... | Returns a client object for a clientId
@param clientId ID of client to return
@return Client or null
@throws Exception exception | [
"Returns",
"a",
"client",
"object",
"for",
"a",
"clientId"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L102-L136 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.