Search in sources :

Example 16 with InvocationContext

use of org.springframework.boot.actuate.endpoint.InvocationContext in project spring-boot by spring-projects.

the class ReflectiveOperationInvokerTests method invokeWhenMissingNullableArgumentShouldInvoke.

@Test
void invokeWhenMissingNullableArgumentShouldInvoke() {
    OperationMethod operationMethod = new OperationMethod(ReflectionUtils.findMethod(Example.class, "reverseNullable", ApiVersion.class, SecurityContext.class, String.class), OperationType.READ);
    ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, operationMethod, this.parameterValueMapper);
    Object result = invoker.invoke(new InvocationContext(mock(SecurityContext.class), Collections.singletonMap("name", null)));
    assertThat(result).isEqualTo("llun");
}
Also used : ApiVersion(org.springframework.boot.actuate.endpoint.ApiVersion) SecurityContext(org.springframework.boot.actuate.endpoint.SecurityContext) InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 17 with InvocationContext

use of org.springframework.boot.actuate.endpoint.InvocationContext in project spring-boot by spring-projects.

the class EndpointMBean method invoke.

private Object invoke(JmxOperation operation, Object[] params) throws MBeanException, ReflectionException {
    try {
        String[] parameterNames = operation.getParameters().stream().map(JmxOperationParameter::getName).toArray(String[]::new);
        Map<String, Object> arguments = getArguments(parameterNames, params);
        InvocationContext context = new InvocationContext(SecurityContext.NONE, arguments);
        Object result = operation.invoke(context);
        if (REACTOR_PRESENT) {
            result = ReactiveHandler.handle(result);
        }
        return this.responseMapper.mapResponse(result);
    } catch (InvalidEndpointRequestException ex) {
        throw new ReflectionException(new IllegalArgumentException(ex.getMessage()), ex.getMessage());
    } catch (Exception ex) {
        throw new MBeanException(translateIfNecessary(ex), ex.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) InvalidEndpointRequestException(org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException) MBeanException(javax.management.MBeanException) InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) AttributeNotFoundException(javax.management.AttributeNotFoundException) InvalidEndpointRequestException(org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ReflectionException(javax.management.ReflectionException)

Aggregations

InvocationContext (org.springframework.boot.actuate.endpoint.InvocationContext)17 Test (org.junit.jupiter.api.Test)14 SecurityContext (org.springframework.boot.actuate.endpoint.SecurityContext)11 OperationInvoker (org.springframework.boot.actuate.endpoint.invoke.OperationInvoker)7 HashMap (java.util.HashMap)4 Principal (java.security.Principal)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Mono (reactor.core.publisher.Mono)2 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)1 MBeanException (javax.management.MBeanException)1 ReflectionException (javax.management.ReflectionException)1 ApiVersion (org.springframework.boot.actuate.endpoint.ApiVersion)1 InvalidEndpointRequestException (org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException)1 ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)1 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)1 Flux (reactor.core.publisher.Flux)1