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.common.Define;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.layer.Result;
33 import org.onap.aaf.auth.locate.AAF_Locate;
34 import org.onap.aaf.auth.locate.LocateCode;
35 import org.onap.aaf.auth.locate.facade.LocateFacade;
36 import org.onap.aaf.auth.locate.mapper.Mapper.API;
37 import org.onap.aaf.auth.rserv.HttpMethods;
38 import org.onap.aaf.misc.env.util.Split;
41 * API Apis.. using Redirect for mechanism
46 public class API_Find {
48 * Normal Init level APIs
54 public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
59 final LocateCode locationInfo = new LocateCode(facade,"Location Information", true) {
61 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
62 String service = pathParam(req, ":service");
63 String version = pathParam(req, ":version");
64 String other = pathParam(req, ":other");
65 if (service.indexOf(':')>=0) {
66 String split[] = Split.split(':', service);
67 switch(split.length) {
75 service=Define.varReplace(service);
76 Result<Void> r = context.getEndpoints(trans,resp,
77 req.getPathInfo(), // use as Key
82 resp.setStatus(HttpStatus.OK_200);
85 context.error(trans,resp,r);
90 gwAPI.route(HttpMethods.GET,"/locate/:service/:version",API.ENDPOINTS,locationInfo);
91 gwAPI.route(HttpMethods.GET,"/locate/:service/:version/:other",API.ENDPOINTS,locationInfo);
92 gwAPI.route(HttpMethods.GET,"/locate/:service",API.ENDPOINTS,locationInfo);
95 gwAPI.route(HttpMethods.GET,"/download/agent", API.VOID, new LocateCode(facade,"Redirect to latest Agent",false) {
97 public void handle(AuthzTrans arg0, HttpServletRequest arg1, HttpServletResponse arg2) throws Exception {
101 gwAPI.route(HttpMethods.PUT,"/registration",API.MGMT_ENDPOINTS,new LocateCode(facade,"Put Location Information", true) {
103 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
104 Result<Void> r = context.putMgmtEndpoints(trans,req,resp);
107 resp.setStatus(HttpStatus.OK_200);
110 context.error(trans,resp,r);
116 gwAPI.route(HttpMethods.DELETE,"/registration",API.MGMT_ENDPOINTS,new LocateCode(facade,"Remove Location Information", true) {
118 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
119 Result<Void> r = context.removeMgmtEndpoints(trans,req,resp);
122 resp.setStatus(HttpStatus.OK_200);
125 context.error(trans,resp,r);