Package com.groupon.odo.proxylib.models

Examples of com.groupon.odo.proxylib.models.EnabledEndpoint


            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;
View Full Code Here


     * @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;
    }
View Full Code Here

     * @param result
     * @return
     * @throws Exception
     */
    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));

        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;
    }
View Full Code Here

TOP

Related Classes of com.groupon.odo.proxylib.models.EnabledEndpoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.