New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access serialized exception with java-client #85

Closed
marosmars opened this Issue Mar 12, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@marosmars
Contributor

marosmars commented Mar 12, 2013

We would like to utilize the "serializeException" option to access thrown exceptions. The problem is that we are unable to access serialized exception with java client included in jolokia.

When we query jolokia directly e.g.

curl http://<host>/jolokia/write/<object-name>/<variable>/<value>?serializeException=true

and an exception is thrown, the exception is serialized under "error_value" field. This is what we expect, but when we query jolokia with its java client e.g.

J4pClient j4pClient = new J4pClient(url);
J4pRequest pRequest = ...;
try {
    Map<J4pQueryParameter, String> pProcessingOptions = Maps.newHashMap();
    pProcessingOptions.put(J4pQueryParameter.SERIALIZE_EXCEPTION, "true");
    pProcessingOptions.put(J4pQueryParameter.INCLUDE_STACKTRACE, "false");
    return j4pClient.execute(pRequest, "POST", pProcessingOptions);
} catch (J4pRemoteException e) {
        // How to access error_value via J4pRemoteException 
}

We are unable to access serialized exception in the catch block via J4pRemoteException. J4pRemoteException does not include any functionality related to "error_value" field neither does processing of json response in org.jolokia.client.J4pClient (method: private J4pRemoteException validate(T pRequest, JSONObject pJsonRespObject)).

We would like the J4pRemoteException to provide either the whole json response object it was created from or just the "error_value" field as string so we can rebuild/rethrow the original exception .

If you agree and decide to provide this functionality, we are willing to implement it.

@rhuss

This comment has been minimized.

Owner

rhuss commented Mar 12, 2013

You are right, I forgot to adapt the Java Client's exception handling. What I could imagine is to add a JSONObject getErrorValue() Method to J4pRemoteException which returns the (parsed) serialized exception if this option is set. This would fit nicely to the current API which uses also already parsed JSONObjects for the return values (and not plain strings). The change is probably not much more than to change the constructor of J4pRemoteException and add a property (the exception is already parsed as a JSON object at that time).

Maybe for the Java Client Lib we could go even further and allow for ExceptionHandlers to be registered in the J4pClient so that sort of translation could be done automatically (but then probably only for RuntimeExceptions).
But that's something which should be thinked about later.

If you like, you can implement it (assumed that you release it under the APL) and send me a pull request. I would happily integrate it. Please don't forget some unit-tests (there are already quite some from which you can take as blueprint) 😄 and, optionally, adapt the documentation in src/docbkx/client/java.xml

I could add it, too, but probably not this week.

@marosmars

This comment has been minimized.

Contributor

marosmars commented Mar 12, 2013

Great

I will send a pull request by the end of this week.

@rhuss

This comment has been minimized.

Owner

rhuss commented Mar 15, 2013

thanks for the pull request, will be in 1.1.1

@rhuss rhuss closed this Mar 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment