Search in sources :

Example 1 with AbtractJ4pMBeanRequest

use of org.jolokia.client.request.AbtractJ4pMBeanRequest in project fabric8 by jboss-fuse.

the class JolokiaInvocationHandler method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String name = method.getName();
    String attribute;
    AbtractJ4pMBeanRequest request;
    if ((attribute = getterAttributeName(method)) != null) {
        request = new J4pReadRequest(objectName, attribute);
    } else if ((attribute = setterAttributeName(method)) != null) {
        request = new J4pWriteRequest(objectName, attribute, args[0]);
    } else {
        name = executeMethodName(method);
        if (args == null | method.getParameterTypes().length == 0) {
            request = new J4pExecRequest(objectName, name);
        } else {
            request = new J4pExecRequest(objectName, name, args);
        }
    }
    try {
        request.setPreferredHttpMethod("POST");
        J4pResponse response = jolokia.execute(request);
        Object value = response.getValue();
        return JolokiaHelpers.convertJolokiaToJavaType(method.getReturnType(), value);
    } catch (J4pException e) {
        List<Object> argsList = args == null ? null : Arrays.asList(args);
        LOG.warn("Failed to invoke " + objectName + " method: " + name + " with arguments: " + argsList + ". " + e, e);
        throw e;
    }
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) J4pWriteRequest(org.jolokia.client.request.J4pWriteRequest) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pException(org.jolokia.client.exception.J4pException) List(java.util.List) AbtractJ4pMBeanRequest(org.jolokia.client.request.AbtractJ4pMBeanRequest) J4pResponse(org.jolokia.client.request.J4pResponse)

Example 2 with AbtractJ4pMBeanRequest

use of org.jolokia.client.request.AbtractJ4pMBeanRequest in project fabric8 by jboss-fuse.

the class JolokiaInvocationHandler method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String name = method.getName();
    String attribute;
    AbtractJ4pMBeanRequest request;
    if ((attribute = getterAttributeName(method)) != null) {
        request = new J4pReadRequest(objectName, attribute);
    } else if ((attribute = setterAttributeName(method)) != null) {
        request = new J4pWriteRequest(objectName, attribute, args[0]);
    } else {
        name = executeMethodName(method);
        if (args == null | method.getParameterTypes().length == 0) {
            request = new J4pExecRequest(objectName, name);
        } else {
            request = new J4pExecRequest(objectName, name, args);
        }
    }
    try {
        request.setPreferredHttpMethod("POST");
        J4pResponse response = jolokia.execute(request);
        Object value = response.getValue();
        return JolokiaClients.convertJolokiaToJavaType(method.getReturnType(), value);
    } catch (J4pException e) {
        List<Object> argsList = args == null ? null : Arrays.asList(args);
        LOG.warn("Failed to invoke " + objectName + " method: " + name + " with arguments: " + argsList + ". " + e, e);
        throw e;
    }
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) J4pWriteRequest(org.jolokia.client.request.J4pWriteRequest) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pException(org.jolokia.client.exception.J4pException) List(java.util.List) AbtractJ4pMBeanRequest(org.jolokia.client.request.AbtractJ4pMBeanRequest) J4pResponse(org.jolokia.client.request.J4pResponse)

Example 3 with AbtractJ4pMBeanRequest

use of org.jolokia.client.request.AbtractJ4pMBeanRequest in project fabric8 by fabric8io.

the class JolokiaInvocationHandler method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String name = method.getName();
    String attribute;
    AbtractJ4pMBeanRequest request;
    if ((attribute = getterAttributeName(method)) != null) {
        request = new J4pReadRequest(objectName, attribute);
    } else if ((attribute = setterAttributeName(method)) != null) {
        request = new J4pWriteRequest(objectName, attribute, args[0]);
    } else {
        name = executeMethodName(method);
        if (args == null | method.getParameterTypes().length == 0) {
            request = new J4pExecRequest(objectName, name);
        } else {
            request = new J4pExecRequest(objectName, name, args);
        }
    }
    try {
        request.setPreferredHttpMethod("POST");
        J4pResponse response = jolokia.execute(request);
        Object value = response.getValue();
        return JolokiaHelpers.convertJolokiaToJavaType(method.getReturnType(), value);
    } catch (J4pException e) {
        List<Object> argsList = args == null ? null : Arrays.asList(args);
        LOG.warn("Failed to invoke " + objectName + " method: " + name + " with arguments: " + argsList + ". " + e, e);
        throw e;
    }
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) J4pWriteRequest(org.jolokia.client.request.J4pWriteRequest) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pException(org.jolokia.client.exception.J4pException) List(java.util.List) AbtractJ4pMBeanRequest(org.jolokia.client.request.AbtractJ4pMBeanRequest) J4pResponse(org.jolokia.client.request.J4pResponse)

Aggregations

List (java.util.List)3 J4pException (org.jolokia.client.exception.J4pException)3 AbtractJ4pMBeanRequest (org.jolokia.client.request.AbtractJ4pMBeanRequest)3 J4pExecRequest (org.jolokia.client.request.J4pExecRequest)3 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)3 J4pResponse (org.jolokia.client.request.J4pResponse)3 J4pWriteRequest (org.jolokia.client.request.J4pWriteRequest)3