id
int32
0
165k
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
sequence
docstring
stringlengths
3
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
105
339
164,800
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", ",", "customData", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "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
164,801
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", ",", "customData", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "false", ";", "}" ]
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
164,802
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", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "false", ";", "}" ]
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
164,803
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", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "false", ";", "}" ]
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
164,804
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", ",", "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", ";", "}" ]
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
164,805
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", "[", "0", "]", ")", ";", "JSONObject", "pathResponse", "=", "new", "JSONObject", "(", "pathInfo", ")", ";", "JSONArray", "enabledEndpoints", "=", "pathResponse", ".", "getJSONArray", "(", "\"enabledEndpoints\"", ")", ";", "int", "lastOrdinal", "=", "0", ";", "for", "(", "int", "x", "=", "0", ";", "x", "<", "enabledEndpoints", ".", "length", "(", ")", ";", "x", "++", ")", "{", "if", "(", "enabledEndpoints", ".", "getJSONObject", "(", "x", ")", ".", "getInt", "(", "\"overrideId\"", ")", "==", "methodId", ")", "{", "lastOrdinal", "++", ";", "}", "}", "return", "lastOrdinal", "+", "1", ";", "}" ]
Get the next available ordinal for a method ID @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
164,806
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", ")", ")", "{", "return", "REQUEST_TYPE_POST", ";", "}", "if", "(", "\"PUT\"", ".", "equals", "(", "requestType", ")", ")", "{", "return", "REQUEST_TYPE_PUT", ";", "}", "if", "(", "\"DELETE\"", ".", "equals", "(", "requestType", ")", ")", "{", "return", "REQUEST_TYPE_DELETE", ";", "}", "return", "REQUEST_TYPE_ALL", ";", "}" ]
Convert a request type string to value @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
164,807
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", "ArrayList", "<", "BasicNameValuePair", ">", "(", ")", ";", "params", ".", "add", "(", "new", "BasicNameValuePair", "(", "\"srcUrl\"", ",", "sourceHost", ")", ")", ";", "params", ".", "add", "(", "new", "BasicNameValuePair", "(", "\"destUrl\"", ",", "destinationHost", ")", ")", ";", "params", ".", "add", "(", "new", "BasicNameValuePair", "(", "\"profileIdentifier\"", ",", "this", ".", "_profileName", ")", ")", ";", "if", "(", "hostHeader", "!=", "null", ")", "{", "params", ".", "add", "(", "new", "BasicNameValuePair", "(", "\"hostHeader\"", ",", "hostHeader", ")", ")", ";", "}", "try", "{", "BasicNameValuePair", "paramArray", "[", "]", "=", "new", "BasicNameValuePair", "[", "params", ".", "size", "(", ")", "]", ";", "params", ".", "toArray", "(", "paramArray", ")", ";", "response", "=", "new", "JSONObject", "(", "doPost", "(", "BASE_SERVER", ",", "paramArray", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "getServerRedirectFromJSON", "(", "response", ")", ";", "}" ]
Add a new server mapping to current profile @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
164,808
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", "serverArray", "=", "new", "JSONArray", "(", "doDelete", "(", "BASE_SERVER", "+", "\"/\"", "+", "serverMappingId", ",", "null", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "serverArray", ".", "length", "(", ")", ";", "i", "++", ")", "{", "JSONObject", "jsonServer", "=", "serverArray", ".", "getJSONObject", "(", "i", ")", ";", "ServerRedirect", "server", "=", "getServerRedirectFromJSON", "(", "jsonServer", ")", ";", "if", "(", "server", "!=", "null", ")", "{", "servers", ".", "add", "(", "server", ")", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "servers", ";", "}" ]
Remove a server mapping from current profile by ID @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
164,809
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", "JSONObject", "(", "doGet", "(", "BASE_SERVER", ",", "null", ")", ")", ";", "JSONArray", "serverArray", "=", "response", ".", "getJSONArray", "(", "\"servers\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "serverArray", ".", "length", "(", ")", ";", "i", "++", ")", "{", "JSONObject", "jsonServer", "=", "serverArray", ".", "getJSONObject", "(", "i", ")", ";", "ServerRedirect", "server", "=", "getServerRedirectFromJSON", "(", "jsonServer", ")", ";", "if", "(", "server", "!=", "null", ")", "{", "servers", ".", "add", "(", "server", ")", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "servers", ";", "}" ]
Get a list of all active server mappings defined for current profile @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
164,810
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", "BasicNameValuePair", "(", "\"hostHeader\"", ",", "hostHeader", ")", ",", "new", "BasicNameValuePair", "(", "\"profileIdentifier\"", ",", "this", ".", "_profileName", ")", "}", ";", "try", "{", "JSONObject", "response", "=", "new", "JSONObject", "(", "doPost", "(", "BASE_SERVER", "+", "\"/\"", "+", "serverMappingId", "+", "\"/host\"", ",", "params", ")", ")", ";", "redirect", "=", "getServerRedirectFromJSON", "(", "response", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "redirect", ";", "}" ]
Update server mapping's host header @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
164,811
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", ")", ",", "new", "BasicNameValuePair", "(", "\"profileIdentifier\"", ",", "this", ".", "_profileName", ")", "}", ";", "try", "{", "JSONObject", "response", "=", "new", "JSONObject", "(", "doPost", "(", "BASE_SERVERGROUP", ",", "params", ")", ")", ";", "group", "=", "getServerGroupFromJSON", "(", "response", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "group", ";", "}" ]
Create a new server group @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
164,812
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", "(", "doGet", "(", "BASE_SERVERGROUP", ",", "null", ")", ")", ";", "JSONArray", "serverArray", "=", "response", ".", "getJSONArray", "(", "\"servergroups\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "serverArray", ".", "length", "(", ")", ";", "i", "++", ")", "{", "JSONObject", "jsonServerGroup", "=", "serverArray", ".", "getJSONObject", "(", "i", ")", ";", "ServerGroup", "group", "=", "getServerGroupFromJSON", "(", "jsonServerGroup", ")", ";", "groups", ".", "add", "(", "group", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "groups", ";", "}" ]
Get the collection of the server groups @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
164,813
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\"", ",", "name", ")", ",", "new", "BasicNameValuePair", "(", "\"profileIdentifier\"", ",", "this", ".", "_profileName", ")", "}", ";", "try", "{", "JSONObject", "response", "=", "new", "JSONObject", "(", "doPost", "(", "BASE_SERVERGROUP", "+", "\"/\"", "+", "serverGroupId", ",", "params", ")", ")", ";", "serverGroup", "=", "getServerGroupFromJSON", "(", "response", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "null", ";", "}", "return", "serverGroup", ";", "}" ]
Update the server group's name @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
164,814
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", ".", "create", "(", ")", ";", "FileBody", "fileBody", "=", "new", "FileBody", "(", "file", ",", "ContentType", ".", "MULTIPART_FORM_DATA", ")", ";", "multipartEntityBuilder", ".", "setMode", "(", "HttpMultipartMode", ".", "BROWSER_COMPATIBLE", ")", ";", "multipartEntityBuilder", ".", "addPart", "(", "\"fileData\"", ",", "fileBody", ")", ";", "multipartEntityBuilder", ".", "addTextBody", "(", "\"odoImport\"", ",", "odoImport", ")", ";", "try", "{", "JSONObject", "response", "=", "new", "JSONObject", "(", "doMultipartPost", "(", "BASE_BACKUP_PROFILE", "+", "\"/\"", "+", "uriEncode", "(", "this", ".", "_profileName", ")", "+", "\"/\"", "+", "this", ".", "_clientId", ",", "multipartEntityBuilder", ")", ")", ";", "if", "(", "response", ".", "length", "(", ")", "==", "0", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "return", "false", ";", "}", "}" ]
Upload file and set odo overrides and configuration of odo @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
164,815
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", "=", "BASE_BACKUP_PROFILE", "+", "\"/\"", "+", "uriEncode", "(", "this", ".", "_profileName", ")", "+", "\"/\"", "+", "this", ".", "_clientId", ";", "return", "new", "JSONObject", "(", "doGet", "(", "url", ",", "new", "BasicNameValuePair", "[", "]", "{", "}", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "new", "JSONObject", "(", ")", ";", "}", "}" ]
Export the odo overrides setup and odo configuration @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
164,816
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", ".", "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", ";", "}" ]
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
164,817
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", ">", "enabledPaths", "=", "new", "ArrayList", "<>", "(", ")", ";", "List", "<", "EndpointOverride", ">", "paths", "=", "PathOverrideService", ".", "getInstance", "(", ")", ".", "getPaths", "(", "profileID", ",", "clientUUID", ",", "null", ")", ";", "for", "(", "EndpointOverride", "override", ":", "paths", ")", "{", "if", "(", "override", ".", "getRequestEnabled", "(", ")", "||", "override", ".", "getResponseEnabled", "(", ")", ")", "{", "PathOverride", "pathOverride", "=", "new", "PathOverride", "(", ")", ";", "pathOverride", ".", "setPathName", "(", "override", ".", "getPathName", "(", ")", ")", ";", "if", "(", "override", ".", "getRequestEnabled", "(", ")", ")", "{", "pathOverride", ".", "setRequestEnabled", "(", "true", ")", ";", "}", "if", "(", "override", ".", "getResponseEnabled", "(", ")", ")", "{", "pathOverride", ".", "setResponseEnabled", "(", "true", ")", ";", "}", "pathOverride", ".", "setEnabledEndpoints", "(", "override", ".", "getEnabledEndpoints", "(", ")", ")", ";", "enabledPaths", ".", "add", "(", "pathOverride", ")", ";", "}", "}", "singleProfileBackup", ".", "setEnabledPaths", "(", "enabledPaths", ")", ";", "Client", "backupClient", "=", "ClientService", ".", "getInstance", "(", ")", ".", "findClient", "(", "clientUUID", ",", "profileID", ")", ";", "ServerGroup", "activeServerGroup", "=", "ServerRedirectService", ".", "getInstance", "(", ")", ".", "getServerGroup", "(", "backupClient", ".", "getActiveServerGroup", "(", ")", ",", "profileID", ")", ";", "singleProfileBackup", ".", "setActiveServerGroup", "(", "activeServerGroup", ")", ";", "return", "singleProfileBackup", ";", "}" ]
Get the active overrides with parameters and the active server group for a client @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
164,818
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", "(", ")", ")", ";", "ArrayList", "<", "Script", ">", "scripts", "=", "new", "ArrayList", "<", "Script", ">", "(", ")", ";", "Collections", ".", "addAll", "(", "scripts", ",", "ScriptService", ".", "getInstance", "(", ")", ".", "getScripts", "(", ")", ")", ";", "backupData", ".", "setScripts", "(", "scripts", ")", ";", "return", "backupData", ";", "}" ]
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
164,819
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", "(", "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", ";", "}" ]
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
164,820
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", "=", "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", ")", ";", "}" ]
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
164,821
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", ":", "requestInfo", ".", "selectedRequestPaths", ")", "{", "List", "<", "EnabledEndpoint", ">", "points", "=", "selectedPath", ".", "getEnabledEndpoints", "(", ")", ";", "for", "(", "EnabledEndpoint", "endpoint", ":", "points", ")", "{", "if", "(", "endpoint", ".", "getOverrideId", "(", ")", "==", "Constants", ".", "PLUGIN_REQUEST_HEADER_OVERRIDE_ADD", ")", "{", "httpMethodProxyRequest", ".", "addRequestHeader", "(", "endpoint", ".", "getArguments", "(", ")", "[", "0", "]", ".", "toString", "(", ")", ",", "endpoint", ".", "getArguments", "(", ")", "[", "1", "]", ".", "toString", "(", ")", ")", ";", "requestInfo", ".", "modified", "=", "true", ";", "}", "else", "if", "(", "endpoint", ".", "getOverrideId", "(", ")", "==", "Constants", ".", "PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE", ")", "{", "httpMethodProxyRequest", ".", "removeRequestHeader", "(", "endpoint", ".", "getArguments", "(", ")", "[", "0", "]", ".", "toString", "(", ")", ")", ";", "requestInfo", ".", "modified", "=", "true", ";", "}", "}", "}", "}" ]
Apply any applicable header overrides to request @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
164,822
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", "(", ")", ")", ";", "for", "(", "ServerRedirect", "server", ":", "servers", ")", "{", "if", "(", "server", ".", "getSrcUrl", "(", ")", ".", "compareTo", "(", "hostName", ")", "==", "0", ")", "{", "String", "hostHeader", "=", "server", ".", "getHostHeader", "(", ")", ";", "if", "(", "hostHeader", "==", "null", "||", "hostHeader", ".", "length", "(", ")", "==", "0", ")", "{", "return", "null", ";", "}", "return", "hostHeader", ";", "}", "}", "return", "null", ";", "}" ]
Obtain host header value for a hostname @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
164,823
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", "(", "httpServletRequest", ".", "getHeader", "(", "Constants", ".", "PROFILE_CLIENT_HEADER_NAME", ")", "!=", "null", "&&", "!", "httpServletRequest", ".", "getHeader", "(", "Constants", ".", "PROFILE_CLIENT_HEADER_NAME", ")", ".", "equals", "(", "\"\"", ")", ")", "{", "history", ".", "setClientUUID", "(", "httpServletRequest", ".", "getHeader", "(", "Constants", ".", "PROFILE_CLIENT_HEADER_NAME", ")", ")", ";", "}", "else", "{", "history", ".", "setClientUUID", "(", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ")", ";", "}", "logger", ".", "info", "(", "\"Client UUID is: {}\"", ",", "history", ".", "getClientUUID", "(", ")", ")", ";", "}" ]
Apply the matching client UUID for the request @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
164,824
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", ">", "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", ";", "}" ]
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
164,825
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", "(", ")", ")", ";", "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", ";", "}" ]
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
164,826
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", ")", "!=", "null", ")", "{", "virtualHostName", "=", "HttpUtilities", ".", "removePortFromHostHeaderString", "(", "httpMethodProxyRequest", ".", "getRequestHeader", "(", "STRING_HOST_HEADER_NAME", ")", ".", "getValue", "(", ")", ")", ";", "}", "else", "{", "virtualHostName", "=", "HttpUtilities", ".", "getHostNameFromURL", "(", "httpServletRequest", ".", "getRequestURL", "(", ")", ".", "toString", "(", ")", ")", ";", "}", "httpMethodProxyRequest", ".", "getParams", "(", ")", ".", "setVirtualHost", "(", "virtualHostName", ")", ";", "}" ]
Set virtual host so the server can direct the request. Value is the host header if it is set, otherwise use the hostname from the original request. @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
164,827
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", "=", "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", ")", ";", "}", "}" ]
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
164,828
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", ":", "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", ";", "}" ]
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
164,829
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", "=", "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", "(", ")", ";", "}", "}" ]
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
164,830
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", "=", "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", ")", ";", "}", "}" ]
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
164,831
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 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", ")", ")", ";", "}" ]
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
164,832
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", "(", "requestType", ")", ";", "history", ".", "setOriginalRequestHeaders", "(", "HttpUtilities", ".", "getHeaders", "(", "request", ")", ")", ";", "history", ".", "setOriginalRequestURL", "(", "request", ".", "getRequestURL", "(", ")", ".", "toString", "(", ")", ")", ";", "history", ".", "setOriginalRequestParams", "(", "request", ".", "getQueryString", "(", ")", "==", "null", "?", "\"\"", ":", "request", ".", "getQueryString", "(", ")", ")", ";", "logger", ".", "info", "(", "\"Done storing\"", ")", ";", "}" ]
Log original incoming request @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
164,833
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", "(", "requestInfo", ".", "handle", "&&", "requestInfo", ".", "client", ".", "getIsActive", "(", ")", ")", "{", "logger", ".", "info", "(", "\"Storing original response history\"", ")", ";", "history", ".", "setOriginalResponseHeaders", "(", "HttpUtilities", ".", "getHeaders", "(", "httpServletResponse", ")", ")", ";", "history", ".", "setOriginalResponseCode", "(", "Integer", ".", "toString", "(", "httpServletResponse", ".", "getStatus", "(", ")", ")", ")", ";", "history", ".", "setOriginalResponseContentType", "(", "httpServletResponse", ".", "getContentType", "(", ")", ")", ";", "history", ".", "setOriginalResponseData", "(", "httpServletResponse", ".", "getContentString", "(", ")", ")", ";", "logger", ".", "info", "(", "\"Done storing\"", ")", ";", "}", "}" ]
Log original response @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
164,834
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", "&&", "requestInformation", ".", "get", "(", ")", ".", "client", ".", "getIsActive", "(", ")", ")", "{", "logger", ".", "info", "(", "\"Storing history\"", ")", ";", "String", "createdDate", ";", "SimpleDateFormat", "sdf", "=", "new", "SimpleDateFormat", "(", ")", ";", "sdf", ".", "setTimeZone", "(", "new", "SimpleTimeZone", "(", "0", ",", "\"GMT\"", ")", ")", ";", "sdf", ".", "applyPattern", "(", "\"dd MMM yyyy HH:mm:ss\"", ")", ";", "createdDate", "=", "sdf", ".", "format", "(", "new", "Date", "(", ")", ")", "+", "\" GMT\"", ";", "history", ".", "setCreatedAt", "(", "createdDate", ")", ";", "history", ".", "setRequestURL", "(", "HttpUtilities", ".", "getURL", "(", "httpMethodProxyRequest", ".", "getURI", "(", ")", ".", "toString", "(", ")", ")", ")", ";", "history", ".", "setRequestParams", "(", "httpMethodProxyRequest", ".", "getQueryString", "(", ")", "==", "null", "?", "\"\"", ":", "httpMethodProxyRequest", ".", "getQueryString", "(", ")", ")", ";", "history", ".", "setRequestHeaders", "(", "HttpUtilities", ".", "getHeaders", "(", "httpMethodProxyRequest", ")", ")", ";", "history", ".", "setResponseHeaders", "(", "HttpUtilities", ".", "getHeaders", "(", "httpServletResponse", ")", ")", ";", "history", ".", "setResponseCode", "(", "Integer", ".", "toString", "(", "httpServletResponse", ".", "getStatus", "(", ")", ")", ")", ";", "history", ".", "setResponseContentType", "(", "httpServletResponse", ".", "getContentType", "(", ")", ")", ";", "history", ".", "setResponseData", "(", "httpServletResponse", ".", "getContentString", "(", ")", ")", ";", "history", ".", "setResponseBodyDecoded", "(", "httpServletResponse", ".", "isContentDecoded", "(", ")", ")", ";", "HistoryService", ".", "getInstance", "(", ")", ".", "addHistory", "(", "history", ")", ";", "logger", ".", "info", "(", "\"Done storing\"", ")", ";", "}", "}", "catch", "(", "URIException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Log modified request @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
164,835
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", ".", "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", "(", ")", ")", ";", "}", "}" ]
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
164,836
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://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", ")", ";", "}", "}" ]
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
164,837
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 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", ")", ";", "}", "}" ]
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
164,838
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", "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", ")", ";", "}", "}" ]
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
164,839
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", "&&", "relay", ".", "isStarted", "(", ")", ")", "{", "relay", ".", "getHttpServer", "(", ")", ".", "removeListener", "(", "relay", ")", ";", "}", "}", "sslRelays", ".", "clear", "(", ")", ";", "}", "}" ]
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
164,840
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", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "int", "enabledId", "=", "getEnabledEndpoint", "(", "pathId", ",", "overrideId", ",", "ordinal", ",", "clientUUID", ")", ".", "getId", "(", ")", ";", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"DELETE FROM \"", "+", "Constants", ".", "DB_TABLE_ENABLED_OVERRIDE", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_ID", "+", "\" = ?\"", ")", ";", "statement", ".", "setInt", "(", "1", ",", "enabledId", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}" ]
Remove specified override id from enabled overrides for path @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
164,841
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", ";", "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", ")", "{", "}", "}", "}" ]
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
164,842
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", ".", "append", "(", "\"?\"", ")", ";", "if", "(", "++", "i", "<", "length", ")", "{", "builder", ".", "append", "(", "\",\"", ")", ";", "}", "}", "return", "builder", ".", "toString", "(", ")", ";", "}" ]
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
164,843
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", "(", ")", ")", "{", "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", ")", "{", "}", "}", "}" ]
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
164,844
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", "(", ")", ")", "{", "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", ")", "{", "}", "}", "}" ]
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
164,845
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", "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", ";", "}" ]
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
164,846
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", ">", "enabledEndpoints", "=", "getEnabledEndpoints", "(", "pathId", ",", "clientUUID", ",", "filters", ")", ";", "for", "(", "EnabledEndpoint", "enabledEndpoint", ":", "enabledEndpoints", ")", "{", "if", "(", "enabledEndpoint", ".", "getOverrideId", "(", ")", "==", "overrideId", ")", "{", "currentOrdinal", "++", ";", "}", "}", "return", "currentOrdinal", ";", "}" ]
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
164,847
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", "(", "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", ";", "}" ]
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", "SQL", "connection", "is", "released" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/OverrideService.java#L830-L852
164,848
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", "(", "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", ";", "}" ]
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
164,849
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", "=", "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", ";", "}" ]
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
164,850
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", "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", ";", "}" ]
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
164,851
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java
ClientService.findClient
public Client findClient(String clientUUID, Integer profileId) throws Exception { Client client = null; /* ERROR CODE: 500 WHEN TRYING TO DELETE A SERVER GROUP. THIS APPEARS TO BE BECAUSE CLIENT UUID IS NULL. */ /* CODE ADDED TO PREVENT NULL POINTERS. */ if (clientUUID == null) { clientUUID = ""; } // first see if the clientUUID is actually a uuid.. it might be a friendlyName and need conversion /* A UUID IS A UNIVERSALLY UNIQUE IDENTIFIER. */ if (clientUUID.compareTo(Constants.PROFILE_CLIENT_DEFAULT_ID) != 0 && !clientUUID.matches("[\\w]{8}-[\\w]{4}-[\\w]{4}-[\\w]{4}-[\\w]{12}")) { Client tmpClient = this.findClientFromFriendlyName(profileId, clientUUID); // if we can't find a client then fall back to the default ID if (tmpClient == null) { clientUUID = Constants.PROFILE_CLIENT_DEFAULT_ID; } else { return tmpClient; } } PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { String queryString = "SELECT * FROM " + Constants.DB_TABLE_CLIENT + " WHERE " + Constants.CLIENT_CLIENT_UUID + " = ?"; if (profileId != null) { queryString += " AND " + Constants.GENERIC_PROFILE_ID + "=?"; } statement = sqlConnection.prepareStatement(queryString); statement.setString(1, clientUUID); if (profileId != null) { statement.setInt(2, profileId); } 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 findClient(String clientUUID, Integer profileId) throws Exception { Client client = null; /* ERROR CODE: 500 WHEN TRYING TO DELETE A SERVER GROUP. THIS APPEARS TO BE BECAUSE CLIENT UUID IS NULL. */ /* CODE ADDED TO PREVENT NULL POINTERS. */ if (clientUUID == null) { clientUUID = ""; } // first see if the clientUUID is actually a uuid.. it might be a friendlyName and need conversion /* A UUID IS A UNIVERSALLY UNIQUE IDENTIFIER. */ if (clientUUID.compareTo(Constants.PROFILE_CLIENT_DEFAULT_ID) != 0 && !clientUUID.matches("[\\w]{8}-[\\w]{4}-[\\w]{4}-[\\w]{4}-[\\w]{12}")) { Client tmpClient = this.findClientFromFriendlyName(profileId, clientUUID); // if we can't find a client then fall back to the default ID if (tmpClient == null) { clientUUID = Constants.PROFILE_CLIENT_DEFAULT_ID; } else { return tmpClient; } } PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { String queryString = "SELECT * FROM " + Constants.DB_TABLE_CLIENT + " WHERE " + Constants.CLIENT_CLIENT_UUID + " = ?"; if (profileId != null) { queryString += " AND " + Constants.GENERIC_PROFILE_ID + "=?"; } statement = sqlConnection.prepareStatement(queryString); statement.setString(1, clientUUID); if (profileId != null) { statement.setInt(2, profileId); } 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", "findClient", "(", "String", "clientUUID", ",", "Integer", "profileId", ")", "throws", "Exception", "{", "Client", "client", "=", "null", ";", "/* ERROR CODE: 500 WHEN TRYING TO DELETE A SERVER GROUP.\n THIS APPEARS TO BE BECAUSE CLIENT UUID IS NULL.\n */", "/* CODE ADDED TO PREVENT NULL POINTERS. */", "if", "(", "clientUUID", "==", "null", ")", "{", "clientUUID", "=", "\"\"", ";", "}", "// first see if the clientUUID is actually a uuid.. it might be a friendlyName and need conversion", "/* A UUID IS A UNIVERSALLY UNIQUE IDENTIFIER. */", "if", "(", "clientUUID", ".", "compareTo", "(", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ")", "!=", "0", "&&", "!", "clientUUID", ".", "matches", "(", "\"[\\\\w]{8}-[\\\\w]{4}-[\\\\w]{4}-[\\\\w]{4}-[\\\\w]{12}\"", ")", ")", "{", "Client", "tmpClient", "=", "this", ".", "findClientFromFriendlyName", "(", "profileId", ",", "clientUUID", ")", ";", "// if we can't find a client then fall back to the default ID", "if", "(", "tmpClient", "==", "null", ")", "{", "clientUUID", "=", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ";", "}", "else", "{", "return", "tmpClient", ";", "}", "}", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "String", "queryString", "=", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_CLIENT", "+", "\" WHERE \"", "+", "Constants", ".", "CLIENT_CLIENT_UUID", "+", "\" = ?\"", ";", "if", "(", "profileId", "!=", "null", ")", "{", "queryString", "+=", "\" AND \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\"=?\"", ";", "}", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "queryString", ")", ";", "statement", ".", "setString", "(", "1", ",", "clientUUID", ")", ";", "if", "(", "profileId", "!=", "null", ")", "{", "statement", ".", "setInt", "(", "2", ",", "profileId", ")", ";", "}", "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", ";", "}" ]
Returns a Client object for a clientUUID and profileId @param clientUUID UUID or friendlyName of client @param profileId - can be null, safer if it is not null @return Client object or null @throws Exception exception
[ "Returns", "a", "Client", "object", "for", "a", "clientUUID", "and", "profileId" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L146-L209
164,852
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java
ClientService.getClientFromResultSet
private Client getClientFromResultSet(ResultSet result) throws Exception { Client client = new Client(); client.setId(result.getInt(Constants.GENERIC_ID)); client.setUUID(result.getString(Constants.CLIENT_CLIENT_UUID)); client.setFriendlyName(result.getString(Constants.CLIENT_FRIENDLY_NAME)); client.setProfile(ProfileService.getInstance().findProfile(result.getInt(Constants.GENERIC_PROFILE_ID))); client.setIsActive(result.getBoolean(Constants.CLIENT_IS_ACTIVE)); client.setActiveServerGroup(result.getInt(Constants.CLIENT_ACTIVESERVERGROUP)); return client; }
java
private Client getClientFromResultSet(ResultSet result) throws Exception { Client client = new Client(); client.setId(result.getInt(Constants.GENERIC_ID)); client.setUUID(result.getString(Constants.CLIENT_CLIENT_UUID)); client.setFriendlyName(result.getString(Constants.CLIENT_FRIENDLY_NAME)); client.setProfile(ProfileService.getInstance().findProfile(result.getInt(Constants.GENERIC_PROFILE_ID))); client.setIsActive(result.getBoolean(Constants.CLIENT_IS_ACTIVE)); client.setActiveServerGroup(result.getInt(Constants.CLIENT_ACTIVESERVERGROUP)); return client; }
[ "private", "Client", "getClientFromResultSet", "(", "ResultSet", "result", ")", "throws", "Exception", "{", "Client", "client", "=", "new", "Client", "(", ")", ";", "client", ".", "setId", "(", "result", ".", "getInt", "(", "Constants", ".", "GENERIC_ID", ")", ")", ";", "client", ".", "setUUID", "(", "result", ".", "getString", "(", "Constants", ".", "CLIENT_CLIENT_UUID", ")", ")", ";", "client", ".", "setFriendlyName", "(", "result", ".", "getString", "(", "Constants", ".", "CLIENT_FRIENDLY_NAME", ")", ")", ";", "client", ".", "setProfile", "(", "ProfileService", ".", "getInstance", "(", ")", ".", "findProfile", "(", "result", ".", "getInt", "(", "Constants", ".", "GENERIC_PROFILE_ID", ")", ")", ")", ";", "client", ".", "setIsActive", "(", "result", ".", "getBoolean", "(", "Constants", ".", "CLIENT_IS_ACTIVE", ")", ")", ";", "client", ".", "setActiveServerGroup", "(", "result", ".", "getInt", "(", "Constants", ".", "CLIENT_ACTIVESERVERGROUP", ")", ")", ";", "return", "client", ";", "}" ]
Returns a client model from a ResultSet @param result resultset containing client information @return Client or null @throws Exception exception
[ "Returns", "a", "client", "model", "from", "a", "ResultSet" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L218-L227
164,853
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java
ClientService.setFriendlyName
public Client setFriendlyName(int profileId, String clientUUID, String friendlyName) throws Exception { // first see if this friendlyName is already in use Client client = this.findClientFromFriendlyName(profileId, friendlyName); if (client != null && !client.getUUID().equals(clientUUID)) { throw new Exception("Friendly name already in use"); } PreparedStatement statement = null; int rowsAffected = 0; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_CLIENT + " SET " + Constants.CLIENT_FRIENDLY_NAME + " = ?" + " WHERE " + Constants.CLIENT_CLIENT_UUID + " = ?" + " AND " + Constants.GENERIC_PROFILE_ID + " = ?" ); statement.setString(1, friendlyName); statement.setString(2, clientUUID); statement.setInt(3, profileId); rowsAffected = statement.executeUpdate(); } catch (Exception e) { } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } if (rowsAffected == 0) { return null; } return this.findClient(clientUUID, profileId); }
java
public Client setFriendlyName(int profileId, String clientUUID, String friendlyName) throws Exception { // first see if this friendlyName is already in use Client client = this.findClientFromFriendlyName(profileId, friendlyName); if (client != null && !client.getUUID().equals(clientUUID)) { throw new Exception("Friendly name already in use"); } PreparedStatement statement = null; int rowsAffected = 0; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_CLIENT + " SET " + Constants.CLIENT_FRIENDLY_NAME + " = ?" + " WHERE " + Constants.CLIENT_CLIENT_UUID + " = ?" + " AND " + Constants.GENERIC_PROFILE_ID + " = ?" ); statement.setString(1, friendlyName); statement.setString(2, clientUUID); statement.setInt(3, profileId); rowsAffected = statement.executeUpdate(); } catch (Exception e) { } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } if (rowsAffected == 0) { return null; } return this.findClient(clientUUID, profileId); }
[ "public", "Client", "setFriendlyName", "(", "int", "profileId", ",", "String", "clientUUID", ",", "String", "friendlyName", ")", "throws", "Exception", "{", "// first see if this friendlyName is already in use", "Client", "client", "=", "this", ".", "findClientFromFriendlyName", "(", "profileId", ",", "friendlyName", ")", ";", "if", "(", "client", "!=", "null", "&&", "!", "client", ".", "getUUID", "(", ")", ".", "equals", "(", "clientUUID", ")", ")", "{", "throw", "new", "Exception", "(", "\"Friendly name already in use\"", ")", ";", "}", "PreparedStatement", "statement", "=", "null", ";", "int", "rowsAffected", "=", "0", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"UPDATE \"", "+", "Constants", ".", "DB_TABLE_CLIENT", "+", "\" SET \"", "+", "Constants", ".", "CLIENT_FRIENDLY_NAME", "+", "\" = ?\"", "+", "\" WHERE \"", "+", "Constants", ".", "CLIENT_CLIENT_UUID", "+", "\" = ?\"", "+", "\" AND \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\" = ?\"", ")", ";", "statement", ".", "setString", "(", "1", ",", "friendlyName", ")", ";", "statement", ".", "setString", "(", "2", ",", "clientUUID", ")", ";", "statement", ".", "setInt", "(", "3", ",", "profileId", ")", ";", "rowsAffected", "=", "statement", ".", "executeUpdate", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "if", "(", "rowsAffected", "==", "0", ")", "{", "return", "null", ";", "}", "return", "this", ".", "findClient", "(", "clientUUID", ",", "profileId", ")", ";", "}" ]
Set a friendly name for a client @param profileId profileId of the client @param clientUUID UUID of the client @param friendlyName friendly name of the client @return return Client object or null @throws Exception exception
[ "Set", "a", "friendly", "name", "for", "a", "client" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L382-L419
164,854
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java
ClientService.updateActive
public void updateActive(int profileId, String clientUUID, Boolean active) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_CLIENT + " SET " + Constants.CLIENT_IS_ACTIVE + "= ?" + " WHERE " + Constants.GENERIC_CLIENT_UUID + "= ? " + " AND " + Constants.GENERIC_PROFILE_ID + "= ?" ); statement.setBoolean(1, active); statement.setString(2, clientUUID); statement.setInt(3, profileId); statement.executeUpdate(); } catch (Exception e) { // ok to swallow this.. just means there wasn't any } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } }
java
public void updateActive(int profileId, String clientUUID, Boolean active) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_CLIENT + " SET " + Constants.CLIENT_IS_ACTIVE + "= ?" + " WHERE " + Constants.GENERIC_CLIENT_UUID + "= ? " + " AND " + Constants.GENERIC_PROFILE_ID + "= ?" ); statement.setBoolean(1, active); statement.setString(2, clientUUID); statement.setInt(3, profileId); statement.executeUpdate(); } catch (Exception e) { // ok to swallow this.. just means there wasn't any } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } }
[ "public", "void", "updateActive", "(", "int", "profileId", ",", "String", "clientUUID", ",", "Boolean", "active", ")", "throws", "Exception", "{", "PreparedStatement", "statement", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"UPDATE \"", "+", "Constants", ".", "DB_TABLE_CLIENT", "+", "\" SET \"", "+", "Constants", ".", "CLIENT_IS_ACTIVE", "+", "\"= ?\"", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_CLIENT_UUID", "+", "\"= ? \"", "+", "\" AND \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\"= ?\"", ")", ";", "statement", ".", "setBoolean", "(", "1", ",", "active", ")", ";", "statement", ".", "setString", "(", "2", ",", "clientUUID", ")", ";", "statement", ".", "setInt", "(", "3", ",", "profileId", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "// ok to swallow this.. just means there wasn't any", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}" ]
disables the current active id, enables the new one selected @param profileId profile ID of the client @param clientUUID UUID of the client @param active true to make client active, false to make client inactive @throws Exception exception
[ "disables", "the", "current", "active", "id", "enables", "the", "new", "one", "selected" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L580-L603
164,855
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java
ClientService.reset
public void reset(int profileId, String clientUUID) throws Exception { PreparedStatement statement = null; // TODO: need a better way to do this than brute force.. but the iterative approach is too slow try (Connection sqlConnection = sqlService.getConnection()) { // first remove all enabled overrides with this client uuid String queryString = "DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE + " WHERE " + Constants.GENERIC_CLIENT_UUID + "= ? " + " AND " + Constants.GENERIC_PROFILE_ID + " = ?"; statement = sqlConnection.prepareStatement(queryString); statement.setString(1, clientUUID); statement.setInt(2, profileId); statement.executeUpdate(); statement.close(); // clean up request response table for this uuid queryString = "UPDATE " + Constants.DB_TABLE_REQUEST_RESPONSE + " SET " + Constants.REQUEST_RESPONSE_CUSTOM_REQUEST + "=?, " + Constants.REQUEST_RESPONSE_CUSTOM_RESPONSE + "=?, " + Constants.REQUEST_RESPONSE_REPEAT_NUMBER + "=-1, " + Constants.REQUEST_RESPONSE_REQUEST_ENABLED + "=0, " + Constants.REQUEST_RESPONSE_RESPONSE_ENABLED + "=0 " + "WHERE " + Constants.GENERIC_CLIENT_UUID + "=? " + " AND " + Constants.GENERIC_PROFILE_ID + "=?"; statement = sqlConnection.prepareStatement(queryString); statement.setString(1, ""); statement.setString(2, ""); statement.setString(3, clientUUID); statement.setInt(4, profileId); statement.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } this.updateActive(profileId, clientUUID, false); }
java
public void reset(int profileId, String clientUUID) throws Exception { PreparedStatement statement = null; // TODO: need a better way to do this than brute force.. but the iterative approach is too slow try (Connection sqlConnection = sqlService.getConnection()) { // first remove all enabled overrides with this client uuid String queryString = "DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE + " WHERE " + Constants.GENERIC_CLIENT_UUID + "= ? " + " AND " + Constants.GENERIC_PROFILE_ID + " = ?"; statement = sqlConnection.prepareStatement(queryString); statement.setString(1, clientUUID); statement.setInt(2, profileId); statement.executeUpdate(); statement.close(); // clean up request response table for this uuid queryString = "UPDATE " + Constants.DB_TABLE_REQUEST_RESPONSE + " SET " + Constants.REQUEST_RESPONSE_CUSTOM_REQUEST + "=?, " + Constants.REQUEST_RESPONSE_CUSTOM_RESPONSE + "=?, " + Constants.REQUEST_RESPONSE_REPEAT_NUMBER + "=-1, " + Constants.REQUEST_RESPONSE_REQUEST_ENABLED + "=0, " + Constants.REQUEST_RESPONSE_RESPONSE_ENABLED + "=0 " + "WHERE " + Constants.GENERIC_CLIENT_UUID + "=? " + " AND " + Constants.GENERIC_PROFILE_ID + "=?"; statement = sqlConnection.prepareStatement(queryString); statement.setString(1, ""); statement.setString(2, ""); statement.setString(3, clientUUID); statement.setInt(4, profileId); statement.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } this.updateActive(profileId, clientUUID, false); }
[ "public", "void", "reset", "(", "int", "profileId", ",", "String", "clientUUID", ")", "throws", "Exception", "{", "PreparedStatement", "statement", "=", "null", ";", "// TODO: need a better way to do this than brute force.. but the iterative approach is too slow", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "// first remove all enabled overrides with this client uuid", "String", "queryString", "=", "\"DELETE FROM \"", "+", "Constants", ".", "DB_TABLE_ENABLED_OVERRIDE", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_CLIENT_UUID", "+", "\"= ? \"", "+", "\" AND \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\" = ?\"", ";", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "queryString", ")", ";", "statement", ".", "setString", "(", "1", ",", "clientUUID", ")", ";", "statement", ".", "setInt", "(", "2", ",", "profileId", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "statement", ".", "close", "(", ")", ";", "// clean up request response table for this uuid", "queryString", "=", "\"UPDATE \"", "+", "Constants", ".", "DB_TABLE_REQUEST_RESPONSE", "+", "\" SET \"", "+", "Constants", ".", "REQUEST_RESPONSE_CUSTOM_REQUEST", "+", "\"=?, \"", "+", "Constants", ".", "REQUEST_RESPONSE_CUSTOM_RESPONSE", "+", "\"=?, \"", "+", "Constants", ".", "REQUEST_RESPONSE_REPEAT_NUMBER", "+", "\"=-1, \"", "+", "Constants", ".", "REQUEST_RESPONSE_REQUEST_ENABLED", "+", "\"=0, \"", "+", "Constants", ".", "REQUEST_RESPONSE_RESPONSE_ENABLED", "+", "\"=0 \"", "+", "\"WHERE \"", "+", "Constants", ".", "GENERIC_CLIENT_UUID", "+", "\"=? \"", "+", "\" AND \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\"=?\"", ";", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "queryString", ")", ";", "statement", ".", "setString", "(", "1", ",", "\"\"", ")", ";", "statement", ".", "setString", "(", "2", ",", "\"\"", ")", ";", "statement", ".", "setString", "(", "3", ",", "clientUUID", ")", ";", "statement", ".", "setInt", "(", "4", ",", "profileId", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "this", ".", "updateActive", "(", "profileId", ",", "clientUUID", ",", "false", ")", ";", "}" ]
Resets all override settings for the clientUUID and disables it @param profileId profile ID of the client @param clientUUID UUID of the client @throws Exception exception
[ "Resets", "all", "override", "settings", "for", "the", "clientUUID", "and", "disables", "it" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L612-L655
164,856
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java
ClientService.getProfileIdFromClientId
public String getProfileIdFromClientId(int id) { return (String) sqlService.getFromTable(Constants.CLIENT_PROFILE_ID, Constants.GENERIC_ID, id, Constants.DB_TABLE_CLIENT); }
java
public String getProfileIdFromClientId(int id) { return (String) sqlService.getFromTable(Constants.CLIENT_PROFILE_ID, Constants.GENERIC_ID, id, Constants.DB_TABLE_CLIENT); }
[ "public", "String", "getProfileIdFromClientId", "(", "int", "id", ")", "{", "return", "(", "String", ")", "sqlService", ".", "getFromTable", "(", "Constants", ".", "CLIENT_PROFILE_ID", ",", "Constants", ".", "GENERIC_ID", ",", "id", ",", "Constants", ".", "DB_TABLE_CLIENT", ")", ";", "}" ]
gets the profile_name associated with a specific id
[ "gets", "the", "profile_name", "associated", "with", "a", "specific", "id" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ClientService.java#L666-L668
164,857
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/ScriptController.java
ScriptController.scriptView
@RequestMapping(value = "/scripts", method = RequestMethod.GET) public String scriptView(Model model) throws Exception { return "script"; }
java
@RequestMapping(value = "/scripts", method = RequestMethod.GET) public String scriptView(Model model) throws Exception { return "script"; }
[ "@", "RequestMapping", "(", "value", "=", "\"/scripts\"", ",", "method", "=", "RequestMethod", ".", "GET", ")", "public", "String", "scriptView", "(", "Model", "model", ")", "throws", "Exception", "{", "return", "\"script\"", ";", "}" ]
Returns script view @param model @return @throws Exception
[ "Returns", "script", "view" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ScriptController.java#L36-L39
164,858
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/ScriptController.java
ScriptController.getScripts
@RequestMapping(value = "/api/scripts", method = RequestMethod.GET) public @ResponseBody HashMap<String, Object> getScripts(Model model, @RequestParam(required = false) Integer type) throws Exception { Script[] scripts = ScriptService.getInstance().getScripts(type); return Utils.getJQGridJSON(scripts, "scripts"); }
java
@RequestMapping(value = "/api/scripts", method = RequestMethod.GET) public @ResponseBody HashMap<String, Object> getScripts(Model model, @RequestParam(required = false) Integer type) throws Exception { Script[] scripts = ScriptService.getInstance().getScripts(type); return Utils.getJQGridJSON(scripts, "scripts"); }
[ "@", "RequestMapping", "(", "value", "=", "\"/api/scripts\"", ",", "method", "=", "RequestMethod", ".", "GET", ")", "public", "@", "ResponseBody", "HashMap", "<", "String", ",", "Object", ">", "getScripts", "(", "Model", "model", ",", "@", "RequestParam", "(", "required", "=", "false", ")", "Integer", "type", ")", "throws", "Exception", "{", "Script", "[", "]", "scripts", "=", "ScriptService", ".", "getInstance", "(", ")", ".", "getScripts", "(", "type", ")", ";", "return", "Utils", ".", "getJQGridJSON", "(", "scripts", ",", "\"scripts\"", ")", ";", "}" ]
Returns all scripts @param model @param type - optional to specify type of script to return @return @throws Exception
[ "Returns", "all", "scripts" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ScriptController.java#L49-L56
164,859
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/ScriptController.java
ScriptController.addScript
@RequestMapping(value = "/api/scripts", method = RequestMethod.POST) public @ResponseBody Script addScript(Model model, @RequestParam(required = true) String name, @RequestParam(required = true) String script) throws Exception { return ScriptService.getInstance().addScript(name, script); }
java
@RequestMapping(value = "/api/scripts", method = RequestMethod.POST) public @ResponseBody Script addScript(Model model, @RequestParam(required = true) String name, @RequestParam(required = true) String script) throws Exception { return ScriptService.getInstance().addScript(name, script); }
[ "@", "RequestMapping", "(", "value", "=", "\"/api/scripts\"", ",", "method", "=", "RequestMethod", ".", "POST", ")", "public", "@", "ResponseBody", "Script", "addScript", "(", "Model", "model", ",", "@", "RequestParam", "(", "required", "=", "true", ")", "String", "name", ",", "@", "RequestParam", "(", "required", "=", "true", ")", "String", "script", ")", "throws", "Exception", "{", "return", "ScriptService", ".", "getInstance", "(", ")", ".", "addScript", "(", "name", ",", "script", ")", ";", "}" ]
Add a new script @param model @param name @param script @return @throws Exception
[ "Add", "a", "new", "script" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/ScriptController.java#L129-L137
164,860
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/GroupController.java
GroupController.newGroupGet
@RequestMapping(value = "group", method = RequestMethod.GET) public String newGroupGet(Model model) { model.addAttribute("groups", pathOverrideService.findAllGroups()); return "groups"; }
java
@RequestMapping(value = "group", method = RequestMethod.GET) public String newGroupGet(Model model) { model.addAttribute("groups", pathOverrideService.findAllGroups()); return "groups"; }
[ "@", "RequestMapping", "(", "value", "=", "\"group\"", ",", "method", "=", "RequestMethod", ".", "GET", ")", "public", "String", "newGroupGet", "(", "Model", "model", ")", "{", "model", ".", "addAttribute", "(", "\"groups\"", ",", "pathOverrideService", ".", "findAllGroups", "(", ")", ")", ";", "return", "\"groups\"", ";", "}" ]
Redirect to page @param model @return
[ "Redirect", "to", "page" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/GroupController.java#L48-L53
164,861
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.createKeystore
protected void createKeystore() { java.security.cert.Certificate signingCert = null; PrivateKey caPrivKey = null; if(_caCert == null || _caPrivKey == null) { try { log.debug("Keystore or signing cert & keypair not found. Generating..."); KeyPair caKeypair = getRSAKeyPair(); caPrivKey = caKeypair.getPrivate(); signingCert = CertificateCreator.createTypicalMasterCert(caKeypair); log.debug("Done generating signing cert"); log.debug(signingCert); _ks.load(null, _keystorepass); _ks.setCertificateEntry(_caCertAlias, signingCert); _ks.setKeyEntry(_caPrivKeyAlias, caPrivKey, _keypassword, new java.security.cert.Certificate[] {signingCert}); File caKsFile = new File(root, _caPrivateKeystore); OutputStream os = new FileOutputStream(caKsFile); _ks.store(os, _keystorepass); log.debug("Wrote JKS keystore to: " + caKsFile.getAbsolutePath()); // also export a .cer that can be imported as a trusted root // to disable all warning dialogs for interception File signingCertFile = new File(root, EXPORTED_CERT_NAME); FileOutputStream cerOut = new FileOutputStream(signingCertFile); byte[] buf = signingCert.getEncoded(); log.debug("Wrote signing cert to: " + signingCertFile.getAbsolutePath()); cerOut.write(buf); cerOut.flush(); cerOut.close(); _caCert = (X509Certificate)signingCert; _caPrivKey = caPrivKey; } catch(Exception e) { log.error("Fatal error creating/storing keystore or signing cert.", e); throw new Error(e); } } else { log.debug("Successfully loaded keystore."); log.debug(_caCert); } }
java
protected void createKeystore() { java.security.cert.Certificate signingCert = null; PrivateKey caPrivKey = null; if(_caCert == null || _caPrivKey == null) { try { log.debug("Keystore or signing cert & keypair not found. Generating..."); KeyPair caKeypair = getRSAKeyPair(); caPrivKey = caKeypair.getPrivate(); signingCert = CertificateCreator.createTypicalMasterCert(caKeypair); log.debug("Done generating signing cert"); log.debug(signingCert); _ks.load(null, _keystorepass); _ks.setCertificateEntry(_caCertAlias, signingCert); _ks.setKeyEntry(_caPrivKeyAlias, caPrivKey, _keypassword, new java.security.cert.Certificate[] {signingCert}); File caKsFile = new File(root, _caPrivateKeystore); OutputStream os = new FileOutputStream(caKsFile); _ks.store(os, _keystorepass); log.debug("Wrote JKS keystore to: " + caKsFile.getAbsolutePath()); // also export a .cer that can be imported as a trusted root // to disable all warning dialogs for interception File signingCertFile = new File(root, EXPORTED_CERT_NAME); FileOutputStream cerOut = new FileOutputStream(signingCertFile); byte[] buf = signingCert.getEncoded(); log.debug("Wrote signing cert to: " + signingCertFile.getAbsolutePath()); cerOut.write(buf); cerOut.flush(); cerOut.close(); _caCert = (X509Certificate)signingCert; _caPrivKey = caPrivKey; } catch(Exception e) { log.error("Fatal error creating/storing keystore or signing cert.", e); throw new Error(e); } } else { log.debug("Successfully loaded keystore."); log.debug(_caCert); } }
[ "protected", "void", "createKeystore", "(", ")", "{", "java", ".", "security", ".", "cert", ".", "Certificate", "signingCert", "=", "null", ";", "PrivateKey", "caPrivKey", "=", "null", ";", "if", "(", "_caCert", "==", "null", "||", "_caPrivKey", "==", "null", ")", "{", "try", "{", "log", ".", "debug", "(", "\"Keystore or signing cert & keypair not found. Generating...\"", ")", ";", "KeyPair", "caKeypair", "=", "getRSAKeyPair", "(", ")", ";", "caPrivKey", "=", "caKeypair", ".", "getPrivate", "(", ")", ";", "signingCert", "=", "CertificateCreator", ".", "createTypicalMasterCert", "(", "caKeypair", ")", ";", "log", ".", "debug", "(", "\"Done generating signing cert\"", ")", ";", "log", ".", "debug", "(", "signingCert", ")", ";", "_ks", ".", "load", "(", "null", ",", "_keystorepass", ")", ";", "_ks", ".", "setCertificateEntry", "(", "_caCertAlias", ",", "signingCert", ")", ";", "_ks", ".", "setKeyEntry", "(", "_caPrivKeyAlias", ",", "caPrivKey", ",", "_keypassword", ",", "new", "java", ".", "security", ".", "cert", ".", "Certificate", "[", "]", "{", "signingCert", "}", ")", ";", "File", "caKsFile", "=", "new", "File", "(", "root", ",", "_caPrivateKeystore", ")", ";", "OutputStream", "os", "=", "new", "FileOutputStream", "(", "caKsFile", ")", ";", "_ks", ".", "store", "(", "os", ",", "_keystorepass", ")", ";", "log", ".", "debug", "(", "\"Wrote JKS keystore to: \"", "+", "caKsFile", ".", "getAbsolutePath", "(", ")", ")", ";", "// also export a .cer that can be imported as a trusted root", "// to disable all warning dialogs for interception", "File", "signingCertFile", "=", "new", "File", "(", "root", ",", "EXPORTED_CERT_NAME", ")", ";", "FileOutputStream", "cerOut", "=", "new", "FileOutputStream", "(", "signingCertFile", ")", ";", "byte", "[", "]", "buf", "=", "signingCert", ".", "getEncoded", "(", ")", ";", "log", ".", "debug", "(", "\"Wrote signing cert to: \"", "+", "signingCertFile", ".", "getAbsolutePath", "(", ")", ")", ";", "cerOut", ".", "write", "(", "buf", ")", ";", "cerOut", ".", "flush", "(", ")", ";", "cerOut", ".", "close", "(", ")", ";", "_caCert", "=", "(", "X509Certificate", ")", "signingCert", ";", "_caPrivKey", "=", "caPrivKey", ";", "}", "catch", "(", "Exception", "e", ")", "{", "log", ".", "error", "(", "\"Fatal error creating/storing keystore or signing cert.\"", ",", "e", ")", ";", "throw", "new", "Error", "(", "e", ")", ";", "}", "}", "else", "{", "log", ".", "debug", "(", "\"Successfully loaded keystore.\"", ")", ";", "log", ".", "debug", "(", "_caCert", ")", ";", "}", "}" ]
Creates, writes and loads a new keystore and CA root certificate.
[ "Creates", "writes", "and", "loads", "a", "new", "keystore", "and", "CA", "root", "certificate", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L475-L537
164,862
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.addCertAndPrivateKey
public synchronized void addCertAndPrivateKey(String hostname, final X509Certificate cert, final PrivateKey privKey) throws KeyStoreException, CertificateException, NoSuchAlgorithmException { // String alias = ThumbprintUtil.getThumbprint(cert); _ks.deleteEntry(hostname); _ks.setCertificateEntry(hostname, cert); _ks.setKeyEntry(hostname, privKey, _keypassword, new java.security.cert.Certificate[] {cert}); if(persistImmediately) { persist(); } }
java
public synchronized void addCertAndPrivateKey(String hostname, final X509Certificate cert, final PrivateKey privKey) throws KeyStoreException, CertificateException, NoSuchAlgorithmException { // String alias = ThumbprintUtil.getThumbprint(cert); _ks.deleteEntry(hostname); _ks.setCertificateEntry(hostname, cert); _ks.setKeyEntry(hostname, privKey, _keypassword, new java.security.cert.Certificate[] {cert}); if(persistImmediately) { persist(); } }
[ "public", "synchronized", "void", "addCertAndPrivateKey", "(", "String", "hostname", ",", "final", "X509Certificate", "cert", ",", "final", "PrivateKey", "privKey", ")", "throws", "KeyStoreException", ",", "CertificateException", ",", "NoSuchAlgorithmException", "{", "//\t\tString alias = ThumbprintUtil.getThumbprint(cert);", "_ks", ".", "deleteEntry", "(", "hostname", ")", ";", "_ks", ".", "setCertificateEntry", "(", "hostname", ",", "cert", ")", ";", "_ks", ".", "setKeyEntry", "(", "hostname", ",", "privKey", ",", "_keypassword", ",", "new", "java", ".", "security", ".", "cert", ".", "Certificate", "[", "]", "{", "cert", "}", ")", ";", "if", "(", "persistImmediately", ")", "{", "persist", "(", ")", ";", "}", "}" ]
Stores a new certificate and its associated private key in the keystore. @param hostname @param cert @param privKey @throws KeyStoreException @throws CertificateException @throws NoSuchAlgorithmException
[ "Stores", "a", "new", "certificate", "and", "its", "associated", "private", "key", "in", "the", "keystore", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L547-L562
164,863
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.getCertificateByHostname
public synchronized X509Certificate getCertificateByHostname(final String hostname) throws KeyStoreException, CertificateParsingException, InvalidKeyException, CertificateExpiredException, CertificateNotYetValidException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, UnrecoverableKeyException{ String alias = _subjectMap.get(getSubjectForHostname(hostname)); if(alias != null) { return (X509Certificate)_ks.getCertificate(alias); } return getMappedCertificateForHostname(hostname); }
java
public synchronized X509Certificate getCertificateByHostname(final String hostname) throws KeyStoreException, CertificateParsingException, InvalidKeyException, CertificateExpiredException, CertificateNotYetValidException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, UnrecoverableKeyException{ String alias = _subjectMap.get(getSubjectForHostname(hostname)); if(alias != null) { return (X509Certificate)_ks.getCertificate(alias); } return getMappedCertificateForHostname(hostname); }
[ "public", "synchronized", "X509Certificate", "getCertificateByHostname", "(", "final", "String", "hostname", ")", "throws", "KeyStoreException", ",", "CertificateParsingException", ",", "InvalidKeyException", ",", "CertificateExpiredException", ",", "CertificateNotYetValidException", ",", "SignatureException", ",", "CertificateException", ",", "NoSuchAlgorithmException", ",", "NoSuchProviderException", ",", "UnrecoverableKeyException", "{", "String", "alias", "=", "_subjectMap", ".", "get", "(", "getSubjectForHostname", "(", "hostname", ")", ")", ";", "if", "(", "alias", "!=", "null", ")", "{", "return", "(", "X509Certificate", ")", "_ks", ".", "getCertificate", "(", "alias", ")", ";", "}", "return", "getMappedCertificateForHostname", "(", "hostname", ")", ";", "}" ]
Returns the aliased certificate. Certificates are aliased by their hostname. @see ThumbprintUtil @param alias @return @throws KeyStoreException @throws UnrecoverableKeyException @throws NoSuchProviderException @throws NoSuchAlgorithmException @throws CertificateException @throws SignatureException @throws CertificateNotYetValidException @throws CertificateExpiredException @throws InvalidKeyException @throws CertificateParsingException
[ "Returns", "the", "aliased", "certificate", ".", "Certificates", "are", "aliased", "by", "their", "hostname", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L615-L623
164,864
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.getMappedCertificate
public synchronized X509Certificate getMappedCertificate(final X509Certificate cert) throws CertificateEncodingException, InvalidKeyException, CertificateException, CertificateNotYetValidException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, KeyStoreException, UnrecoverableKeyException { String thumbprint = ThumbprintUtil.getThumbprint(cert); String mappedCertThumbprint = _certMap.get(thumbprint); if(mappedCertThumbprint == null) { // Check if we've already mapped this public key from a KeyValue PublicKey mappedPk = getMappedPublicKey(cert.getPublicKey()); PrivateKey privKey; if(mappedPk == null) { PublicKey pk = cert.getPublicKey(); String algo = pk.getAlgorithm(); KeyPair kp; if(algo.equals("RSA")) { kp = getRSAKeyPair(); } else if(algo.equals("DSA")) { kp = getDSAKeyPair(); } else { throw new InvalidKeyException("Key algorithm " + algo + " not supported."); } mappedPk = kp.getPublic(); privKey = kp.getPrivate(); mapPublicKeys(cert.getPublicKey(), mappedPk); } else { privKey = getPrivateKey(mappedPk); } X509Certificate replacementCert = CertificateCreator.mitmDuplicateCertificate( cert, mappedPk, getSigningCert(), getSigningPrivateKey()); addCertAndPrivateKey(null, replacementCert, privKey); mappedCertThumbprint = ThumbprintUtil.getThumbprint(replacementCert); _certMap.put(thumbprint, mappedCertThumbprint); _certMap.put(mappedCertThumbprint, thumbprint); _subjectMap.put(replacementCert.getSubjectX500Principal().getName(), thumbprint); if(persistImmediately) { persist(); } return replacementCert; } return getCertificateByAlias(mappedCertThumbprint); }
java
public synchronized X509Certificate getMappedCertificate(final X509Certificate cert) throws CertificateEncodingException, InvalidKeyException, CertificateException, CertificateNotYetValidException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, KeyStoreException, UnrecoverableKeyException { String thumbprint = ThumbprintUtil.getThumbprint(cert); String mappedCertThumbprint = _certMap.get(thumbprint); if(mappedCertThumbprint == null) { // Check if we've already mapped this public key from a KeyValue PublicKey mappedPk = getMappedPublicKey(cert.getPublicKey()); PrivateKey privKey; if(mappedPk == null) { PublicKey pk = cert.getPublicKey(); String algo = pk.getAlgorithm(); KeyPair kp; if(algo.equals("RSA")) { kp = getRSAKeyPair(); } else if(algo.equals("DSA")) { kp = getDSAKeyPair(); } else { throw new InvalidKeyException("Key algorithm " + algo + " not supported."); } mappedPk = kp.getPublic(); privKey = kp.getPrivate(); mapPublicKeys(cert.getPublicKey(), mappedPk); } else { privKey = getPrivateKey(mappedPk); } X509Certificate replacementCert = CertificateCreator.mitmDuplicateCertificate( cert, mappedPk, getSigningCert(), getSigningPrivateKey()); addCertAndPrivateKey(null, replacementCert, privKey); mappedCertThumbprint = ThumbprintUtil.getThumbprint(replacementCert); _certMap.put(thumbprint, mappedCertThumbprint); _certMap.put(mappedCertThumbprint, thumbprint); _subjectMap.put(replacementCert.getSubjectX500Principal().getName(), thumbprint); if(persistImmediately) { persist(); } return replacementCert; } return getCertificateByAlias(mappedCertThumbprint); }
[ "public", "synchronized", "X509Certificate", "getMappedCertificate", "(", "final", "X509Certificate", "cert", ")", "throws", "CertificateEncodingException", ",", "InvalidKeyException", ",", "CertificateException", ",", "CertificateNotYetValidException", ",", "NoSuchAlgorithmException", ",", "NoSuchProviderException", ",", "SignatureException", ",", "KeyStoreException", ",", "UnrecoverableKeyException", "{", "String", "thumbprint", "=", "ThumbprintUtil", ".", "getThumbprint", "(", "cert", ")", ";", "String", "mappedCertThumbprint", "=", "_certMap", ".", "get", "(", "thumbprint", ")", ";", "if", "(", "mappedCertThumbprint", "==", "null", ")", "{", "// Check if we've already mapped this public key from a KeyValue", "PublicKey", "mappedPk", "=", "getMappedPublicKey", "(", "cert", ".", "getPublicKey", "(", ")", ")", ";", "PrivateKey", "privKey", ";", "if", "(", "mappedPk", "==", "null", ")", "{", "PublicKey", "pk", "=", "cert", ".", "getPublicKey", "(", ")", ";", "String", "algo", "=", "pk", ".", "getAlgorithm", "(", ")", ";", "KeyPair", "kp", ";", "if", "(", "algo", ".", "equals", "(", "\"RSA\"", ")", ")", "{", "kp", "=", "getRSAKeyPair", "(", ")", ";", "}", "else", "if", "(", "algo", ".", "equals", "(", "\"DSA\"", ")", ")", "{", "kp", "=", "getDSAKeyPair", "(", ")", ";", "}", "else", "{", "throw", "new", "InvalidKeyException", "(", "\"Key algorithm \"", "+", "algo", "+", "\" not supported.\"", ")", ";", "}", "mappedPk", "=", "kp", ".", "getPublic", "(", ")", ";", "privKey", "=", "kp", ".", "getPrivate", "(", ")", ";", "mapPublicKeys", "(", "cert", ".", "getPublicKey", "(", ")", ",", "mappedPk", ")", ";", "}", "else", "{", "privKey", "=", "getPrivateKey", "(", "mappedPk", ")", ";", "}", "X509Certificate", "replacementCert", "=", "CertificateCreator", ".", "mitmDuplicateCertificate", "(", "cert", ",", "mappedPk", ",", "getSigningCert", "(", ")", ",", "getSigningPrivateKey", "(", ")", ")", ";", "addCertAndPrivateKey", "(", "null", ",", "replacementCert", ",", "privKey", ")", ";", "mappedCertThumbprint", "=", "ThumbprintUtil", ".", "getThumbprint", "(", "replacementCert", ")", ";", "_certMap", ".", "put", "(", "thumbprint", ",", "mappedCertThumbprint", ")", ";", "_certMap", ".", "put", "(", "mappedCertThumbprint", ",", "thumbprint", ")", ";", "_subjectMap", ".", "put", "(", "replacementCert", ".", "getSubjectX500Principal", "(", ")", ".", "getName", "(", ")", ",", "thumbprint", ")", ";", "if", "(", "persistImmediately", ")", "{", "persist", "(", ")", ";", "}", "return", "replacementCert", ";", "}", "return", "getCertificateByAlias", "(", "mappedCertThumbprint", ")", ";", "}" ]
This method returns the duplicated certificate mapped to the passed in cert, or creates and returns one if no mapping has yet been performed. If a naked public key has already been mapped that matches the key in the cert, the already mapped keypair will be reused for the mapped cert. @param cert @return @throws CertificateEncodingException @throws InvalidKeyException @throws CertificateException @throws CertificateNotYetValidException @throws NoSuchAlgorithmException @throws NoSuchProviderException @throws SignatureException @throws KeyStoreException @throws UnrecoverableKeyException
[ "This", "method", "returns", "the", "duplicated", "certificate", "mapped", "to", "the", "passed", "in", "cert", "or", "creates", "and", "returns", "one", "if", "no", "mapping", "has", "yet", "been", "performed", ".", "If", "a", "naked", "public", "key", "has", "already", "been", "mapped", "that", "matches", "the", "key", "in", "the", "cert", "the", "already", "mapped", "keypair", "will", "be", "reused", "for", "the", "mapped", "cert", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L680-L754
164,865
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.getMappedCertificateForHostname
public X509Certificate getMappedCertificateForHostname(String hostname) throws CertificateParsingException, InvalidKeyException, CertificateExpiredException, CertificateNotYetValidException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, KeyStoreException, UnrecoverableKeyException { String subject = getSubjectForHostname(hostname); String thumbprint = _subjectMap.get(subject); if(thumbprint == null) { KeyPair kp = getRSAKeyPair(); X509Certificate newCert = CertificateCreator.generateStdSSLServerCertificate(kp.getPublic(), getSigningCert(), getSigningPrivateKey(), subject); addCertAndPrivateKey(hostname, newCert, kp.getPrivate()); thumbprint = ThumbprintUtil.getThumbprint(newCert); _subjectMap.put(subject, thumbprint); if(persistImmediately) { persist(); } return newCert; } return getCertificateByAlias(thumbprint); }
java
public X509Certificate getMappedCertificateForHostname(String hostname) throws CertificateParsingException, InvalidKeyException, CertificateExpiredException, CertificateNotYetValidException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, KeyStoreException, UnrecoverableKeyException { String subject = getSubjectForHostname(hostname); String thumbprint = _subjectMap.get(subject); if(thumbprint == null) { KeyPair kp = getRSAKeyPair(); X509Certificate newCert = CertificateCreator.generateStdSSLServerCertificate(kp.getPublic(), getSigningCert(), getSigningPrivateKey(), subject); addCertAndPrivateKey(hostname, newCert, kp.getPrivate()); thumbprint = ThumbprintUtil.getThumbprint(newCert); _subjectMap.put(subject, thumbprint); if(persistImmediately) { persist(); } return newCert; } return getCertificateByAlias(thumbprint); }
[ "public", "X509Certificate", "getMappedCertificateForHostname", "(", "String", "hostname", ")", "throws", "CertificateParsingException", ",", "InvalidKeyException", ",", "CertificateExpiredException", ",", "CertificateNotYetValidException", ",", "SignatureException", ",", "CertificateException", ",", "NoSuchAlgorithmException", ",", "NoSuchProviderException", ",", "KeyStoreException", ",", "UnrecoverableKeyException", "{", "String", "subject", "=", "getSubjectForHostname", "(", "hostname", ")", ";", "String", "thumbprint", "=", "_subjectMap", ".", "get", "(", "subject", ")", ";", "if", "(", "thumbprint", "==", "null", ")", "{", "KeyPair", "kp", "=", "getRSAKeyPair", "(", ")", ";", "X509Certificate", "newCert", "=", "CertificateCreator", ".", "generateStdSSLServerCertificate", "(", "kp", ".", "getPublic", "(", ")", ",", "getSigningCert", "(", ")", ",", "getSigningPrivateKey", "(", ")", ",", "subject", ")", ";", "addCertAndPrivateKey", "(", "hostname", ",", "newCert", ",", "kp", ".", "getPrivate", "(", ")", ")", ";", "thumbprint", "=", "ThumbprintUtil", ".", "getThumbprint", "(", "newCert", ")", ";", "_subjectMap", ".", "put", "(", "subject", ",", "thumbprint", ")", ";", "if", "(", "persistImmediately", ")", "{", "persist", "(", ")", ";", "}", "return", "newCert", ";", "}", "return", "getCertificateByAlias", "(", "thumbprint", ")", ";", "}" ]
This method returns the mapped certificate for a hostname, or generates a "standard" SSL server certificate issued by the CA to the supplied subject if no mapping has been created. This is not a true duplication, just a shortcut method that is adequate for web browsers. @param hostname @return @throws CertificateParsingException @throws InvalidKeyException @throws CertificateExpiredException @throws CertificateNotYetValidException @throws SignatureException @throws CertificateException @throws NoSuchAlgorithmException @throws NoSuchProviderException @throws KeyStoreException @throws UnrecoverableKeyException
[ "This", "method", "returns", "the", "mapped", "certificate", "for", "a", "hostname", "or", "generates", "a", "standard", "SSL", "server", "certificate", "issued", "by", "the", "CA", "to", "the", "supplied", "subject", "if", "no", "mapping", "has", "been", "created", ".", "This", "is", "not", "a", "true", "duplication", "just", "a", "shortcut", "method", "that", "is", "adequate", "for", "web", "browsers", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L775-L806
164,866
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.getPrivateKeyForLocalCert
public synchronized PrivateKey getPrivateKeyForLocalCert(final X509Certificate cert) throws CertificateEncodingException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException { String thumbprint = ThumbprintUtil.getThumbprint(cert); return (PrivateKey)_ks.getKey(thumbprint, _keypassword); }
java
public synchronized PrivateKey getPrivateKeyForLocalCert(final X509Certificate cert) throws CertificateEncodingException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException { String thumbprint = ThumbprintUtil.getThumbprint(cert); return (PrivateKey)_ks.getKey(thumbprint, _keypassword); }
[ "public", "synchronized", "PrivateKey", "getPrivateKeyForLocalCert", "(", "final", "X509Certificate", "cert", ")", "throws", "CertificateEncodingException", ",", "KeyStoreException", ",", "UnrecoverableKeyException", ",", "NoSuchAlgorithmException", "{", "String", "thumbprint", "=", "ThumbprintUtil", ".", "getThumbprint", "(", "cert", ")", ";", "return", "(", "PrivateKey", ")", "_ks", ".", "getKey", "(", "thumbprint", ",", "_keypassword", ")", ";", "}" ]
For a cert we have generated, return the private key. @param cert @return @throws CertificateEncodingException @throws KeyStoreException @throws UnrecoverableKeyException @throws NoSuchAlgorithmException
[ "For", "a", "cert", "we", "have", "generated", "return", "the", "private", "key", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L858-L865
164,867
groupon/odo
browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java
KeyStoreManager.mapPublicKeys
public synchronized void mapPublicKeys(final PublicKey original, final PublicKey substitute) { _mappedPublicKeys.put(original, substitute); if(persistImmediately) { persistPublicKeyMap(); } }
java
public synchronized void mapPublicKeys(final PublicKey original, final PublicKey substitute) { _mappedPublicKeys.put(original, substitute); if(persistImmediately) { persistPublicKeyMap(); } }
[ "public", "synchronized", "void", "mapPublicKeys", "(", "final", "PublicKey", "original", ",", "final", "PublicKey", "substitute", ")", "{", "_mappedPublicKeys", ".", "put", "(", "original", ",", "substitute", ")", ";", "if", "(", "persistImmediately", ")", "{", "persistPublicKeyMap", "(", ")", ";", "}", "}" ]
Stores a public key mapping. @param original @param substitute
[ "Stores", "a", "public", "key", "mapping", "." ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/browsermob-proxy/src/main/java/com/groupon/odo/bmp/KeyStoreManager.java#L935-L939
164,868
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java
ScriptService.getScript
public Script getScript(int id) { PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SCRIPT + " WHERE id = ?" ); statement.setInt(1, id); results = statement.executeQuery(); if (results.next()) { return scriptFromSQLResult(results); } } catch (Exception e) { } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return null; }
java
public Script getScript(int id) { PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SCRIPT + " WHERE id = ?" ); statement.setInt(1, id); results = statement.executeQuery(); if (results.next()) { return scriptFromSQLResult(results); } } catch (Exception e) { } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return null; }
[ "public", "Script", "getScript", "(", "int", "id", ")", "{", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "SQLService", ".", "getInstance", "(", ")", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SCRIPT", "+", "\" WHERE id = ?\"", ")", ";", "statement", ".", "setInt", "(", "1", ",", "id", ")", ";", "results", "=", "statement", ".", "executeQuery", "(", ")", ";", "if", "(", "results", ".", "next", "(", ")", ")", "{", "return", "scriptFromSQLResult", "(", "results", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "null", ";", "}" ]
Get the script for a given ID @param id ID of script @return Script if found, otherwise null
[ "Get", "the", "script", "for", "a", "given", "ID" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java#L65-L97
164,869
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java
ScriptService.getScripts
public Script[] getScripts(Integer type) { ArrayList<Script> returnData = new ArrayList<>(); PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement("SELECT * FROM " + Constants.DB_TABLE_SCRIPT + " ORDER BY " + Constants.GENERIC_ID); if (type != null) { statement = sqlConnection.prepareStatement("SELECT * FROM " + Constants.DB_TABLE_SCRIPT + " WHERE " + Constants.SCRIPT_TYPE + "= ?" + " ORDER BY " + Constants.GENERIC_ID); statement.setInt(1, type); } logger.info("Query: {}", statement); results = statement.executeQuery(); while (results.next()) { returnData.add(scriptFromSQLResult(results)); } } catch (Exception e) { } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return returnData.toArray(new Script[0]); }
java
public Script[] getScripts(Integer type) { ArrayList<Script> returnData = new ArrayList<>(); PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement("SELECT * FROM " + Constants.DB_TABLE_SCRIPT + " ORDER BY " + Constants.GENERIC_ID); if (type != null) { statement = sqlConnection.prepareStatement("SELECT * FROM " + Constants.DB_TABLE_SCRIPT + " WHERE " + Constants.SCRIPT_TYPE + "= ?" + " ORDER BY " + Constants.GENERIC_ID); statement.setInt(1, type); } logger.info("Query: {}", statement); results = statement.executeQuery(); while (results.next()) { returnData.add(scriptFromSQLResult(results)); } } catch (Exception e) { } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return returnData.toArray(new Script[0]); }
[ "public", "Script", "[", "]", "getScripts", "(", "Integer", "type", ")", "{", "ArrayList", "<", "Script", ">", "returnData", "=", "new", "ArrayList", "<>", "(", ")", ";", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "SQLService", ".", "getInstance", "(", ")", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SCRIPT", "+", "\" ORDER BY \"", "+", "Constants", ".", "GENERIC_ID", ")", ";", "if", "(", "type", "!=", "null", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SCRIPT", "+", "\" WHERE \"", "+", "Constants", ".", "SCRIPT_TYPE", "+", "\"= ?\"", "+", "\" ORDER BY \"", "+", "Constants", ".", "GENERIC_ID", ")", ";", "statement", ".", "setInt", "(", "1", ",", "type", ")", ";", "}", "logger", ".", "info", "(", "\"Query: {}\"", ",", "statement", ")", ";", "results", "=", "statement", ".", "executeQuery", "(", ")", ";", "while", "(", "results", ".", "next", "(", ")", ")", "{", "returnData", ".", "add", "(", "scriptFromSQLResult", "(", "results", ")", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "returnData", ".", "toArray", "(", "new", "Script", "[", "0", "]", ")", ";", "}" ]
Return all scripts of a given type @param type integer value of type @return Array of scripts of the given type
[ "Return", "all", "scripts", "of", "a", "given", "type" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java#L114-L154
164,870
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java
ScriptService.updateName
public Script updateName(int id, String name) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_SCRIPT + " SET " + Constants.SCRIPT_NAME + " = ? " + " WHERE " + Constants.GENERIC_ID + " = ?" ); statement.setString(1, name); statement.setInt(2, id); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return this.getScript(id); }
java
public Script updateName(int id, String name) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_SCRIPT + " SET " + Constants.SCRIPT_NAME + " = ? " + " WHERE " + Constants.GENERIC_ID + " = ?" ); statement.setString(1, name); statement.setInt(2, id); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return this.getScript(id); }
[ "public", "Script", "updateName", "(", "int", "id", ",", "String", "name", ")", "throws", "Exception", "{", "PreparedStatement", "statement", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "SQLService", ".", "getInstance", "(", ")", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"UPDATE \"", "+", "Constants", ".", "DB_TABLE_SCRIPT", "+", "\" SET \"", "+", "Constants", ".", "SCRIPT_NAME", "+", "\" = ? \"", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_ID", "+", "\" = ?\"", ")", ";", "statement", ".", "setString", "(", "1", ",", "name", ")", ";", "statement", ".", "setInt", "(", "2", ",", "id", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "this", ".", "getScript", "(", "id", ")", ";", "}" ]
Update the name of a script @param id ID of script @param name new name @return updated script @throws Exception exception
[ "Update", "the", "name", "of", "a", "script" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java#L218-L242
164,871
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java
ScriptService.removeScript
public void removeScript(int id) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement( "DELETE FROM " + Constants.DB_TABLE_SCRIPT + " WHERE " + Constants.GENERIC_ID + " = ?" ); statement.setInt(1, id); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } }
java
public void removeScript(int id) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = SQLService.getInstance().getConnection()) { statement = sqlConnection.prepareStatement( "DELETE FROM " + Constants.DB_TABLE_SCRIPT + " WHERE " + Constants.GENERIC_ID + " = ?" ); statement.setInt(1, id); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } }
[ "public", "void", "removeScript", "(", "int", "id", ")", "throws", "Exception", "{", "PreparedStatement", "statement", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "SQLService", ".", "getInstance", "(", ")", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"DELETE FROM \"", "+", "Constants", ".", "DB_TABLE_SCRIPT", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_ID", "+", "\" = ?\"", ")", ";", "statement", ".", "setInt", "(", "1", ",", "id", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}" ]
Remove script for a given ID @param id ID of script @throws Exception exception
[ "Remove", "script", "for", "a", "given", "ID" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ScriptService.java#L284-L304
164,872
groupon/odo
proxyserver/src/main/java/com/groupon/odo/RemoveHeaderFilter.java
RemoveHeaderFilter.doFilter
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final ServletRequest r1 = request; chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) { @SuppressWarnings("unchecked") public void setHeader(String name, String value) { ArrayList<String> headersToRemove = new ArrayList<String>(); if (r1.getAttribute("com.groupon.odo.removeHeaders") != null) headersToRemove = (ArrayList<String>) r1.getAttribute("com.groupon.odo.removeHeaders"); boolean removeHeader = false; // need to loop through removeHeaders to make things case insensitive for (String headerToRemove : headersToRemove) { if (headerToRemove.toLowerCase().equals(name.toLowerCase())) { removeHeader = true; break; } } if (! removeHeader) { super.setHeader(name, value); } } }); }
java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final ServletRequest r1 = request; chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) { @SuppressWarnings("unchecked") public void setHeader(String name, String value) { ArrayList<String> headersToRemove = new ArrayList<String>(); if (r1.getAttribute("com.groupon.odo.removeHeaders") != null) headersToRemove = (ArrayList<String>) r1.getAttribute("com.groupon.odo.removeHeaders"); boolean removeHeader = false; // need to loop through removeHeaders to make things case insensitive for (String headerToRemove : headersToRemove) { if (headerToRemove.toLowerCase().equals(name.toLowerCase())) { removeHeader = true; break; } } if (! removeHeader) { super.setHeader(name, value); } } }); }
[ "@", "Override", "public", "void", "doFilter", "(", "ServletRequest", "request", ",", "ServletResponse", "response", ",", "FilterChain", "chain", ")", "throws", "IOException", ",", "ServletException", "{", "final", "ServletRequest", "r1", "=", "request", ";", "chain", ".", "doFilter", "(", "request", ",", "new", "HttpServletResponseWrapper", "(", "(", "HttpServletResponse", ")", "response", ")", "{", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "void", "setHeader", "(", "String", "name", ",", "String", "value", ")", "{", "ArrayList", "<", "String", ">", "headersToRemove", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "if", "(", "r1", ".", "getAttribute", "(", "\"com.groupon.odo.removeHeaders\"", ")", "!=", "null", ")", "headersToRemove", "=", "(", "ArrayList", "<", "String", ">", ")", "r1", ".", "getAttribute", "(", "\"com.groupon.odo.removeHeaders\"", ")", ";", "boolean", "removeHeader", "=", "false", ";", "// need to loop through removeHeaders to make things case insensitive", "for", "(", "String", "headerToRemove", ":", "headersToRemove", ")", "{", "if", "(", "headerToRemove", ".", "toLowerCase", "(", ")", ".", "equals", "(", "name", ".", "toLowerCase", "(", ")", ")", ")", "{", "removeHeader", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "removeHeader", ")", "{", "super", ".", "setHeader", "(", "name", ",", "value", ")", ";", "}", "}", "}", ")", ";", "}" ]
This looks at the servlet attributes to get the list of response headers to remove while the response object gets created by the servlet
[ "This", "looks", "at", "the", "servlet", "attributes", "to", "get", "the", "list", "of", "response", "headers", "to", "remove", "while", "the", "response", "object", "gets", "created", "by", "the", "servlet" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyserver/src/main/java/com/groupon/odo/RemoveHeaderFilter.java#L28-L53
164,873
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java
Utils.arrayFromStringOfIntegers
public static int[] arrayFromStringOfIntegers(String str) throws IllegalArgumentException { StringTokenizer tokenizer = new StringTokenizer(str, ","); int n = tokenizer.countTokens(); int[] list = new int[n]; for (int i = 0; i < n; i++) { String token = tokenizer.nextToken(); list[i] = Integer.parseInt(token); } return list; }
java
public static int[] arrayFromStringOfIntegers(String str) throws IllegalArgumentException { StringTokenizer tokenizer = new StringTokenizer(str, ","); int n = tokenizer.countTokens(); int[] list = new int[n]; for (int i = 0; i < n; i++) { String token = tokenizer.nextToken(); list[i] = Integer.parseInt(token); } return list; }
[ "public", "static", "int", "[", "]", "arrayFromStringOfIntegers", "(", "String", "str", ")", "throws", "IllegalArgumentException", "{", "StringTokenizer", "tokenizer", "=", "new", "StringTokenizer", "(", "str", ",", "\",\"", ")", ";", "int", "n", "=", "tokenizer", ".", "countTokens", "(", ")", ";", "int", "[", "]", "list", "=", "new", "int", "[", "n", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "String", "token", "=", "tokenizer", ".", "nextToken", "(", ")", ";", "list", "[", "i", "]", "=", "Integer", ".", "parseInt", "(", "token", ")", ";", "}", "return", "list", ";", "}" ]
Split string of comma-delimited ints into an a int array @param str @return @throws IllegalArgumentException
[ "Split", "string", "of", "comma", "-", "delimited", "ints", "into", "an", "a", "int", "array" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java#L44-L53
164,874
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java
Utils.copyResourceToLocalFile
public static File copyResourceToLocalFile(String sourceResource, String destFileName) throws Exception { try { Resource keystoreFile = new ClassPathResource(sourceResource); InputStream in = keystoreFile.getInputStream(); File outKeyStoreFile = new File(destFileName); FileOutputStream fop = new FileOutputStream(outKeyStoreFile); byte[] buf = new byte[512]; int num; while ((num = in.read(buf)) != -1) { fop.write(buf, 0, num); } fop.flush(); fop.close(); in.close(); return outKeyStoreFile; } catch (IOException ioe) { throw new Exception("Could not copy keystore file: " + ioe.getMessage()); } }
java
public static File copyResourceToLocalFile(String sourceResource, String destFileName) throws Exception { try { Resource keystoreFile = new ClassPathResource(sourceResource); InputStream in = keystoreFile.getInputStream(); File outKeyStoreFile = new File(destFileName); FileOutputStream fop = new FileOutputStream(outKeyStoreFile); byte[] buf = new byte[512]; int num; while ((num = in.read(buf)) != -1) { fop.write(buf, 0, num); } fop.flush(); fop.close(); in.close(); return outKeyStoreFile; } catch (IOException ioe) { throw new Exception("Could not copy keystore file: " + ioe.getMessage()); } }
[ "public", "static", "File", "copyResourceToLocalFile", "(", "String", "sourceResource", ",", "String", "destFileName", ")", "throws", "Exception", "{", "try", "{", "Resource", "keystoreFile", "=", "new", "ClassPathResource", "(", "sourceResource", ")", ";", "InputStream", "in", "=", "keystoreFile", ".", "getInputStream", "(", ")", ";", "File", "outKeyStoreFile", "=", "new", "File", "(", "destFileName", ")", ";", "FileOutputStream", "fop", "=", "new", "FileOutputStream", "(", "outKeyStoreFile", ")", ";", "byte", "[", "]", "buf", "=", "new", "byte", "[", "512", "]", ";", "int", "num", ";", "while", "(", "(", "num", "=", "in", ".", "read", "(", "buf", ")", ")", "!=", "-", "1", ")", "{", "fop", ".", "write", "(", "buf", ",", "0", ",", "num", ")", ";", "}", "fop", ".", "flush", "(", ")", ";", "fop", ".", "close", "(", ")", ";", "in", ".", "close", "(", ")", ";", "return", "outKeyStoreFile", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "Exception", "(", "\"Could not copy keystore file: \"", "+", "ioe", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Copies file from a resource to a local temp file @param sourceResource @return Absolute filename of the temp file @throws Exception
[ "Copies", "file", "from", "a", "resource", "to", "a", "local", "temp", "file" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java#L100-L119
164,875
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java
Utils.getSystemPort
public static int getSystemPort(String portIdentifier) { int defaultPort = 0; if (portIdentifier.compareTo(Constants.SYS_API_PORT) == 0) { defaultPort = Constants.DEFAULT_API_PORT; } else if (portIdentifier.compareTo(Constants.SYS_DB_PORT) == 0) { defaultPort = Constants.DEFAULT_DB_PORT; } else if (portIdentifier.compareTo(Constants.SYS_FWD_PORT) == 0) { defaultPort = Constants.DEFAULT_FWD_PORT; } else if (portIdentifier.compareTo(Constants.SYS_HTTP_PORT) == 0) { defaultPort = Constants.DEFAULT_HTTP_PORT; } else if (portIdentifier.compareTo(Constants.SYS_HTTPS_PORT) == 0) { defaultPort = Constants.DEFAULT_HTTPS_PORT; } else { return defaultPort; } String portStr = System.getenv(portIdentifier); return (portStr == null || portStr.isEmpty()) ? defaultPort : Integer.valueOf(portStr); }
java
public static int getSystemPort(String portIdentifier) { int defaultPort = 0; if (portIdentifier.compareTo(Constants.SYS_API_PORT) == 0) { defaultPort = Constants.DEFAULT_API_PORT; } else if (portIdentifier.compareTo(Constants.SYS_DB_PORT) == 0) { defaultPort = Constants.DEFAULT_DB_PORT; } else if (portIdentifier.compareTo(Constants.SYS_FWD_PORT) == 0) { defaultPort = Constants.DEFAULT_FWD_PORT; } else if (portIdentifier.compareTo(Constants.SYS_HTTP_PORT) == 0) { defaultPort = Constants.DEFAULT_HTTP_PORT; } else if (portIdentifier.compareTo(Constants.SYS_HTTPS_PORT) == 0) { defaultPort = Constants.DEFAULT_HTTPS_PORT; } else { return defaultPort; } String portStr = System.getenv(portIdentifier); return (portStr == null || portStr.isEmpty()) ? defaultPort : Integer.valueOf(portStr); }
[ "public", "static", "int", "getSystemPort", "(", "String", "portIdentifier", ")", "{", "int", "defaultPort", "=", "0", ";", "if", "(", "portIdentifier", ".", "compareTo", "(", "Constants", ".", "SYS_API_PORT", ")", "==", "0", ")", "{", "defaultPort", "=", "Constants", ".", "DEFAULT_API_PORT", ";", "}", "else", "if", "(", "portIdentifier", ".", "compareTo", "(", "Constants", ".", "SYS_DB_PORT", ")", "==", "0", ")", "{", "defaultPort", "=", "Constants", ".", "DEFAULT_DB_PORT", ";", "}", "else", "if", "(", "portIdentifier", ".", "compareTo", "(", "Constants", ".", "SYS_FWD_PORT", ")", "==", "0", ")", "{", "defaultPort", "=", "Constants", ".", "DEFAULT_FWD_PORT", ";", "}", "else", "if", "(", "portIdentifier", ".", "compareTo", "(", "Constants", ".", "SYS_HTTP_PORT", ")", "==", "0", ")", "{", "defaultPort", "=", "Constants", ".", "DEFAULT_HTTP_PORT", ";", "}", "else", "if", "(", "portIdentifier", ".", "compareTo", "(", "Constants", ".", "SYS_HTTPS_PORT", ")", "==", "0", ")", "{", "defaultPort", "=", "Constants", ".", "DEFAULT_HTTPS_PORT", ";", "}", "else", "{", "return", "defaultPort", ";", "}", "String", "portStr", "=", "System", ".", "getenv", "(", "portIdentifier", ")", ";", "return", "(", "portStr", "==", "null", "||", "portStr", ".", "isEmpty", "(", ")", ")", "?", "defaultPort", ":", "Integer", ".", "valueOf", "(", "portStr", ")", ";", "}" ]
Returns the port as configured by the system variables, fallback is the default port value @param portIdentifier - SYS_*_PORT defined in Constants @return
[ "Returns", "the", "port", "as", "configured", "by", "the", "system", "variables", "fallback", "is", "the", "default", "port", "value" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java#L127-L146
164,876
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java
Utils.getPublicIPAddress
public static String getPublicIPAddress() throws Exception { final String IPV4_REGEX = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z"; String ipAddr = null; Enumeration e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); // Pick the first non loop back address if ((!i.isLoopbackAddress() && i.isSiteLocalAddress()) || i.getHostAddress().matches(IPV4_REGEX)) { ipAddr = i.getHostAddress(); break; } } if (ipAddr != null) { break; } } return ipAddr; }
java
public static String getPublicIPAddress() throws Exception { final String IPV4_REGEX = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z"; String ipAddr = null; Enumeration e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); // Pick the first non loop back address if ((!i.isLoopbackAddress() && i.isSiteLocalAddress()) || i.getHostAddress().matches(IPV4_REGEX)) { ipAddr = i.getHostAddress(); break; } } if (ipAddr != null) { break; } } return ipAddr; }
[ "public", "static", "String", "getPublicIPAddress", "(", ")", "throws", "Exception", "{", "final", "String", "IPV4_REGEX", "=", "\"\\\\A(25[0-5]|2[0-4]\\\\d|[0-1]?\\\\d?\\\\d)(\\\\.(25[0-5]|2[0-4]\\\\d|[0-1]?\\\\d?\\\\d)){3}\\\\z\"", ";", "String", "ipAddr", "=", "null", ";", "Enumeration", "e", "=", "NetworkInterface", ".", "getNetworkInterfaces", "(", ")", ";", "while", "(", "e", ".", "hasMoreElements", "(", ")", ")", "{", "NetworkInterface", "n", "=", "(", "NetworkInterface", ")", "e", ".", "nextElement", "(", ")", ";", "Enumeration", "ee", "=", "n", ".", "getInetAddresses", "(", ")", ";", "while", "(", "ee", ".", "hasMoreElements", "(", ")", ")", "{", "InetAddress", "i", "=", "(", "InetAddress", ")", "ee", ".", "nextElement", "(", ")", ";", "// Pick the first non loop back address", "if", "(", "(", "!", "i", ".", "isLoopbackAddress", "(", ")", "&&", "i", ".", "isSiteLocalAddress", "(", ")", ")", "||", "i", ".", "getHostAddress", "(", ")", ".", "matches", "(", "IPV4_REGEX", ")", ")", "{", "ipAddr", "=", "i", ".", "getHostAddress", "(", ")", ";", "break", ";", "}", "}", "if", "(", "ipAddr", "!=", "null", ")", "{", "break", ";", "}", "}", "return", "ipAddr", ";", "}" ]
This function returns the first external IP address encountered @return IP address or null @throws Exception
[ "This", "function", "returns", "the", "first", "external", "IP", "address", "encountered" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/Utils.java#L163-L187
164,877
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ConfigurationService.java
ConfigurationService.getConfiguration
public Configuration getConfiguration(String name) { Configuration[] values = getConfigurations(name); if (values == null) { return null; } return values[0]; }
java
public Configuration getConfiguration(String name) { Configuration[] values = getConfigurations(name); if (values == null) { return null; } return values[0]; }
[ "public", "Configuration", "getConfiguration", "(", "String", "name", ")", "{", "Configuration", "[", "]", "values", "=", "getConfigurations", "(", "name", ")", ";", "if", "(", "values", "==", "null", ")", "{", "return", "null", ";", "}", "return", "values", "[", "0", "]", ";", "}" ]
Get the value for a particular configuration property @param name - name of the property @return The first value encountered or null
[ "Get", "the", "value", "for", "a", "particular", "configuration", "property" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ConfigurationService.java#L70-L78
164,878
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ConfigurationService.java
ConfigurationService.getConfigurations
public Configuration[] getConfigurations(String name) { ArrayList<Configuration> valuesList = new ArrayList<Configuration>(); logger.info("Getting data for {}", name); PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { String queryString = "SELECT * FROM " + Constants.DB_TABLE_CONFIGURATION; if (name != null) { queryString += " WHERE " + Constants.DB_TABLE_CONFIGURATION_NAME + "=?"; } statement = sqlConnection.prepareStatement(queryString); if (name != null) { statement.setString(1, name); } results = statement.executeQuery(); while (results.next()) { Configuration config = new Configuration(); config.setValue(results.getString(Constants.DB_TABLE_CONFIGURATION_VALUE)); config.setKey(results.getString(Constants.DB_TABLE_CONFIGURATION_NAME)); config.setId(results.getInt(Constants.GENERIC_ID)); logger.info("the configValue is = {}", config.getValue()); valuesList.add(config); } } catch (SQLException sqe) { logger.info("Exception in sql"); sqe.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } if (valuesList.size() == 0) { return null; } return valuesList.toArray(new Configuration[0]); }
java
public Configuration[] getConfigurations(String name) { ArrayList<Configuration> valuesList = new ArrayList<Configuration>(); logger.info("Getting data for {}", name); PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { String queryString = "SELECT * FROM " + Constants.DB_TABLE_CONFIGURATION; if (name != null) { queryString += " WHERE " + Constants.DB_TABLE_CONFIGURATION_NAME + "=?"; } statement = sqlConnection.prepareStatement(queryString); if (name != null) { statement.setString(1, name); } results = statement.executeQuery(); while (results.next()) { Configuration config = new Configuration(); config.setValue(results.getString(Constants.DB_TABLE_CONFIGURATION_VALUE)); config.setKey(results.getString(Constants.DB_TABLE_CONFIGURATION_NAME)); config.setId(results.getInt(Constants.GENERIC_ID)); logger.info("the configValue is = {}", config.getValue()); valuesList.add(config); } } catch (SQLException sqe) { logger.info("Exception in sql"); sqe.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } if (valuesList.size() == 0) { return null; } return valuesList.toArray(new Configuration[0]); }
[ "public", "Configuration", "[", "]", "getConfigurations", "(", "String", "name", ")", "{", "ArrayList", "<", "Configuration", ">", "valuesList", "=", "new", "ArrayList", "<", "Configuration", ">", "(", ")", ";", "logger", ".", "info", "(", "\"Getting data for {}\"", ",", "name", ")", ";", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "String", "queryString", "=", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION", ";", "if", "(", "name", "!=", "null", ")", "{", "queryString", "+=", "\" WHERE \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_NAME", "+", "\"=?\"", ";", "}", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "queryString", ")", ";", "if", "(", "name", "!=", "null", ")", "{", "statement", ".", "setString", "(", "1", ",", "name", ")", ";", "}", "results", "=", "statement", ".", "executeQuery", "(", ")", ";", "while", "(", "results", ".", "next", "(", ")", ")", "{", "Configuration", "config", "=", "new", "Configuration", "(", ")", ";", "config", ".", "setValue", "(", "results", ".", "getString", "(", "Constants", ".", "DB_TABLE_CONFIGURATION_VALUE", ")", ")", ";", "config", ".", "setKey", "(", "results", ".", "getString", "(", "Constants", ".", "DB_TABLE_CONFIGURATION_NAME", ")", ")", ";", "config", ".", "setId", "(", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_ID", ")", ")", ";", "logger", ".", "info", "(", "\"the configValue is = {}\"", ",", "config", ".", "getValue", "(", ")", ")", ";", "valuesList", ".", "add", "(", "config", ")", ";", "}", "}", "catch", "(", "SQLException", "sqe", ")", "{", "logger", ".", "info", "(", "\"Exception in sql\"", ")", ";", "sqe", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "if", "(", "valuesList", ".", "size", "(", ")", "==", "0", ")", "{", "return", "null", ";", "}", "return", "valuesList", ".", "toArray", "(", "new", "Configuration", "[", "0", "]", ")", ";", "}" ]
Get the values for a particular configuration property @param name - name of the property @return All values encountered or null
[ "Get", "the", "values", "for", "a", "particular", "configuration", "property" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ConfigurationService.java#L86-L138
164,879
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/EditController.java
EditController.disableAll
@RequestMapping(value = "api/edit/disableAll", method = RequestMethod.POST) public @ResponseBody String disableAll(Model model, int profileID, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) { editService.disableAll(profileID, clientUUID); return null; }
java
@RequestMapping(value = "api/edit/disableAll", method = RequestMethod.POST) public @ResponseBody String disableAll(Model model, int profileID, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) { editService.disableAll(profileID, clientUUID); return null; }
[ "@", "RequestMapping", "(", "value", "=", "\"api/edit/disableAll\"", ",", "method", "=", "RequestMethod", ".", "POST", ")", "public", "@", "ResponseBody", "String", "disableAll", "(", "Model", "model", ",", "int", "profileID", ",", "@", "RequestParam", "(", "defaultValue", "=", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ")", "String", "clientUUID", ")", "{", "editService", ".", "disableAll", "(", "profileID", ",", "clientUUID", ")", ";", "return", "null", ";", "}" ]
Disables all the overrides for a specific profile @param model @param profileID @param clientUUID @return
[ "Disables", "all", "the", "overrides", "for", "a", "specific", "profile" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/EditController.java#L74-L81
164,880
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/EditController.java
EditController.updateRepeatNumber
@RequestMapping(value = "api/edit/repeatNumber", method = RequestMethod.POST) public @ResponseBody String updateRepeatNumber(Model model, int newNum, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception { logger.info("want to update repeat number of path_id={}, to newNum={}", path_id, newNum); editService.updateRepeatNumber(newNum, path_id, clientUUID); return null; }
java
@RequestMapping(value = "api/edit/repeatNumber", method = RequestMethod.POST) public @ResponseBody String updateRepeatNumber(Model model, int newNum, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception { logger.info("want to update repeat number of path_id={}, to newNum={}", path_id, newNum); editService.updateRepeatNumber(newNum, path_id, clientUUID); return null; }
[ "@", "RequestMapping", "(", "value", "=", "\"api/edit/repeatNumber\"", ",", "method", "=", "RequestMethod", ".", "POST", ")", "public", "@", "ResponseBody", "String", "updateRepeatNumber", "(", "Model", "model", ",", "int", "newNum", ",", "int", "path_id", ",", "@", "RequestParam", "(", "defaultValue", "=", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ")", "String", "clientUUID", ")", "throws", "Exception", "{", "logger", ".", "info", "(", "\"want to update repeat number of path_id={}, to newNum={}\"", ",", "path_id", ",", "newNum", ")", ";", "editService", ".", "updateRepeatNumber", "(", "newNum", ",", "path_id", ",", "clientUUID", ")", ";", "return", "null", ";", "}" ]
Calls a method from editService to update the repeat number for a path @param model @param newNum @param path_id @param clientUUID @return @throws Exception
[ "Calls", "a", "method", "from", "editService", "to", "update", "the", "repeat", "number", "for", "a", "path" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/EditController.java#L110-L118
164,881
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/EditController.java
EditController.enableCustomResponse
@RequestMapping(value = "api/edit/enable/custom", method = RequestMethod.POST) public @ResponseBody String enableCustomResponse(Model model, String custom, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception { if (custom.equals("undefined")) return null; editService.enableCustomResponse(custom, path_id, clientUUID); return null; }
java
@RequestMapping(value = "api/edit/enable/custom", method = RequestMethod.POST) public @ResponseBody String enableCustomResponse(Model model, String custom, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception { if (custom.equals("undefined")) return null; editService.enableCustomResponse(custom, path_id, clientUUID); return null; }
[ "@", "RequestMapping", "(", "value", "=", "\"api/edit/enable/custom\"", ",", "method", "=", "RequestMethod", ".", "POST", ")", "public", "@", "ResponseBody", "String", "enableCustomResponse", "(", "Model", "model", ",", "String", "custom", ",", "int", "path_id", ",", "@", "RequestParam", "(", "defaultValue", "=", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ")", "String", "clientUUID", ")", "throws", "Exception", "{", "if", "(", "custom", ".", "equals", "(", "\"undefined\"", ")", ")", "return", "null", ";", "editService", ".", "enableCustomResponse", "(", "custom", ",", "path_id", ",", "clientUUID", ")", ";", "return", "null", ";", "}" ]
Enables a custom response @param model @param custom @param path_id @param clientUUID @return @throws Exception
[ "Enables", "a", "custom", "response" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/EditController.java#L130-L139
164,882
groupon/odo
proxyui/src/main/java/com/groupon/odo/controllers/EditController.java
EditController.disableResponses
@RequestMapping(value = "api/edit/disable", method = RequestMethod.POST) public @ResponseBody String disableResponses(Model model, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception { OverrideService.getInstance().disableAllOverrides(path_id, clientUUID); //TODO also need to disable custom override if there is one of those editService.removeCustomOverride(path_id, clientUUID); return null; }
java
@RequestMapping(value = "api/edit/disable", method = RequestMethod.POST) public @ResponseBody String disableResponses(Model model, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception { OverrideService.getInstance().disableAllOverrides(path_id, clientUUID); //TODO also need to disable custom override if there is one of those editService.removeCustomOverride(path_id, clientUUID); return null; }
[ "@", "RequestMapping", "(", "value", "=", "\"api/edit/disable\"", ",", "method", "=", "RequestMethod", ".", "POST", ")", "public", "@", "ResponseBody", "String", "disableResponses", "(", "Model", "model", ",", "int", "path_id", ",", "@", "RequestParam", "(", "defaultValue", "=", "Constants", ".", "PROFILE_CLIENT_DEFAULT_ID", ")", "String", "clientUUID", ")", "throws", "Exception", "{", "OverrideService", ".", "getInstance", "(", ")", ".", "disableAllOverrides", "(", "path_id", ",", "clientUUID", ")", ";", "//TODO also need to disable custom override if there is one of those", "editService", ".", "removeCustomOverride", "(", "path_id", ",", "clientUUID", ")", ";", "return", "null", ";", "}" ]
disables the responses for a given pathname and user id @param model @param path_id @param clientUUID @return @throws Exception
[ "disables", "the", "responses", "for", "a", "given", "pathname", "and", "user", "id" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/EditController.java#L150-L159
164,883
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.startServer
public void startServer() throws Exception { if (!externalDatabaseHost) { try { this.port = Utils.getSystemPort(Constants.SYS_DB_PORT); server = Server.createTcpServer("-tcpPort", String.valueOf(port), "-tcpAllowOthers").start(); } catch (SQLException e) { if (e.toString().contains("java.net.UnknownHostException")) { logger.error("Startup failure. Potential bug in OSX & Java7. Workaround: add name of local machine to '/etc/hosts.'"); logger.error("Example: 127.0.0.1 MacBook"); throw e; } } } }
java
public void startServer() throws Exception { if (!externalDatabaseHost) { try { this.port = Utils.getSystemPort(Constants.SYS_DB_PORT); server = Server.createTcpServer("-tcpPort", String.valueOf(port), "-tcpAllowOthers").start(); } catch (SQLException e) { if (e.toString().contains("java.net.UnknownHostException")) { logger.error("Startup failure. Potential bug in OSX & Java7. Workaround: add name of local machine to '/etc/hosts.'"); logger.error("Example: 127.0.0.1 MacBook"); throw e; } } } }
[ "public", "void", "startServer", "(", ")", "throws", "Exception", "{", "if", "(", "!", "externalDatabaseHost", ")", "{", "try", "{", "this", ".", "port", "=", "Utils", ".", "getSystemPort", "(", "Constants", ".", "SYS_DB_PORT", ")", ";", "server", "=", "Server", ".", "createTcpServer", "(", "\"-tcpPort\"", ",", "String", ".", "valueOf", "(", "port", ")", ",", "\"-tcpAllowOthers\"", ")", ".", "start", "(", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "if", "(", "e", ".", "toString", "(", ")", ".", "contains", "(", "\"java.net.UnknownHostException\"", ")", ")", "{", "logger", ".", "error", "(", "\"Startup failure. Potential bug in OSX & Java7. Workaround: add name of local machine to '/etc/hosts.'\"", ")", ";", "logger", ".", "error", "(", "\"Example: 127.0.0.1 MacBook\"", ")", ";", "throw", "e", ";", "}", "}", "}", "}" ]
Only meant to be called once @throws Exception exception
[ "Only", "meant", "to", "be", "called", "once" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L64-L77
164,884
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.stopServer
public void stopServer() throws Exception { if (!externalDatabaseHost) { try (Connection sqlConnection = getConnection()) { sqlConnection.prepareStatement("SHUTDOWN").execute(); } catch (Exception e) { } try { server.stop(); } catch (Exception e) { } } }
java
public void stopServer() throws Exception { if (!externalDatabaseHost) { try (Connection sqlConnection = getConnection()) { sqlConnection.prepareStatement("SHUTDOWN").execute(); } catch (Exception e) { } try { server.stop(); } catch (Exception e) { } } }
[ "public", "void", "stopServer", "(", ")", "throws", "Exception", "{", "if", "(", "!", "externalDatabaseHost", ")", "{", "try", "(", "Connection", "sqlConnection", "=", "getConnection", "(", ")", ")", "{", "sqlConnection", ".", "prepareStatement", "(", "\"SHUTDOWN\"", ")", ".", "execute", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "server", ".", "stop", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}" ]
Shutdown the server @throws Exception exception
[ "Shutdown", "the", "server" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L84-L96
164,885
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.getInstance
public static SQLService getInstance() throws Exception { if (_instance == null) { _instance = new SQLService(); _instance.startServer(); // default pool size is 20 // can be overriden by env variable int dbPool = 20; if (Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE) != null) { dbPool = Integer.valueOf(Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE)); } // initialize connection pool PoolProperties p = new PoolProperties(); String connectString = "jdbc:h2:tcp://" + _instance.databaseHost + ":" + String.valueOf(_instance.port) + "/" + _instance.databaseName + "/proxydb;MULTI_THREADED=true;AUTO_RECONNECT=TRUE;AUTOCOMMIT=ON"; p.setUrl(connectString); p.setDriverClassName("org.h2.Driver"); p.setUsername("sa"); p.setJmxEnabled(true); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setValidationQuery("SELECT 1"); p.setTestOnReturn(false); p.setValidationInterval(5000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(dbPool); p.setInitialSize(5); p.setMaxWait(30000); p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMinIdle(10); p.setLogAbandoned(true); p.setRemoveAbandoned(true); _instance.datasource = new DataSource(); _instance.datasource.setPoolProperties(p); } return _instance; }
java
public static SQLService getInstance() throws Exception { if (_instance == null) { _instance = new SQLService(); _instance.startServer(); // default pool size is 20 // can be overriden by env variable int dbPool = 20; if (Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE) != null) { dbPool = Integer.valueOf(Utils.getEnvironmentOptionValue(Constants.SYS_DATABASE_POOL_SIZE)); } // initialize connection pool PoolProperties p = new PoolProperties(); String connectString = "jdbc:h2:tcp://" + _instance.databaseHost + ":" + String.valueOf(_instance.port) + "/" + _instance.databaseName + "/proxydb;MULTI_THREADED=true;AUTO_RECONNECT=TRUE;AUTOCOMMIT=ON"; p.setUrl(connectString); p.setDriverClassName("org.h2.Driver"); p.setUsername("sa"); p.setJmxEnabled(true); p.setTestWhileIdle(false); p.setTestOnBorrow(true); p.setValidationQuery("SELECT 1"); p.setTestOnReturn(false); p.setValidationInterval(5000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(dbPool); p.setInitialSize(5); p.setMaxWait(30000); p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMinIdle(10); p.setLogAbandoned(true); p.setRemoveAbandoned(true); _instance.datasource = new DataSource(); _instance.datasource.setPoolProperties(p); } return _instance; }
[ "public", "static", "SQLService", "getInstance", "(", ")", "throws", "Exception", "{", "if", "(", "_instance", "==", "null", ")", "{", "_instance", "=", "new", "SQLService", "(", ")", ";", "_instance", ".", "startServer", "(", ")", ";", "// default pool size is 20", "// can be overriden by env variable", "int", "dbPool", "=", "20", ";", "if", "(", "Utils", ".", "getEnvironmentOptionValue", "(", "Constants", ".", "SYS_DATABASE_POOL_SIZE", ")", "!=", "null", ")", "{", "dbPool", "=", "Integer", ".", "valueOf", "(", "Utils", ".", "getEnvironmentOptionValue", "(", "Constants", ".", "SYS_DATABASE_POOL_SIZE", ")", ")", ";", "}", "// initialize connection pool", "PoolProperties", "p", "=", "new", "PoolProperties", "(", ")", ";", "String", "connectString", "=", "\"jdbc:h2:tcp://\"", "+", "_instance", ".", "databaseHost", "+", "\":\"", "+", "String", ".", "valueOf", "(", "_instance", ".", "port", ")", "+", "\"/\"", "+", "_instance", ".", "databaseName", "+", "\"/proxydb;MULTI_THREADED=true;AUTO_RECONNECT=TRUE;AUTOCOMMIT=ON\"", ";", "p", ".", "setUrl", "(", "connectString", ")", ";", "p", ".", "setDriverClassName", "(", "\"org.h2.Driver\"", ")", ";", "p", ".", "setUsername", "(", "\"sa\"", ")", ";", "p", ".", "setJmxEnabled", "(", "true", ")", ";", "p", ".", "setTestWhileIdle", "(", "false", ")", ";", "p", ".", "setTestOnBorrow", "(", "true", ")", ";", "p", ".", "setValidationQuery", "(", "\"SELECT 1\"", ")", ";", "p", ".", "setTestOnReturn", "(", "false", ")", ";", "p", ".", "setValidationInterval", "(", "5000", ")", ";", "p", ".", "setTimeBetweenEvictionRunsMillis", "(", "30000", ")", ";", "p", ".", "setMaxActive", "(", "dbPool", ")", ";", "p", ".", "setInitialSize", "(", "5", ")", ";", "p", ".", "setMaxWait", "(", "30000", ")", ";", "p", ".", "setRemoveAbandonedTimeout", "(", "60", ")", ";", "p", ".", "setMinEvictableIdleTimeMillis", "(", "30000", ")", ";", "p", ".", "setMinIdle", "(", "10", ")", ";", "p", ".", "setLogAbandoned", "(", "true", ")", ";", "p", ".", "setRemoveAbandoned", "(", "true", ")", ";", "_instance", ".", "datasource", "=", "new", "DataSource", "(", ")", ";", "_instance", ".", "datasource", ".", "setPoolProperties", "(", "p", ")", ";", "}", "return", "_instance", ";", "}" ]
Obtain instance of the SQL Service @return instance of SQLService @throws Exception exception
[ "Obtain", "instance", "of", "the", "SQL", "Service" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L104-L142
164,886
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.updateSchema
public void updateSchema(String migrationPath) { try { logger.info("Updating schema... "); int current_version = 0; // first check the current schema version HashMap<String, Object> configuration = getFirstResult("SELECT * FROM " + Constants.DB_TABLE_CONFIGURATION + " WHERE " + Constants.DB_TABLE_CONFIGURATION_NAME + " = \'" + Constants.DB_TABLE_CONFIGURATION_DATABASE_VERSION + "\'"); if (configuration == null) { logger.info("Creating configuration table.."); // create configuration table executeUpdate("CREATE TABLE " + Constants.DB_TABLE_CONFIGURATION + " (" + Constants.GENERIC_ID + " INTEGER IDENTITY," + Constants.DB_TABLE_CONFIGURATION_NAME + " VARCHAR(256)," + Constants.DB_TABLE_CONFIGURATION_VALUE + " VARCHAR(1024));"); executeUpdate("INSERT INTO " + Constants.DB_TABLE_CONFIGURATION + "(" + Constants.DB_TABLE_CONFIGURATION_NAME + "," + Constants.DB_TABLE_CONFIGURATION_VALUE + ")" + " VALUES (\'" + Constants.DB_TABLE_CONFIGURATION_DATABASE_VERSION + "\', '0');"); } else { logger.info("Getting current schema version.."); // get current version current_version = new Integer(configuration.get("VALUE").toString()); logger.info("Current schema version is {}", current_version); } // loop through until we get up to the right schema version while (current_version < Constants.DB_CURRENT_SCHEMA_VERSION) { current_version++; // look for a schema file for this version logger.info("Updating to schema version {}", current_version); String currentFile = migrationPath + "/schema." + current_version; Resource migFile = new ClassPathResource(currentFile); BufferedReader in = new BufferedReader(new InputStreamReader( migFile.getInputStream())); String str; while ((str = in.readLine()) != null) { // execute each line if (str.length() > 0) { executeUpdate(str); } } in.close(); } // update the configuration table with the correct version executeUpdate("UPDATE " + Constants.DB_TABLE_CONFIGURATION + " SET " + Constants.DB_TABLE_CONFIGURATION_VALUE + "='" + current_version + "' WHERE " + Constants.DB_TABLE_CONFIGURATION_NAME + "='" + Constants.DB_TABLE_CONFIGURATION_DATABASE_VERSION + "';"); } catch (Exception e) { logger.info("Error in executeUpdate"); e.printStackTrace(); } }
java
public void updateSchema(String migrationPath) { try { logger.info("Updating schema... "); int current_version = 0; // first check the current schema version HashMap<String, Object> configuration = getFirstResult("SELECT * FROM " + Constants.DB_TABLE_CONFIGURATION + " WHERE " + Constants.DB_TABLE_CONFIGURATION_NAME + " = \'" + Constants.DB_TABLE_CONFIGURATION_DATABASE_VERSION + "\'"); if (configuration == null) { logger.info("Creating configuration table.."); // create configuration table executeUpdate("CREATE TABLE " + Constants.DB_TABLE_CONFIGURATION + " (" + Constants.GENERIC_ID + " INTEGER IDENTITY," + Constants.DB_TABLE_CONFIGURATION_NAME + " VARCHAR(256)," + Constants.DB_TABLE_CONFIGURATION_VALUE + " VARCHAR(1024));"); executeUpdate("INSERT INTO " + Constants.DB_TABLE_CONFIGURATION + "(" + Constants.DB_TABLE_CONFIGURATION_NAME + "," + Constants.DB_TABLE_CONFIGURATION_VALUE + ")" + " VALUES (\'" + Constants.DB_TABLE_CONFIGURATION_DATABASE_VERSION + "\', '0');"); } else { logger.info("Getting current schema version.."); // get current version current_version = new Integer(configuration.get("VALUE").toString()); logger.info("Current schema version is {}", current_version); } // loop through until we get up to the right schema version while (current_version < Constants.DB_CURRENT_SCHEMA_VERSION) { current_version++; // look for a schema file for this version logger.info("Updating to schema version {}", current_version); String currentFile = migrationPath + "/schema." + current_version; Resource migFile = new ClassPathResource(currentFile); BufferedReader in = new BufferedReader(new InputStreamReader( migFile.getInputStream())); String str; while ((str = in.readLine()) != null) { // execute each line if (str.length() > 0) { executeUpdate(str); } } in.close(); } // update the configuration table with the correct version executeUpdate("UPDATE " + Constants.DB_TABLE_CONFIGURATION + " SET " + Constants.DB_TABLE_CONFIGURATION_VALUE + "='" + current_version + "' WHERE " + Constants.DB_TABLE_CONFIGURATION_NAME + "='" + Constants.DB_TABLE_CONFIGURATION_DATABASE_VERSION + "';"); } catch (Exception e) { logger.info("Error in executeUpdate"); e.printStackTrace(); } }
[ "public", "void", "updateSchema", "(", "String", "migrationPath", ")", "{", "try", "{", "logger", ".", "info", "(", "\"Updating schema... \"", ")", ";", "int", "current_version", "=", "0", ";", "// first check the current schema version", "HashMap", "<", "String", ",", "Object", ">", "configuration", "=", "getFirstResult", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION", "+", "\" WHERE \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_NAME", "+", "\" = \\'\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_DATABASE_VERSION", "+", "\"\\'\"", ")", ";", "if", "(", "configuration", "==", "null", ")", "{", "logger", ".", "info", "(", "\"Creating configuration table..\"", ")", ";", "// create configuration table", "executeUpdate", "(", "\"CREATE TABLE \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION", "+", "\" (\"", "+", "Constants", ".", "GENERIC_ID", "+", "\" INTEGER IDENTITY,\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_NAME", "+", "\" VARCHAR(256),\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_VALUE", "+", "\" VARCHAR(1024));\"", ")", ";", "executeUpdate", "(", "\"INSERT INTO \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION", "+", "\"(\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_NAME", "+", "\",\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_VALUE", "+", "\")\"", "+", "\" VALUES (\\'\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_DATABASE_VERSION", "+", "\"\\', '0');\"", ")", ";", "}", "else", "{", "logger", ".", "info", "(", "\"Getting current schema version..\"", ")", ";", "// get current version", "current_version", "=", "new", "Integer", "(", "configuration", ".", "get", "(", "\"VALUE\"", ")", ".", "toString", "(", ")", ")", ";", "logger", ".", "info", "(", "\"Current schema version is {}\"", ",", "current_version", ")", ";", "}", "// loop through until we get up to the right schema version", "while", "(", "current_version", "<", "Constants", ".", "DB_CURRENT_SCHEMA_VERSION", ")", "{", "current_version", "++", ";", "// look for a schema file for this version", "logger", ".", "info", "(", "\"Updating to schema version {}\"", ",", "current_version", ")", ";", "String", "currentFile", "=", "migrationPath", "+", "\"/schema.\"", "+", "current_version", ";", "Resource", "migFile", "=", "new", "ClassPathResource", "(", "currentFile", ")", ";", "BufferedReader", "in", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "migFile", ".", "getInputStream", "(", ")", ")", ")", ";", "String", "str", ";", "while", "(", "(", "str", "=", "in", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "// execute each line", "if", "(", "str", ".", "length", "(", ")", ">", "0", ")", "{", "executeUpdate", "(", "str", ")", ";", "}", "}", "in", ".", "close", "(", ")", ";", "}", "// update the configuration table with the correct version", "executeUpdate", "(", "\"UPDATE \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION", "+", "\" SET \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_VALUE", "+", "\"='\"", "+", "current_version", "+", "\"' WHERE \"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_NAME", "+", "\"='\"", "+", "Constants", ".", "DB_TABLE_CONFIGURATION_DATABASE_VERSION", "+", "\"';\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "info", "(", "\"Error in executeUpdate\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Update database schema @param migrationPath path to migrations
[ "Update", "database", "schema" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L187-L248
164,887
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.executeUpdate
public int executeUpdate(String query) throws Exception { int returnVal = 0; Statement queryStatement = null; try (Connection sqlConnection = getConnection()) { queryStatement = sqlConnection.createStatement(); returnVal = queryStatement.executeUpdate(query); } catch (Exception e) { } finally { try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return returnVal; }
java
public int executeUpdate(String query) throws Exception { int returnVal = 0; Statement queryStatement = null; try (Connection sqlConnection = getConnection()) { queryStatement = sqlConnection.createStatement(); returnVal = queryStatement.executeUpdate(query); } catch (Exception e) { } finally { try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return returnVal; }
[ "public", "int", "executeUpdate", "(", "String", "query", ")", "throws", "Exception", "{", "int", "returnVal", "=", "0", ";", "Statement", "queryStatement", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "getConnection", "(", ")", ")", "{", "queryStatement", "=", "sqlConnection", ".", "createStatement", "(", ")", ";", "returnVal", "=", "queryStatement", ".", "executeUpdate", "(", "query", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "}", "finally", "{", "try", "{", "if", "(", "queryStatement", "!=", "null", ")", "{", "queryStatement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "returnVal", ";", "}" ]
Wrapped version of standard jdbc executeUpdate Pays attention to DB locked exception and waits up to 1s @param query SQL query to execute @throws Exception - will throw an exception if we can never get a lock
[ "Wrapped", "version", "of", "standard", "jdbc", "executeUpdate", "Pays", "attention", "to", "DB", "locked", "exception", "and", "waits", "up", "to", "1s" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L257-L275
164,888
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.getFirstResult
public HashMap<String, Object> getFirstResult(String query) throws Exception { HashMap<String, Object> result = null; Statement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = getConnection()) { queryStatement = sqlConnection.createStatement(); results = queryStatement.executeQuery(query); if (results.next()) { result = new HashMap<>(); String[] columns = getColumnNames(results.getMetaData()); for (String column : columns) { result.put(column, results.getObject(column)); } } } catch (Exception e) { } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return result; }
java
public HashMap<String, Object> getFirstResult(String query) throws Exception { HashMap<String, Object> result = null; Statement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = getConnection()) { queryStatement = sqlConnection.createStatement(); results = queryStatement.executeQuery(query); if (results.next()) { result = new HashMap<>(); String[] columns = getColumnNames(results.getMetaData()); for (String column : columns) { result.put(column, results.getObject(column)); } } } catch (Exception e) { } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return result; }
[ "public", "HashMap", "<", "String", ",", "Object", ">", "getFirstResult", "(", "String", "query", ")", "throws", "Exception", "{", "HashMap", "<", "String", ",", "Object", ">", "result", "=", "null", ";", "Statement", "queryStatement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "getConnection", "(", ")", ")", "{", "queryStatement", "=", "sqlConnection", ".", "createStatement", "(", ")", ";", "results", "=", "queryStatement", ".", "executeQuery", "(", "query", ")", ";", "if", "(", "results", ".", "next", "(", ")", ")", "{", "result", "=", "new", "HashMap", "<>", "(", ")", ";", "String", "[", "]", "columns", "=", "getColumnNames", "(", "results", ".", "getMetaData", "(", ")", ")", ";", "for", "(", "String", "column", ":", "columns", ")", "{", "result", ".", "put", "(", "column", ",", "results", ".", "getObject", "(", "column", ")", ")", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "queryStatement", "!=", "null", ")", "{", "queryStatement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "result", ";", "}" ]
Gets the first row for a query @param query query to execute @return result or NULL
[ "Gets", "the", "first", "row", "for", "a", "query" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L283-L318
164,889
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.toClob
public Clob toClob(String stringName, Connection sqlConnection) { Clob clobName = null; try { clobName = sqlConnection.createClob(); clobName.setString(1, stringName); } catch (SQLException e) { // TODO Auto-generated catch block logger.info("Unable to create clob object"); e.printStackTrace(); } return clobName; }
java
public Clob toClob(String stringName, Connection sqlConnection) { Clob clobName = null; try { clobName = sqlConnection.createClob(); clobName.setString(1, stringName); } catch (SQLException e) { // TODO Auto-generated catch block logger.info("Unable to create clob object"); e.printStackTrace(); } return clobName; }
[ "public", "Clob", "toClob", "(", "String", "stringName", ",", "Connection", "sqlConnection", ")", "{", "Clob", "clobName", "=", "null", ";", "try", "{", "clobName", "=", "sqlConnection", ".", "createClob", "(", ")", ";", "clobName", ".", "setString", "(", "1", ",", "stringName", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "// TODO Auto-generated catch block", "logger", ".", "info", "(", "\"Unable to create clob object\"", ")", ";", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "clobName", ";", "}" ]
Converts the given string to a clob object @param stringName string name to clob @param sqlConnection Connection object @return Clob object or NULL
[ "Converts", "the", "given", "string", "to", "a", "clob", "object" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L328-L339
164,890
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java
SQLService.getColumnNames
private String[] getColumnNames(ResultSetMetaData rsmd) throws Exception { ArrayList<String> names = new ArrayList<String>(); // Get result set meta data int numColumns = rsmd.getColumnCount(); // Get the column names; column indices start from 1 for (int i = 1; i < numColumns + 1; i++) { String columnName = rsmd.getColumnName(i); names.add(columnName); } return names.toArray(new String[0]); }
java
private String[] getColumnNames(ResultSetMetaData rsmd) throws Exception { ArrayList<String> names = new ArrayList<String>(); // Get result set meta data int numColumns = rsmd.getColumnCount(); // Get the column names; column indices start from 1 for (int i = 1; i < numColumns + 1; i++) { String columnName = rsmd.getColumnName(i); names.add(columnName); } return names.toArray(new String[0]); }
[ "private", "String", "[", "]", "getColumnNames", "(", "ResultSetMetaData", "rsmd", ")", "throws", "Exception", "{", "ArrayList", "<", "String", ">", "names", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "// Get result set meta data", "int", "numColumns", "=", "rsmd", ".", "getColumnCount", "(", ")", ";", "// Get the column names; column indices start from 1", "for", "(", "int", "i", "=", "1", ";", "i", "<", "numColumns", "+", "1", ";", "i", "++", ")", "{", "String", "columnName", "=", "rsmd", ".", "getColumnName", "(", "i", ")", ";", "names", ".", "add", "(", "columnName", ")", ";", "}", "return", "names", ".", "toArray", "(", "new", "String", "[", "0", "]", ")", ";", "}" ]
Gets all of the column names for a result meta data @param rsmd Resultset metadata @return Array of column names @throws Exception exception
[ "Gets", "all", "of", "the", "column", "names", "for", "a", "result", "meta", "data" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/SQLService.java#L348-L362
164,891
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.tableServers
public List<ServerRedirect> tableServers(int clientId) { List<ServerRedirect> servers = new ArrayList<>(); try { Client client = ClientService.getInstance().getClient(clientId); servers = tableServers(client.getProfile().getId(), client.getActiveServerGroup()); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return servers; }
java
public List<ServerRedirect> tableServers(int clientId) { List<ServerRedirect> servers = new ArrayList<>(); try { Client client = ClientService.getInstance().getClient(clientId); servers = tableServers(client.getProfile().getId(), client.getActiveServerGroup()); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return servers; }
[ "public", "List", "<", "ServerRedirect", ">", "tableServers", "(", "int", "clientId", ")", "{", "List", "<", "ServerRedirect", ">", "servers", "=", "new", "ArrayList", "<>", "(", ")", ";", "try", "{", "Client", "client", "=", "ClientService", ".", "getInstance", "(", ")", ".", "getClient", "(", "clientId", ")", ";", "servers", "=", "tableServers", "(", "client", ".", "getProfile", "(", ")", ".", "getId", "(", ")", ",", "client", ".", "getActiveServerGroup", "(", ")", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "servers", ";", "}" ]
Get the server redirects for a given clientId from the database @param clientId client ID @return collection of ServerRedirects
[ "Get", "the", "server", "redirects", "for", "a", "given", "clientId", "from", "the", "database" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L64-L76
164,892
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.tableServers
public List<ServerRedirect> tableServers(int profileId, int serverGroupId) { ArrayList<ServerRedirect> servers = new ArrayList<>(); PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVERS + " WHERE " + Constants.GENERIC_PROFILE_ID + " = ?" + " AND " + Constants.SERVER_REDIRECT_GROUP_ID + " = ?" ); queryStatement.setInt(1, profileId); queryStatement.setInt(2, serverGroupId); results = queryStatement.executeQuery(); while (results.next()) { ServerRedirect curServer = new ServerRedirect(results.getInt(Constants.GENERIC_ID), results.getString(Constants.SERVER_REDIRECT_REGION), results.getString(Constants.SERVER_REDIRECT_SRC_URL), results.getString(Constants.SERVER_REDIRECT_DEST_URL), results.getString(Constants.SERVER_REDIRECT_HOST_HEADER)); curServer.setProfileId(profileId); servers.add(curServer); } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return servers; }
java
public List<ServerRedirect> tableServers(int profileId, int serverGroupId) { ArrayList<ServerRedirect> servers = new ArrayList<>(); PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVERS + " WHERE " + Constants.GENERIC_PROFILE_ID + " = ?" + " AND " + Constants.SERVER_REDIRECT_GROUP_ID + " = ?" ); queryStatement.setInt(1, profileId); queryStatement.setInt(2, serverGroupId); results = queryStatement.executeQuery(); while (results.next()) { ServerRedirect curServer = new ServerRedirect(results.getInt(Constants.GENERIC_ID), results.getString(Constants.SERVER_REDIRECT_REGION), results.getString(Constants.SERVER_REDIRECT_SRC_URL), results.getString(Constants.SERVER_REDIRECT_DEST_URL), results.getString(Constants.SERVER_REDIRECT_HOST_HEADER)); curServer.setProfileId(profileId); servers.add(curServer); } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return servers; }
[ "public", "List", "<", "ServerRedirect", ">", "tableServers", "(", "int", "profileId", ",", "int", "serverGroupId", ")", "{", "ArrayList", "<", "ServerRedirect", ">", "servers", "=", "new", "ArrayList", "<>", "(", ")", ";", "PreparedStatement", "queryStatement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "queryStatement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SERVERS", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\" = ?\"", "+", "\" AND \"", "+", "Constants", ".", "SERVER_REDIRECT_GROUP_ID", "+", "\" = ?\"", ")", ";", "queryStatement", ".", "setInt", "(", "1", ",", "profileId", ")", ";", "queryStatement", ".", "setInt", "(", "2", ",", "serverGroupId", ")", ";", "results", "=", "queryStatement", ".", "executeQuery", "(", ")", ";", "while", "(", "results", ".", "next", "(", ")", ")", "{", "ServerRedirect", "curServer", "=", "new", "ServerRedirect", "(", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_ID", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_REGION", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_SRC_URL", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_DEST_URL", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_HOST_HEADER", ")", ")", ";", "curServer", ".", "setProfileId", "(", "profileId", ")", ";", "servers", ".", "add", "(", "curServer", ")", ";", "}", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "queryStatement", "!=", "null", ")", "{", "queryStatement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "servers", ";", "}" ]
Get the server redirects belonging to a server group @param profileId ID of profile @param serverGroupId ID of server group @return Collection of ServerRedirect for a server group
[ "Get", "the", "server", "redirects", "belonging", "to", "a", "server", "group" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L85-L127
164,893
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.tableServerGroups
public List<ServerGroup> tableServerGroups(int profileId) { ArrayList<ServerGroup> serverGroups = new ArrayList<>(); PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVER_GROUPS + " WHERE " + Constants.GENERIC_PROFILE_ID + " = ? " + "ORDER BY " + Constants.GENERIC_NAME ); queryStatement.setInt(1, profileId); results = queryStatement.executeQuery(); while (results.next()) { ServerGroup curServerGroup = new ServerGroup(results.getInt(Constants.GENERIC_ID), results.getString(Constants.GENERIC_NAME), results.getInt(Constants.GENERIC_PROFILE_ID)); curServerGroup.setServers(tableServers(profileId, curServerGroup.getId())); serverGroups.add(curServerGroup); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return serverGroups; }
java
public List<ServerGroup> tableServerGroups(int profileId) { ArrayList<ServerGroup> serverGroups = new ArrayList<>(); PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVER_GROUPS + " WHERE " + Constants.GENERIC_PROFILE_ID + " = ? " + "ORDER BY " + Constants.GENERIC_NAME ); queryStatement.setInt(1, profileId); results = queryStatement.executeQuery(); while (results.next()) { ServerGroup curServerGroup = new ServerGroup(results.getInt(Constants.GENERIC_ID), results.getString(Constants.GENERIC_NAME), results.getInt(Constants.GENERIC_PROFILE_ID)); curServerGroup.setServers(tableServers(profileId, curServerGroup.getId())); serverGroups.add(curServerGroup); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return serverGroups; }
[ "public", "List", "<", "ServerGroup", ">", "tableServerGroups", "(", "int", "profileId", ")", "{", "ArrayList", "<", "ServerGroup", ">", "serverGroups", "=", "new", "ArrayList", "<>", "(", ")", ";", "PreparedStatement", "queryStatement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "queryStatement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SERVER_GROUPS", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\" = ? \"", "+", "\"ORDER BY \"", "+", "Constants", ".", "GENERIC_NAME", ")", ";", "queryStatement", ".", "setInt", "(", "1", ",", "profileId", ")", ";", "results", "=", "queryStatement", ".", "executeQuery", "(", ")", ";", "while", "(", "results", ".", "next", "(", ")", ")", "{", "ServerGroup", "curServerGroup", "=", "new", "ServerGroup", "(", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_ID", ")", ",", "results", ".", "getString", "(", "Constants", ".", "GENERIC_NAME", ")", ",", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_PROFILE_ID", ")", ")", ";", "curServerGroup", ".", "setServers", "(", "tableServers", "(", "profileId", ",", "curServerGroup", ".", "getId", "(", ")", ")", ")", ";", "serverGroups", ".", "add", "(", "curServerGroup", ")", ";", "}", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "queryStatement", "!=", "null", ")", "{", "queryStatement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "serverGroups", ";", "}" ]
Return all server groups for a profile @param profileId ID of profile @return collection of ServerGroups for a profile
[ "Return", "all", "server", "groups", "for", "a", "profile" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L135-L172
164,894
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.getRedirect
public ServerRedirect getRedirect(int id) throws Exception { PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVERS + " WHERE " + Constants.GENERIC_ID + " = ?" ); queryStatement.setInt(1, id); results = queryStatement.executeQuery(); if (results.next()) { ServerRedirect curServer = new ServerRedirect(results.getInt(Constants.GENERIC_ID), results.getString(Constants.SERVER_REDIRECT_REGION), results.getString(Constants.SERVER_REDIRECT_SRC_URL), results.getString(Constants.SERVER_REDIRECT_DEST_URL), results.getString(Constants.SERVER_REDIRECT_HOST_HEADER)); curServer.setProfileId(results.getInt(Constants.GENERIC_PROFILE_ID)); return curServer; } logger.info("Did not find the ID: {}", id); } catch (SQLException e) { throw e; } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return null; }
java
public ServerRedirect getRedirect(int id) throws Exception { PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVERS + " WHERE " + Constants.GENERIC_ID + " = ?" ); queryStatement.setInt(1, id); results = queryStatement.executeQuery(); if (results.next()) { ServerRedirect curServer = new ServerRedirect(results.getInt(Constants.GENERIC_ID), results.getString(Constants.SERVER_REDIRECT_REGION), results.getString(Constants.SERVER_REDIRECT_SRC_URL), results.getString(Constants.SERVER_REDIRECT_DEST_URL), results.getString(Constants.SERVER_REDIRECT_HOST_HEADER)); curServer.setProfileId(results.getInt(Constants.GENERIC_PROFILE_ID)); return curServer; } logger.info("Did not find the ID: {}", id); } catch (SQLException e) { throw e; } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return null; }
[ "public", "ServerRedirect", "getRedirect", "(", "int", "id", ")", "throws", "Exception", "{", "PreparedStatement", "queryStatement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "queryStatement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SERVERS", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_ID", "+", "\" = ?\"", ")", ";", "queryStatement", ".", "setInt", "(", "1", ",", "id", ")", ";", "results", "=", "queryStatement", ".", "executeQuery", "(", ")", ";", "if", "(", "results", ".", "next", "(", ")", ")", "{", "ServerRedirect", "curServer", "=", "new", "ServerRedirect", "(", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_ID", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_REGION", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_SRC_URL", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_DEST_URL", ")", ",", "results", ".", "getString", "(", "Constants", ".", "SERVER_REDIRECT_HOST_HEADER", ")", ")", ";", "curServer", ".", "setProfileId", "(", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_PROFILE_ID", ")", ")", ";", "return", "curServer", ";", "}", "logger", ".", "info", "(", "\"Did not find the ID: {}\"", ",", "id", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "throw", "e", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "queryStatement", "!=", "null", ")", "{", "queryStatement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "null", ";", "}" ]
Returns redirect information for the given ID @param id ID of redirect @return ServerRedirect @throws Exception exception
[ "Returns", "redirect", "information", "for", "the", "given", "ID" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L181-L220
164,895
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.getServerGroup
public ServerGroup getServerGroup(int id, int profileId) throws Exception { PreparedStatement queryStatement = null; ResultSet results = null; if (id == 0) { return new ServerGroup(0, "Default", profileId); } try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVER_GROUPS + " WHERE " + Constants.GENERIC_ID + " = ?" ); queryStatement.setInt(1, id); results = queryStatement.executeQuery(); if (results.next()) { ServerGroup curGroup = new ServerGroup(results.getInt(Constants.GENERIC_ID), results.getString(Constants.GENERIC_NAME), results.getInt(Constants.GENERIC_PROFILE_ID)); return curGroup; } logger.info("Did not find the ID: {}", id); } catch (SQLException e) { throw e; } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return null; }
java
public ServerGroup getServerGroup(int id, int profileId) throws Exception { PreparedStatement queryStatement = null; ResultSet results = null; if (id == 0) { return new ServerGroup(0, "Default", profileId); } try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement( "SELECT * FROM " + Constants.DB_TABLE_SERVER_GROUPS + " WHERE " + Constants.GENERIC_ID + " = ?" ); queryStatement.setInt(1, id); results = queryStatement.executeQuery(); if (results.next()) { ServerGroup curGroup = new ServerGroup(results.getInt(Constants.GENERIC_ID), results.getString(Constants.GENERIC_NAME), results.getInt(Constants.GENERIC_PROFILE_ID)); return curGroup; } logger.info("Did not find the ID: {}", id); } catch (SQLException e) { throw e; } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (queryStatement != null) { queryStatement.close(); } } catch (Exception e) { } } return null; }
[ "public", "ServerGroup", "getServerGroup", "(", "int", "id", ",", "int", "profileId", ")", "throws", "Exception", "{", "PreparedStatement", "queryStatement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "if", "(", "id", "==", "0", ")", "{", "return", "new", "ServerGroup", "(", "0", ",", "\"Default\"", ",", "profileId", ")", ";", "}", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "queryStatement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"SELECT * FROM \"", "+", "Constants", ".", "DB_TABLE_SERVER_GROUPS", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_ID", "+", "\" = ?\"", ")", ";", "queryStatement", ".", "setInt", "(", "1", ",", "id", ")", ";", "results", "=", "queryStatement", ".", "executeQuery", "(", ")", ";", "if", "(", "results", ".", "next", "(", ")", ")", "{", "ServerGroup", "curGroup", "=", "new", "ServerGroup", "(", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_ID", ")", ",", "results", ".", "getString", "(", "Constants", ".", "GENERIC_NAME", ")", ",", "results", ".", "getInt", "(", "Constants", ".", "GENERIC_PROFILE_ID", ")", ")", ";", "return", "curGroup", ";", "}", "logger", ".", "info", "(", "\"Did not find the ID: {}\"", ",", "id", ")", ";", "}", "catch", "(", "SQLException", "e", ")", "{", "throw", "e", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "queryStatement", "!=", "null", ")", "{", "queryStatement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "null", ";", "}" ]
Returns server group by ID @param id ID of server group @return ServerGroup @throws Exception exception
[ "Returns", "server", "group", "by", "ID" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L229-L268
164,896
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.addServerRedirectToProfile
public int addServerRedirectToProfile(String region, String srcUrl, String destUrl, String hostHeader, int profileId, int clientId) throws Exception { int serverId = -1; try { Client client = ClientService.getInstance().getClient(clientId); serverId = addServerRedirect(region, srcUrl, destUrl, hostHeader, profileId, client.getActiveServerGroup()); } catch (Exception e) { e.printStackTrace(); } return serverId; }
java
public int addServerRedirectToProfile(String region, String srcUrl, String destUrl, String hostHeader, int profileId, int clientId) throws Exception { int serverId = -1; try { Client client = ClientService.getInstance().getClient(clientId); serverId = addServerRedirect(region, srcUrl, destUrl, hostHeader, profileId, client.getActiveServerGroup()); } catch (Exception e) { e.printStackTrace(); } return serverId; }
[ "public", "int", "addServerRedirectToProfile", "(", "String", "region", ",", "String", "srcUrl", ",", "String", "destUrl", ",", "String", "hostHeader", ",", "int", "profileId", ",", "int", "clientId", ")", "throws", "Exception", "{", "int", "serverId", "=", "-", "1", ";", "try", "{", "Client", "client", "=", "ClientService", ".", "getInstance", "(", ")", ".", "getClient", "(", "clientId", ")", ";", "serverId", "=", "addServerRedirect", "(", "region", ",", "srcUrl", ",", "destUrl", ",", "hostHeader", ",", "profileId", ",", "client", ".", "getActiveServerGroup", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "serverId", ";", "}" ]
Add server redirect to a profile, using current active ServerGroup @param region region @param srcUrl source URL @param destUrl destination URL @param hostHeader host header @param profileId profile ID @return ID of added ServerRedirect @throws Exception exception
[ "Add", "server", "redirect", "to", "a", "profile", "using", "current", "active", "ServerGroup" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L281-L293
164,897
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.addServerRedirect
public int addServerRedirect(String region, String srcUrl, String destUrl, String hostHeader, int profileId, int groupId) throws Exception { int serverId = -1; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_SERVERS + "(" + Constants.SERVER_REDIRECT_REGION + "," + Constants.SERVER_REDIRECT_SRC_URL + "," + Constants.SERVER_REDIRECT_DEST_URL + "," + Constants.SERVER_REDIRECT_HOST_HEADER + "," + Constants.SERVER_REDIRECT_PROFILE_ID + "," + Constants.SERVER_REDIRECT_GROUP_ID + ")" + " VALUES (?, ?, ?, ?, ?, ?);", PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, region); statement.setString(2, srcUrl); statement.setString(3, destUrl); statement.setString(4, hostHeader); statement.setInt(5, profileId); statement.setInt(6, groupId); statement.executeUpdate(); results = statement.getGeneratedKeys(); if (results.next()) { serverId = results.getInt(1); } else { // something went wrong throw new Exception("Could not add path"); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return serverId; }
java
public int addServerRedirect(String region, String srcUrl, String destUrl, String hostHeader, int profileId, int groupId) throws Exception { int serverId = -1; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_SERVERS + "(" + Constants.SERVER_REDIRECT_REGION + "," + Constants.SERVER_REDIRECT_SRC_URL + "," + Constants.SERVER_REDIRECT_DEST_URL + "," + Constants.SERVER_REDIRECT_HOST_HEADER + "," + Constants.SERVER_REDIRECT_PROFILE_ID + "," + Constants.SERVER_REDIRECT_GROUP_ID + ")" + " VALUES (?, ?, ?, ?, ?, ?);", PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, region); statement.setString(2, srcUrl); statement.setString(3, destUrl); statement.setString(4, hostHeader); statement.setInt(5, profileId); statement.setInt(6, groupId); statement.executeUpdate(); results = statement.getGeneratedKeys(); if (results.next()) { serverId = results.getInt(1); } else { // something went wrong throw new Exception("Could not add path"); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return serverId; }
[ "public", "int", "addServerRedirect", "(", "String", "region", ",", "String", "srcUrl", ",", "String", "destUrl", ",", "String", "hostHeader", ",", "int", "profileId", ",", "int", "groupId", ")", "throws", "Exception", "{", "int", "serverId", "=", "-", "1", ";", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"INSERT INTO \"", "+", "Constants", ".", "DB_TABLE_SERVERS", "+", "\"(\"", "+", "Constants", ".", "SERVER_REDIRECT_REGION", "+", "\",\"", "+", "Constants", ".", "SERVER_REDIRECT_SRC_URL", "+", "\",\"", "+", "Constants", ".", "SERVER_REDIRECT_DEST_URL", "+", "\",\"", "+", "Constants", ".", "SERVER_REDIRECT_HOST_HEADER", "+", "\",\"", "+", "Constants", ".", "SERVER_REDIRECT_PROFILE_ID", "+", "\",\"", "+", "Constants", ".", "SERVER_REDIRECT_GROUP_ID", "+", "\")\"", "+", "\" VALUES (?, ?, ?, ?, ?, ?);\"", ",", "PreparedStatement", ".", "RETURN_GENERATED_KEYS", ")", ";", "statement", ".", "setString", "(", "1", ",", "region", ")", ";", "statement", ".", "setString", "(", "2", ",", "srcUrl", ")", ";", "statement", ".", "setString", "(", "3", ",", "destUrl", ")", ";", "statement", ".", "setString", "(", "4", ",", "hostHeader", ")", ";", "statement", ".", "setInt", "(", "5", ",", "profileId", ")", ";", "statement", ".", "setInt", "(", "6", ",", "groupId", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "results", "=", "statement", ".", "getGeneratedKeys", "(", ")", ";", "if", "(", "results", ".", "next", "(", ")", ")", "{", "serverId", "=", "results", ".", "getInt", "(", "1", ")", ";", "}", "else", "{", "// something went wrong", "throw", "new", "Exception", "(", "\"Could not add path\"", ")", ";", "}", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "serverId", ";", "}" ]
Add server redirect to a profile @param region region @param srcUrl source URL @param destUrl destination URL @param hostHeader host header @param profileId profile ID @param groupId group ID @return ID of added ServerRedirect @throws Exception exception
[ "Add", "server", "redirect", "to", "a", "profile" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L307-L355
164,898
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.addServerGroup
public int addServerGroup(String groupName, int profileId) throws Exception { int groupId = -1; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_SERVER_GROUPS + "(" + Constants.GENERIC_NAME + "," + Constants.GENERIC_PROFILE_ID + ")" + " VALUES (?, ?);", PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, groupName); statement.setInt(2, profileId); statement.executeUpdate(); results = statement.getGeneratedKeys(); if (results.next()) { groupId = results.getInt(1); } else { // something went wrong throw new Exception("Could not add group"); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return groupId; }
java
public int addServerGroup(String groupName, int profileId) throws Exception { int groupId = -1; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_SERVER_GROUPS + "(" + Constants.GENERIC_NAME + "," + Constants.GENERIC_PROFILE_ID + ")" + " VALUES (?, ?);", PreparedStatement.RETURN_GENERATED_KEYS); statement.setString(1, groupName); statement.setInt(2, profileId); statement.executeUpdate(); results = statement.getGeneratedKeys(); if (results.next()) { groupId = results.getInt(1); } else { // something went wrong throw new Exception("Could not add group"); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (statement != null) { statement.close(); } } catch (Exception e) { } } return groupId; }
[ "public", "int", "addServerGroup", "(", "String", "groupName", ",", "int", "profileId", ")", "throws", "Exception", "{", "int", "groupId", "=", "-", "1", ";", "PreparedStatement", "statement", "=", "null", ";", "ResultSet", "results", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"INSERT INTO \"", "+", "Constants", ".", "DB_TABLE_SERVER_GROUPS", "+", "\"(\"", "+", "Constants", ".", "GENERIC_NAME", "+", "\",\"", "+", "Constants", ".", "GENERIC_PROFILE_ID", "+", "\")\"", "+", "\" VALUES (?, ?);\"", ",", "PreparedStatement", ".", "RETURN_GENERATED_KEYS", ")", ";", "statement", ".", "setString", "(", "1", ",", "groupName", ")", ";", "statement", ".", "setInt", "(", "2", ",", "profileId", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "results", "=", "statement", ".", "getGeneratedKeys", "(", ")", ";", "if", "(", "results", ".", "next", "(", ")", ")", "{", "groupId", "=", "results", ".", "getInt", "(", "1", ")", ";", "}", "else", "{", "// something went wrong", "throw", "new", "Exception", "(", "\"Could not add group\"", ")", ";", "}", "}", "catch", "(", "SQLException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "results", "!=", "null", ")", "{", "results", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "return", "groupId", ";", "}" ]
Add a new server group @param groupName name of the group @param profileId ID of associated profile @return id of server group @throws Exception
[ "Add", "a", "new", "server", "group" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L365-L405
164,899
groupon/odo
proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java
ServerRedirectService.setGroupName
public void setGroupName(String name, int id) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_SERVER_GROUPS + " SET " + Constants.GENERIC_NAME + " = ?" + " WHERE " + Constants.GENERIC_ID + " = ?" ); statement.setString(1, name); statement.setInt(2, id); statement.executeUpdate(); statement.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } }
java
public void setGroupName(String name, int id) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_SERVER_GROUPS + " SET " + Constants.GENERIC_NAME + " = ?" + " WHERE " + Constants.GENERIC_ID + " = ?" ); statement.setString(1, name); statement.setInt(2, id); statement.executeUpdate(); statement.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } } catch (Exception e) { } } }
[ "public", "void", "setGroupName", "(", "String", "name", ",", "int", "id", ")", "{", "PreparedStatement", "statement", "=", "null", ";", "try", "(", "Connection", "sqlConnection", "=", "sqlService", ".", "getConnection", "(", ")", ")", "{", "statement", "=", "sqlConnection", ".", "prepareStatement", "(", "\"UPDATE \"", "+", "Constants", ".", "DB_TABLE_SERVER_GROUPS", "+", "\" SET \"", "+", "Constants", ".", "GENERIC_NAME", "+", "\" = ?\"", "+", "\" WHERE \"", "+", "Constants", ".", "GENERIC_ID", "+", "\" = ?\"", ")", ";", "statement", ".", "setString", "(", "1", ",", "name", ")", ";", "statement", ".", "setInt", "(", "2", ",", "id", ")", ";", "statement", ".", "executeUpdate", "(", ")", ";", "statement", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "statement", "!=", "null", ")", "{", "statement", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "}", "}", "}" ]
Set the group name @param name new name of server group @param id ID of group
[ "Set", "the", "group", "name" ]
3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1
https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L413-L436