--- /dev/null
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ * * http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ * * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.authz.gw.api;\r
+\r
+import java.net.ConnectException;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.onap.aaf.authz.env.AuthzTrans;\r
+import org.onap.aaf.authz.gw.GwAPI;\r
+import org.onap.aaf.authz.gw.GwCode;\r
+import org.onap.aaf.authz.gw.facade.GwFacade;\r
+import org.onap.aaf.authz.gw.mapper.Mapper.API;\r
+import org.onap.aaf.cssa.rserv.HttpMethods;\r
+\r
+import com.att.aft.dme2.internal.jetty.http.HttpStatus;\r
+import org.onap.aaf.cadi.CadiException;\r
+import org.onap.aaf.cadi.client.Future;\r
+import org.onap.aaf.cadi.client.Rcli;\r
+import org.onap.aaf.cadi.client.Retryable;\r
+import org.onap.aaf.cadi.config.Config;\r
+import org.onap.aaf.inno.env.APIException;\r
+import org.onap.aaf.inno.env.Env;\r
+import org.onap.aaf.inno.env.TimeTaken;\r
+\r
+/**\r
+ * API Apis.. using Redirect for mechanism\r
+ * \r
+ *\r
+ */\r
+public class API_Proxy {\r
+\r
+ /**\r
+ * Normal Init level APIs\r
+ * \r
+ * @param gwAPI\r
+ * @param facade\r
+ * @throws Exception\r
+ */\r
+ public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception {\r
+ \r
+ String aafurl = gwAPI.env.getProperty(Config.AAF_URL);\r
+ if(aafurl==null) {\r
+ } else {\r
+\r
+ ////////\r
+ // Transferring APIs\r
+ ///////\r
+ gwAPI.routeAll(HttpMethods.GET,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy GET", true) {\r
+ @Override\r
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {\r
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);\r
+ try {\r
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {\r
+ @Override\r
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {\r
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);\r
+ ft.get(10000); // Covers return codes and err messages\r
+ return null;\r
+ }\r
+ });\r
+ \r
+ } catch (CadiException | APIException e) {\r
+ trans.error().log(e);\r
+ } finally {\r
+ tt.done();\r
+ }\r
+ }\r
+ });\r
+ \r
+ gwAPI.routeAll(HttpMethods.POST,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy POST", true) {\r
+ @Override\r
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {\r
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);\r
+ try {\r
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {\r
+ @Override\r
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {\r
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.CREATED_201);\r
+ ft.get(10000); // Covers return codes and err messages\r
+ return null;\r
+ }\r
+ });\r
+ } catch (CadiException | APIException e) {\r
+ trans.error().log(e);\r
+ } finally {\r
+ tt.done();\r
+ }\r
+ }\r
+ });\r
+ \r
+ gwAPI.routeAll(HttpMethods.PUT,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy PUT", true) {\r
+ @Override\r
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {\r
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);\r
+ try {\r
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {\r
+ @Override\r
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {\r
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);\r
+ ft.get(10000); // Covers return codes and err messages\r
+ return null;\r
+ }\r
+ });\r
+ } catch (CadiException | APIException e) {\r
+ trans.error().log(e);\r
+ } finally {\r
+ tt.done();\r
+ }\r
+ }\r
+ });\r
+ \r
+ gwAPI.routeAll(HttpMethods.DELETE,"/proxy/:path*",API.VOID,new GwCode(facade,"Proxy DELETE", true) {\r
+ @Override\r
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {\r
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);\r
+ try {\r
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {\r
+ @Override\r
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {\r
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);\r
+ ft.get(10000); // Covers return codes and err messages\r
+ return null;\r
+ }\r
+ });\r
+ } catch (CadiException | APIException e) {\r
+ trans.error().log(e);\r
+ } finally {\r
+ tt.done();\r
+ }\r
+ }\r
+ });\r
+ }\r
+ }\r
+}\r