* @param clientUUID
* @return
* @throws Exception
*/
public EnabledEndpoint getEnabledEndpoint(int pathId, int overrideId, Integer ordinal, String clientUUID) throws Exception {
EnabledEndpoint endpoint = null;
PreparedStatement statement = null;
ResultSet results = null;
if (ordinal == null)
ordinal = 1;
// try to get it from the database
try (Connection sqlConnection = sqlService.getConnection()) {
// decrease ordinal by 1 so offset works right
ordinal--;
String queryString = "SELECT * FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE +
" WHERE " + Constants.ENABLED_OVERRIDES_PATH_ID + "=? " +
" AND " + Constants.ENABLED_OVERRIDES_OVERRIDE_ID + "=? " +
" AND " + Constants.GENERIC_CLIENT_UUID + "=? " +
" LIMIT 1 OFFSET ?";
statement = sqlConnection.prepareStatement(queryString);
statement.setInt(1, pathId);
statement.setInt(2, overrideId);
statement.setString(3, clientUUID);
statement.setInt(4, ordinal);
results = statement.executeQuery();
while (results.next()) {
endpoint = this.getPartialEnabledEndpointFromResultset(results);
break;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (results != null) results.close();
} catch (Exception e) {
}
try {
if (statement != null) statement.close();
} catch (Exception e) {
}
}
if (endpoint != null) {
// get the method also for a real endpoint
if (endpoint.getOverrideId() >= 0) {
com.groupon.odo.proxylib.models.Method m = PathOverrideService.getInstance().getMethodForOverrideId(endpoint.getOverrideId());
endpoint.setMethodInformation(m);
} else if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_HEADER_OVERRIDE_ADD
|| endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_ADD) {
// set fake method info
com.groupon.odo.proxylib.models.Method m = new com.groupon.odo.proxylib.models.Method();
m.setMethodArgumentNames(new String[]{"key", "value"});
m.setMethodArguments(new Object[]{String.class, String.class});
m.setClassName("");
m.setMethodName("CUSTOM HEADER");
if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_HEADER_OVERRIDE_ADD) {
m.setDescription("Set a response header");
} else if (endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_ADD) {
m.setDescription("Set a request header");
}
endpoint.setMethodInformation(m);
} else if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_HEADER_OVERRIDE_REMOVE
|| endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE) {
// set fake method info
com.groupon.odo.proxylib.models.Method m = new com.groupon.odo.proxylib.models.Method();
m.setMethodArgumentNames(new String[]{"key"});
m.setMethodArguments(new Object[]{String.class});
m.setClassName("");
m.setMethodName("REMOVE HEADER");
if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_HEADER_OVERRIDE_REMOVE) {
m.setDescription("Remove a response header");
} else if (endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_HEADER_OVERRIDE_REMOVE) {
m.setDescription("Remove a request header");
}
endpoint.setMethodInformation(m);
} else if (endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_OVERRIDE_CUSTOM
|| endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_OVERRIDE_CUSTOM) {
// set fake method info
com.groupon.odo.proxylib.models.Method m = new com.groupon.odo.proxylib.models.Method();
m.setMethodArgumentNames(new String[]{"response"});
m.setMethodArguments(new Object[]{String.class});
m.setClassName("");
m.setMethodName("CUSTOM");
if (endpoint.getOverrideId() == Constants.PLUGIN_REQUEST_OVERRIDE_CUSTOM) {
m.setDescription("Return a custom request");
} else if (endpoint.getOverrideId() == Constants.PLUGIN_RESPONSE_OVERRIDE_CUSTOM) {
m.setDescription("Return a custom response");
}
endpoint.setMethodInformation(m);
}
}
return endpoint;
}