@StaplerDispatchable public void getTestForReverseProxySetup(String rest) { Jenkins j = Jenkins.getInstance(); String inferred = j.getRootUrlFromRequest() + "manage"; // TODO this could also verify that j.getRootUrl() has been properly configured, and send a different message if not if (rest.startsWith(inferred)) { // not using equals due to JENKINS-24014 throw HttpResponses.ok(); } else { LOGGER.log(Level.WARNING, "{0} vs. {1}", new Object[] {inferred, rest}); throw HttpResponses.errorWithoutStack(404, inferred + " vs. " + rest); } }
/** * Utility method to stop preprocessing if condition is false * * @param condition on false throws exception * @param msg to add to exception * @throws InvocationTargetException BAD REQUEST 400 status code with message */ private void isTrue(boolean condition, String msg) throws InvocationTargetException { if (!condition) { throw new InvocationTargetException(errorWithoutStack(SC_BAD_REQUEST, msg)); } } }
public void getTestForReverseProxySetup(String rest) { Jenkins j = Jenkins.getInstance(); String inferred = j.getRootUrlFromRequest() + "manage"; // TODO this could also verify that j.getRootUrl() has been properly configured, and send a different message if not if (rest.startsWith(inferred)) { // not using equals due to JENKINS-24014 throw HttpResponses.ok(); } else { LOGGER.log(Level.WARNING, "{0} vs. {1}", new Object[] {inferred, rest}); throw HttpResponses.errorWithoutStack(404, inferred + " vs. " + rest); } }
@Override public Object invoke(StaplerRequest request, StaplerResponse response, Object instance, Object[] arguments) throws IllegalAccessException, InvocationTargetException { if (!from(newArrayList(arguments)).firstMatch(instanceOf(GitHubRepositoryName.class)).isPresent()) { throw new InvocationTargetException( errorWithoutStack(SC_BAD_REQUEST, "Request should contain full repo name") ); } return target.invoke(request, response, instance, arguments); } }