Improve exception message that reports clashing endpoint operations

Closes gh-10942
pull/10545/merge
Andy Wilkinson 7 years ago
parent e216560896
commit 4d1a98b380

@ -95,7 +95,9 @@ public class JmxOperation extends Operation {
@Override
public String toString() {
return new ToStringCreator(this).append("operationName", this.operationName)
return new ToStringCreator(this).append("type", getType())
.append("invoker", getInvoker()).append("blocking", isBlocking())
.append("operationName", this.operationName)
.append("outputType", this.outputType)
.append("description", this.description).toString();
}

@ -22,6 +22,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.boot.actuate.endpoint.OperationInvoker;
import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@ -103,4 +104,10 @@ public class ReflectiveOperationInvoker implements OperationInvoker {
return this.parameterMapper.mapParameter(resolved, parameter.getType());
}
@Override
public String toString() {
return new ToStringCreator(this).append("target", this.target)
.append("method", this.methodInfo.getMethod().toString()).toString();
}
}

@ -19,6 +19,7 @@ package org.springframework.boot.actuate.endpoint.web;
import org.springframework.boot.actuate.endpoint.Operation;
import org.springframework.boot.actuate.endpoint.OperationInvoker;
import org.springframework.boot.actuate.endpoint.OperationType;
import org.springframework.core.style.ToStringCreator;
/**
* An operation on a web endpoint.
@ -65,4 +66,12 @@ public class WebOperation extends Operation {
return this.id;
}
@Override
public String toString() {
return new ToStringCreator(this).append("type", getType())
.append("invoker", getInvoker()).append("blocking", isBlocking())
.append("requestPredicate", getRequestPredicate()).append("id", getId())
.toString();
}
}

@ -47,6 +47,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -216,6 +217,11 @@ public class JmxAnnotationEndpointDiscovererTests {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Found multiple JMX operations with the same name");
this.thrown.expectMessage("getAll");
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingOperationsEndpoint.class, "getAll").toString());
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingOperationsEndpoint.class, "getAll", String.class)
.toString());
discoverer.discoverEndpoints();
});
}
@ -226,6 +232,13 @@ public class JmxAnnotationEndpointDiscovererTests {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Found multiple JMX operations with the same name");
this.thrown.expectMessage("getAll");
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingOperationsJmxEndpointExtension.class, "getAll")
.toString());
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingOperationsJmxEndpointExtension.class, "getAll",
String.class)
.toString());
discoverer.discoverEndpoints();
});
}

@ -54,6 +54,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -162,6 +163,10 @@ public class WebAnnotationEndpointDiscovererTests {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage(
"Found multiple web operations with matching request predicates:");
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingOperationsEndpoint.class, "getAll").toString());
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingOperationsEndpoint.class, "getAgain").toString());
discoverer.discoverEndpoints();
});
}
@ -183,6 +188,14 @@ public class WebAnnotationEndpointDiscovererTests {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage(
"Found multiple web operations with matching request predicates:");
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingSelectorsWebEndpointExtension.class, "readOne",
String.class, String.class)
.toString());
this.thrown.expectMessage(ReflectionUtils
.findMethod(ClashingSelectorsWebEndpointExtension.class, "readTwo",
String.class, String.class)
.toString());
discoverer.discoverEndpoints();
});
}

Loading…
Cancel
Save