Search in sources :

Example 21 with J4pExecRequest

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

the class ProfileFacade method getFieldValue.

@SuppressWarnings("unchecked")
private static <T extends Object> T getFieldValue(J4pClient j4p, String operation, String versionId, String id, String field) {
    T rc = null;
    try {
        J4pExecRequest request = Helpers.createExecRequest(operation, versionId, id, Helpers.toList(field));
        J4pExecResponse response = j4p.execute(request);
        Map<String, Object> value = response.getValue();
        rc = (T) value.get(field);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException("Failed to get container field", e);
    } catch (J4pException e) {
        throw new RuntimeException("Failed to get container field", e);
    }
    return rc;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) J4pException(org.jolokia.client.exception.J4pException) J4pExecResponse(org.jolokia.client.request.J4pExecResponse)

Example 22 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest 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 23 with J4pExecRequest

use of org.jolokia.client.request.J4pExecRequest 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)

Example 24 with J4pExecRequest

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

the class JolokiaAssert method operationResult.

protected Object operationResult(String mbean, String operation, Object... arguments) throws MalformedObjectNameException, J4pException {
    ObjectName objectName = new ObjectName(mbean);
    J4pResponse<J4pExecRequest> results = client.execute(new J4pExecRequest(objectName, operation, arguments));
    return results.getValue();
}
Also used : J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ObjectName(javax.management.ObjectName)

Aggregations

J4pExecRequest (org.jolokia.client.request.J4pExecRequest)24 ObjectName (javax.management.ObjectName)17 J4pExecResponse (org.jolokia.client.request.J4pExecResponse)12 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 JSONObject (org.json.simple.JSONObject)7 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 J4pException (org.jolokia.client.exception.J4pException)5 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)3 J4pReadRequest (org.jolokia.client.request.J4pReadRequest)3 List (java.util.List)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 AbtractJ4pMBeanRequest (org.jolokia.client.request.AbtractJ4pMBeanRequest)2 J4pResponse (org.jolokia.client.request.J4pResponse)2 J4pWriteRequest (org.jolokia.client.request.J4pWriteRequest)2 DeployResults (io.fabric8.deployer.dto.DeployResults)1 IOException (java.io.IOException)1 Override (java.lang.Override)1