Search in sources :

Example 6 with J4pException

use of org.jolokia.client.exception.J4pException 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

J4pException (org.jolokia.client.exception.J4pException)6 J4pExecRequest (org.jolokia.client.request.J4pExecRequest)5 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 List (java.util.List)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 J4pConnectException (org.jolokia.client.exception.J4pConnectException)2 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)2 AbtractJ4pMBeanRequest (org.jolokia.client.request.AbtractJ4pMBeanRequest)2 J4pExecResponse (org.jolokia.client.request.J4pExecResponse)2 J4pResponse (org.jolokia.client.request.J4pResponse)2 J4pWriteRequest (org.jolokia.client.request.J4pWriteRequest)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 ArtifactDeploymentException (org.apache.maven.artifact.deployer.ArtifactDeploymentException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 J4pClient (org.jolokia.client.J4pClient)1 J4pClientBuilder (org.jolokia.client.J4pClientBuilder)1 J4pReadResponse (org.jolokia.client.request.J4pReadResponse)1