2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.locate.api;
24 import static org.onap.aaf.auth.layer.Result.OK;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
29 import org.eclipse.jetty.http.HttpStatus;
30 import org.onap.aaf.auth.env.AuthzTrans;
31 import org.onap.aaf.auth.layer.Result;
32 import org.onap.aaf.auth.locate.AAF_Locate;
33 import org.onap.aaf.auth.locate.LocateCode;
34 import org.onap.aaf.auth.locate.facade.LocateFacade;
35 import org.onap.aaf.auth.locate.mapper.Mapper.API;
36 import org.onap.aaf.auth.rserv.HttpMethods;
37 import org.onap.aaf.cadi.Symm;
44 public class API_Api {
46 * Normal Init level APIs
52 public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
56 gwAPI.route(HttpMethods.GET,"/api",API.VOID,new LocateCode(facade,"Document API", true) {
58 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
59 Result<Void> r = context.getAPI(trans,resp,gwAPI);
62 resp.setStatus(HttpStatus.OK_200);
65 context.error(trans,resp,r);
74 gwAPI.route(HttpMethods.GET,"/api/example/*",API.VOID,new LocateCode(facade,"Document API", true) {
76 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
77 String pathInfo = req.getPathInfo();
78 int question = pathInfo.lastIndexOf('?');
80 pathInfo = pathInfo.substring(13, question<0?pathInfo.length():question);// IMPORTANT, this is size of "/api/example/"
81 String nameOrContextType=Symm.base64noSplit.decode(pathInfo);
82 // String param = req.getParameter("optional");
83 Result<Void> r = context.getAPIExample(trans,resp,nameOrContextType,
84 question>=0 && "optional=true".equalsIgnoreCase(req.getPathInfo().substring(question+1))
88 resp.setStatus(HttpStatus.OK_200);
91 context.error(trans,resp,r);