--- /dev/null
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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 com.att.authz.gw.api;\r
+\r
+import java.net.URI;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import com.att.authz.env.AuthzTrans;\r
+import com.att.authz.gw.GwAPI;\r
+import com.att.authz.gw.GwCode;\r
+import com.att.authz.gw.facade.GwFacade;\r
+import com.att.authz.gw.mapper.Mapper.API;\r
+import com.att.authz.layer.Result;\r
+import com.att.cadi.Locator;\r
+import com.att.cadi.Locator.Item;\r
+import com.att.cadi.LocatorException;\r
+import com.att.cadi.dme2.DME2Locator;\r
+import com.att.cssa.rserv.HttpMethods;\r
+\r
+/**\r
+ * API Apis.. using Redirect for mechanism\r
+ * \r
+ *\r
+ */\r
+public class API_Find {\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
+ // Overall APIs\r
+ ///////\r
+ gwAPI.route(HttpMethods.GET,"/dme2/:service/:version/:envContext/:routeOffer/:path*",API.VOID,new GwCode(facade,"Document API", true) {\r
+ @Override\r
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {\r
+ //TODO cache this...\r
+ try {\r
+ Locator loc = new DME2Locator(gwAPI.env, gwAPI.dme2Man, \r
+ pathParam(req,":service"),\r
+ pathParam(req,":version"),\r
+ pathParam(req,":envContext"),\r
+ pathParam(req,":routeOffer")\r
+ );\r
+ if(loc.hasItems()) {\r
+ Item item = loc.best();\r
+ URI uri = (URI) loc.get(item);\r
+ String redirectURL = uri.toString() + '/' + pathParam(req,":path");\r
+ trans.warn().log("Redirect to",redirectURL);\r
+ resp.sendRedirect(redirectURL);\r
+ } else {\r
+ context.error(trans, resp, Result.err(Result.ERR_NotFound,"%s is not valid",req.getPathInfo()));\r
+ }\r
+ } catch (LocatorException e) {\r
+ context.error(trans, resp, Result.err(Result.ERR_NotFound,"No DME2 Endpoints found for %s",req.getPathInfo()));\r
+ }\r
+ }\r
+ });\r
+\r
+ }\r
+}\r