interceptor

Angular Jasmine test response interceptor

我只是一个虾纸丫 提交于 2019-11-29 07:28:27
问题 I'm trying to test my response interceptor but I have a hard time figuring out how to mock the $window object. Here is my interceptor code : 'use strict'; angular.module('Domain.handlers') .config(function($httpProvider) { $httpProvider.responseInterceptors.push('UnauthorizedInterceptor'); }) .factory('UnauthorizedInterceptor', function($q, $injector, $window, ENV) { return function(promise) { var success = function(response) { return response; }; var error = function(response) { if (response

Intercept Fetch() API responses and request in Javascript

南楼画角 提交于 2019-11-29 06:31:08
I want to intercept the fetch API request and response in Javascript. For ex: Before sending the request want to intercept the request URL and once get the response wants to intercept the response. The below code is for intercepting response of All XMLHTTPRequest. (function(open) { XMLHttpRequest.prototype.open = function(XMLHttpRequest) { var self = this; this.addEventListener("readystatechange", function() { if (this.responseText.length > 0 && this.readyState == 4 && this.responseURL.indexOf('www.google.com') >= 0) { Object.defineProperty(self, 'response', { get: function() { return bValue;

Interceptor method not called with interceptor binding

亡梦爱人 提交于 2019-11-29 06:12:12
I'm using Java EE 6 & Jboss AS7.1 and try to use interceptor binding ( Example from jboss site ). I have an InterceptorBinding annotation: @InterceptorBinding @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface GeoRestrictedEquipment { } The interceptor: @GeoRestrictedEquipment @Interceptor public class GeoRestrictedEquipmentInterceptor { @EJB EquipmentDao equipmenttDao; @EJB SecurityService securityService; @AroundInvoke public Object checker(InvocationContext ctx) throws Exception { Integer id = (Integer) ctx.getParameters()[0]; Equipment

Interceptor Angular 4.3 - Set multiple headers on the cloned request

。_饼干妹妹 提交于 2019-11-29 05:30:06
I just noticed that the Header Object that was possible to use in the previous HTTP RequestsOption is not anymore supported in the new Interceptor. It's the new Interceptor logic: // Get the auth header from the service. const authHeader = this.auth.getAuthorizationHeader(); // Clone the request to add the new header. const authReq = req.clone({headers: req.headers.set('Authorization', authHeader)}); I have, now, two ways to add my headers in this request: Example: headers?: HttpHeaders; headers: req.headers.set('token1', 'asd') setHeaders?: { [name: string]: string | string[]; }; setHeaders:

Castle Windsor intercept method call from within the class

家住魔仙堡 提交于 2019-11-29 05:14:54
We have components registrations in Castle Windsor container like so void RegisterComponent<TInterface, TImplementation>() { var component = Component.For<TInterface>().ImplementedBy<TImplementation>(); component.Interceptors<SomeInterceptor>(); container.Register(component); } However we got to the problem that when we do a method call from within the class it does not get intercepted. For example we have component like ServiceA : IService { public void MethodA1() { // do some stuff } public void MethodA2() { MethodA1(); } } And if we call MethodA2 or MethodA1 methods from some other class it

关于数据脱敏的两种解决方案之一基于mybatis Interceptor的脱敏

痴心易碎 提交于 2019-11-29 04:10:59
这是我根据网上资料整理的两种数据脱敏解决方案,各有千秋,都在我都实际环境中使用了,来自网络,回归网络,希望对读到的朋友有帮助。废话少说,下面就开始贴代码 /** * 脱敏注解 * */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Desensitization { /** * 脱敏规则类型 * @return */ DesensitionType type(); /** * 附加值, 自定义正则表达式等 * @return */ String[] attach() default ""; } /** * 脱敏规则枚举 * */ public enum DesensitionType { PHONE("phone", "11位手机号", "^(\\d{3})\\d{4}(\\d{4})$", "$1****$2"), //注意后四位的表达式,因为有的身份证最后一位是X ID_CARD("idCard", "16或者18身份证号", "^(\\d{4})\\d{8,10}(\\w{4})$", "$1****$2"), BANK_CARD("bankCardNo", "银行卡号", "^(\\d{4})\\d*(\\d{4})$", "$1****$2"), REAL

Interceptor in JSF

穿精又带淫゛_ 提交于 2019-11-29 02:14:00
I want to know if there is an interceptor in JSF (like we use in Spring), and how to do we implement it? You could implement a PhaseListener for this. You could program them to listen on a specific JSF phase which you specify in the overridden getPhaseId() method. You can intercept on the before and after phase events by beforePhase() and afterPhase() methods. The below example listens on the render response phase: public class RequestInterceptor implements PhaseListener { @Override public PhaseId getPhaseId() { return PhaseId.RENDER_RESPONSE; } @Override public void beforePhase(PhaseEvent

Angular.js $http intercept “net::ERR_CONNECTION_REFUSED”

一个人想着一个人 提交于 2019-11-29 02:07:10
问题 I'm trying to write a generic error handler for my website using $http' s interceptors but they don't seem to be able to do what I want to do. I placed interceptors on 'response' and 'responseError' but they never get called when the server is offline/not reponding (net::ERR_CONNECTION_REFUSED). I understand why this happens, there's no response to intercept. I'd like to know if there's a generic way of catching these errors, other than listening to the $httpPromise 's error callback for each

Alternative of $httpProvider.responseInterceptors

放肆的年华 提交于 2019-11-29 01:52:32
问题 What is alternative of $httpProvider.responseInterceptors as it is discontinued in AngularJS V1.3? My interceptors which was working with Angular JS 1.2 is now not working with version 1.3 var angularErrorHandling = angular.module('xx-http-error-handling', []); angularErrorHandling.config(function ($provide, $httpProvider, $compileProvider) { var elementsList = $(); push function to the responseInterceptors which will intercept the http responses of the whole application $httpProvider

Automating access token refreshing via interceptors in axios

折月煮酒 提交于 2019-11-29 01:30:40
问题 We've recently discussed an axios' interceptor for OAuth authentication token refresh in this question. Basically, what the interceptor should do is to intercept any response with 401 status code and try to refresh the token. With that in mind, the next thing to do is to return a Promise from the interceptor, so that any request which would have normally fail, would run as nothing happens after a token refresh. The main problem is, that an interceptor checks only the 401 status code, which is