I am using Castle's DynamicProxy to intercept method calls. Before executing the target with
invocation.Proceed();
I check if the result is already in the cache. If so I do not want to call invocation.Proceed . However I do want to execute other interceptors for instance if there is a timing interceptor registered but because I am not calling invocation.Proceed if I found the results in the cache it never get's called. Is there a way around this? Or would I just have to add the timing interceptor to the caching interceptor as well?
Put caching interceptor last in the pipeline.
Related
I want to mock out a situation where if the service is called with a specific set of inputs, it should return a value, but if it's called with any other inputs throw an exception. So I've got:
doThrow(new ValidationException()).when(mockService).thing(any(), any());
when(mockService.thing(EXPECTED_PARAM_1, EXPECTED_PARAM_2).thenReturn(mockResult);
But when I go to run my test it throws the ValidationException on that second line where I'm creating the mock. It seems as though that second line is being treated as if I was actually calling the service, and since I'm mocking it with params that fit the any() any() it's throwing the exception rather than setting up the additional mock.
Thanks!
It turns out when.thenReturn actually calls the method it's mocking exactly once when the mock is first setup. Since the previous mock setup the default scenario where anytime the method is called it should thrown the exception, the second mock when it does its initial single call triggers the first mock and throws.
The solution to this scenario is to switch the second mock to use doReturn.when instead, as it never actually calls the method.
Accessing the local filesystem a la: https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle
If I inline all my code for the show(Open|Save)FilePicker API logic directly in my button event closure or call plain fn's then things work ok. However, if I define a class w/helper methods and call those from my event-handler, and those helpers call the file pickers, then I get this error:
Uncaught DOMException: Failed to execute 'showOpenFilePicker' on 'Window': Must be handling a user gesture to show a file picker.
I assume the the security system is looking at this to establish the gesture context - is there a way to re-establish this context with code running in my class?
Turns out the class methods were a red herring -- the issue has to do with async code and promises -- this is what looses the context and causes the error.
You need to make any calls to the FS without any promise chaining.
I've a View and Utility classes and wanted to hook-in the Utility method once View's job is done. So wanted to call the utility method (to add behavior to the view) once View's render call is done.
Using ES6 Proxy API, Is there a way to execute a method before / after executing the main method ? (aka method interceptions)
Similar to YUI3 Do API.
http://yuilibrary.com/yui/docs/api/classes/Do.html
Yes there is a way. Actually I'm trying to build the same thing and as long as you use a synchronous context I already got it working. Have a look at the code examples in the issue I created for my problem: stack overflow when returning an ES6 proxy through a promise
What you need to do to intercept the call is to use the ES6 proxy to get notified of the get-call that takes place to retrieve the function before the method is actually called.
In my example you can see that you get all the information about the call like what method was called with which parameters and also who called it and on which target it was originally called.
I created a custom component for a proprietary service. If this service is down i get noticed via a call of a callback function. I am throwing a custom exception at this point.
Sending exchanges to the producer/ consumer will yield no errors or exceptions (all seems to fine).
So i need to implement an emergency stop if my custom exception is thrown. I read a bit about exception handling in camel. I think i need a context-scoped onException(MyException.class).??? but what then?
Is this working on exceptions that are called without relation to an exchange? If this is working how to handle it. I want to stop certain routes in this case.
here you can find to stop routes from a route: http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html.
If you do the call of the proprietary service in a route you do have an exchange btw.
kind regards,
soilworker
I created a little workaround: I set a boolean i the callback method is called. On each call of process i check this boolean and if true i throw an exception.
With this the exception is within normal camel exception handling and onException could be used.
I search for a long time, but I still not found the answer.
In common case, we keep the token of a remote method call, Flex -> Java for example.
But, if the client know that the current call is not needed anymore, how stopping the server processing ?
With an asyncToken, is it possible to stop a remote call ?
Thanks for your answer.
As I understood it, an AsyncToken just provides extra data for some operation. You'll need to access that operation to cancel.
IF you're calling an HTTPService, you use the cancel() method.
If you're using a WebService, you should be able to call getOperation() method and then cancel() the corresponding operation.
If you're using a RemoteObject you should be able to call getOperation() method and then cancel() on the corresponding operation.