1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.authz.gw.api;
\r
25 import java.net.ConnectException;
\r
27 import javax.servlet.http.HttpServletRequest;
\r
28 import javax.servlet.http.HttpServletResponse;
\r
30 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
\r
31 import com.att.authz.env.AuthzTrans;
\r
32 import com.att.authz.gw.GwAPI;
\r
33 import com.att.authz.gw.GwCode;
\r
34 import com.att.authz.gw.facade.GwFacade;
\r
35 import com.att.authz.gw.mapper.Mapper.API;
\r
36 import com.att.cadi.CadiException;
\r
37 import com.att.cadi.client.Future;
\r
38 import com.att.cadi.client.Rcli;
\r
39 import com.att.cadi.client.Retryable;
\r
40 import com.att.cadi.config.Config;
\r
41 import com.att.cssa.rserv.HttpMethods;
\r
42 import com.att.inno.env.APIException;
\r
43 import com.att.inno.env.Env;
\r
44 import com.att.inno.env.TimeTaken;
\r
47 * API Apis.. using Redirect for mechanism
\r
51 public class API_Proxy {
\r
54 * Normal Init level APIs
\r
60 public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception {
\r
62 String aafurl = gwAPI.env.getProperty(Config.AAF_URL);
\r
67 // Transferring APIs
\r
69 gwAPI.routeAll(HttpMethods.GET,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy GET", true) {
\r
71 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
72 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
74 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
76 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
77 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
\r
78 ft.get(10000); // Covers return codes and err messages
\r
83 } catch (CadiException | APIException e) {
\r
84 trans.error().log(e);
\r
91 gwAPI.routeAll(HttpMethods.POST,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy POST", true) {
\r
93 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
94 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
96 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
98 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
99 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.CREATED_201);
\r
100 ft.get(10000); // Covers return codes and err messages
\r
104 } catch (CadiException | APIException e) {
\r
105 trans.error().log(e);
\r
112 gwAPI.routeAll(HttpMethods.PUT,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy PUT", true) {
\r
114 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
115 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
117 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
119 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
120 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
\r
121 ft.get(10000); // Covers return codes and err messages
\r
125 } catch (CadiException | APIException e) {
\r
126 trans.error().log(e);
\r
133 gwAPI.routeAll(HttpMethods.DELETE,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy DELETE", true) {
\r
135 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
136 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
138 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
140 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
141 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
\r
142 ft.get(10000); // Covers return codes and err messages
\r
146 } catch (CadiException | APIException e) {
\r
147 trans.error().log(e);
\r