diff options
author | Tal Gitelman <tg851x@intl.att.com> | 2017-06-29 19:30:00 +0300 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-06-29 21:32:19 +0300 |
commit | ed7e1c3dfe332abc67ed943717db2ee94406f95e (patch) | |
tree | e0f2f39596656456272900f59aadc3dff6c6e828 /catalog-ui/src/app/ng2/services/http.interceptor.service.ts | |
parent | 68ccc45de18f41cddb79de33a245bceb3b063ffb (diff) |
[SDC] rebase code
Change-Id: I456ec65a233d277e6bae35e140f2e3da5765bae6
Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-ui/src/app/ng2/services/http.interceptor.service.ts')
-rw-r--r-- | catalog-ui/src/app/ng2/services/http.interceptor.service.ts | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/catalog-ui/src/app/ng2/services/http.interceptor.service.ts b/catalog-ui/src/app/ng2/services/http.interceptor.service.ts new file mode 100644 index 0000000000..aebbdbf7af --- /dev/null +++ b/catalog-ui/src/app/ng2/services/http.interceptor.service.ts @@ -0,0 +1,57 @@ +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/toPromise'; +import 'rxjs/Rx'; +import { sdc2Config } from './../../../main'; +import { Interceptor, InterceptedRequest, InterceptedResponse } from 'ng2-interceptors'; +import {SharingService} from "../../services/sharing-service"; +import {ReflectiveInjector} from '@angular/core'; +import {Cookie2Service} from "./cookie.service"; +import {UUID} from "angular2-uuid"; +import {Dictionary} from "../../utils/dictionary/dictionary"; + +export class HttpInterceptor implements Interceptor { + + private cookieService: Cookie2Service; + private sharingService:SharingService; + constructor() { + let injector = ReflectiveInjector.resolveAndCreate([Cookie2Service,SharingService]); + this.cookieService = injector.get(Cookie2Service); + this.sharingService = injector.get(SharingService); + } + + public interceptBefore(request: InterceptedRequest): InterceptedRequest { + + /** + * For every request to the server, that the service id, or resource id is sent in the URL, need to pass UUID in the header. + * Check if the unique id exists in uuidMap, and if so get the UUID and add it to the header. + */ + + request.options.headers.append(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId()); + var uuidValue = this.getUuidValue(request.url); + if(uuidValue!= ''){ + request.options.headers.set('X-ECOMP-ServiceID',uuidValue); + } + request.options.headers.set('X-ECOMP-RequestID', UUID.UUID()); + return request; + + } + + public interceptAfter(response: InterceptedResponse): InterceptedResponse { + + return response; + + } + + private getUuidValue = (url: string) :string => { + let map:Dictionary<string, string> = this.sharingService.getUuidMap(); + if (map && url.indexOf(sdc2Config.api.root) > 0) { + map.forEach((key:string) => { + if (url.indexOf(key) !== -1) { + return this.sharingService.getUuidValue(key); + } + }); + } + return ''; + } + +} |