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 org.onap.aaf.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 org.onap.aaf.authz.env.AuthzTrans;
\r
31 import org.onap.aaf.authz.gw.GwAPI;
\r
32 import org.onap.aaf.authz.gw.GwCode;
\r
33 import org.onap.aaf.authz.gw.facade.GwFacade;
\r
34 import org.onap.aaf.authz.gw.mapper.Mapper.API;
\r
35 import org.onap.aaf.cssa.rserv.HttpMethods;
\r
37 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
\r
38 import org.onap.aaf.cadi.CadiException;
\r
39 import org.onap.aaf.cadi.client.Future;
\r
40 import org.onap.aaf.cadi.client.Rcli;
\r
41 import org.onap.aaf.cadi.client.Retryable;
\r
42 import org.onap.aaf.cadi.config.Config;
\r
43 import org.onap.aaf.inno.env.APIException;
\r
44 import org.onap.aaf.inno.env.Env;
\r
45 import org.onap.aaf.inno.env.TimeTaken;
\r
48 * API Apis.. using Redirect for mechanism
\r
52 public class API_Proxy {
\r
55 * Normal Init level APIs
\r
61 public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception {
\r
63 String aafurl = gwAPI.env.getProperty(Config.AAF_URL);
\r
68 // Transferring APIs
\r
70 gwAPI.routeAll(HttpMethods.GET,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy GET", true) {
\r
72 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
73 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
75 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
77 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
78 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
\r
79 ft.get(10000); // Covers return codes and err messages
\r
84 } catch (CadiException | APIException e) {
\r
85 trans.error().log(e);
\r
92 gwAPI.routeAll(HttpMethods.POST,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy POST", true) {
\r
94 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
95 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
97 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
99 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
100 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.CREATED_201);
\r
101 ft.get(10000); // Covers return codes and err messages
\r
105 } catch (CadiException | APIException e) {
\r
106 trans.error().log(e);
\r
113 gwAPI.routeAll(HttpMethods.PUT,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy PUT", true) {
\r
115 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
116 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
118 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
120 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
121 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
\r
122 ft.get(10000); // Covers return codes and err messages
\r
126 } catch (CadiException | APIException e) {
\r
127 trans.error().log(e);
\r
134 gwAPI.routeAll(HttpMethods.DELETE,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy DELETE", true) {
\r
136 public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
\r
137 TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
\r
139 gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
\r
141 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
\r
142 Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
\r
143 ft.get(10000); // Covers return codes and err messages
\r
147 } catch (CadiException | APIException e) {
\r
148 trans.error().log(e);
\r