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.URI;
\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.authz.layer.Result;
\r
36 import org.onap.aaf.cssa.rserv.HttpMethods;
\r
38 import org.onap.aaf.cadi.Locator;
\r
39 import org.onap.aaf.cadi.Locator.Item;
\r
40 import org.onap.aaf.cadi.LocatorException;
\r
41 import org.onap.aaf.cadi.dme2.DME2Locator;
\r
44 * API Apis.. using Redirect for mechanism
\r
48 public class API_Find {
\r
50 * Normal Init level APIs
\r
56 public static void init(final GwAPI gwAPI, GwFacade facade) throws Exception {
\r
60 gwAPI.route(HttpMethods.GET,"/dme2/:service/:version/:envContext/:routeOffer/:path*",API.VOID,new GwCode(facade,"Document API", true) {
\r
62 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
\r
63 //TODO cache this...
\r
65 Locator loc = new DME2Locator(gwAPI.env, gwAPI.dme2Man,
\r
66 pathParam(req,":service"),
\r
67 pathParam(req,":version"),
\r
68 pathParam(req,":envContext"),
\r
69 pathParam(req,":routeOffer")
\r
71 if(loc.hasItems()) {
\r
72 Item item = loc.best();
\r
73 URI uri = (URI) loc.get(item);
\r
74 String redirectURL = uri.toString() + '/' + pathParam(req,":path");
\r
75 trans.warn().log("Redirect to",redirectURL);
\r
76 resp.sendRedirect(redirectURL);
\r
78 context.error(trans, resp, Result.err(Result.ERR_NotFound,"%s is not valid",req.getPathInfo()));
\r
80 } catch (LocatorException e) {
\r
81 context.error(trans, resp, Result.err(Result.ERR_NotFound,"No DME2 Endpoints found for %s",req.getPathInfo()));
\r