AngularJS Intercept all $http JSON responses

You can intercept responses by adding an interceptor to $httpProvider.interceptors with Angular 1.1.4+ (see documentation here search for interceptors). For a specific content type like json you can potentially reject changes or throw an exception even if the call was a success. You can modify the response.data that will get passed to your controller code … Read more

Advanced Wildcard Mappings Parameters not found in Prepare() method

That parameters are not set by the ParametersInterceptor (like those coming from the JSP), but by the StaticParametersInterceptor.To have them filled in the prepare() method, the same trick of the paramsPrepareParamsStack must be applied. Since there is not an Interceptor Stack that does that out-of-the-box, you must define it.Starting from the defaultStack, we should create … Read more

How To Modify The Raw XML message of an Outbound CXF Request?

Based on the first comment, I created an abstract class which can easily be used to change the whole soap envelope. Just in case someone wants a ready-to-use code part. import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.commons.io.IOUtils; import org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor; import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.apache.log4j.Logger; /** * http://www.mastertheboss.com/jboss-web-services/apache-cxf-interceptors * http://stackoverflow.com/questions/6915428/how-to-modify-the-raw-xml-message-of-an-outbound-cxf-request … Read more

I need two instances of AngularJS $http service or what?

1. Circular dependency problem. So, why does the error appear? Here is a quick overview of the process: $http service is requested. $httpProvider is asked to construct it. During construction you register interceptor, that requests $http service not existing yet. You get “Circular dependency” error. First solution. Create your dependency using angular.injector(). Notice, that you … Read more

Intercept fetch() API requests and responses in JavaScript

Existing answers show the general structure for mocking fetch in the browser but omit important details. The accepted answer shows the general pattern for replacing the window.fetch function with custom implementation that intercepts the call and forwards the arguments to fetch. However, the pattern shown doesn’t let the interception function do anything with the response … Read more

Spring HandlerInterceptor vs Servlet Filters

The org.springframework.web.servlet.HanderInterceptor Interface JavaDoc itself has a two paragraphs that discuss this question: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow … Read more

How to use angular2 http API for tracking upload/download progress

As of Angular 4.3.x and beyond versions, it can be achieved using the new HttpClient from @angular/common/http. Read the Listening to progress events section. Simple upload example (copied from the section mentioned above): const req = new HttpRequest(‘POST’, ‘/upload/file’, file, { reportProgress: true, }); http.request(req).subscribe(event => { // Via this API, you get access to … Read more