2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 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
21 package org.openecomp.vid.controller.test;
\r
23 import java.io.IOException;
\r
25 import javax.servlet.http.HttpServletRequest;
\r
26 import javax.servlet.http.HttpServletResponse;
\r
28 import org.codehaus.jackson.map.ObjectMapper;
\r
29 import org.openecomp.vid.model.ExceptionResponse;
\r
30 import org.springframework.web.bind.annotation.ExceptionHandler;
\r
31 import org.springframework.web.bind.annotation.PathVariable;
\r
32 import org.springframework.web.bind.annotation.RequestMapping;
\r
33 import org.springframework.web.bind.annotation.RequestMethod;
\r
34 import org.springframework.web.bind.annotation.RestController;
\r
36 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
\r
39 * The Class TestAsdcController.
\r
42 @RequestMapping("testasdc")
\r
43 public class TestAsdcController extends RestrictedBaseController {
\r
48 * @param modelId the model id
\r
49 * @param request the request
\r
51 * @throws Exception the exception
\r
53 @RequestMapping(value = "/getModel/{modelId}", method = RequestMethod.GET)
\r
54 public String getModel(@PathVariable("modelId") String modelId, HttpServletRequest request) throws Exception {
\r
56 System.err.println("SDC: GET MODEL: modelId: " + modelId);
\r
61 "\"uuid\": \"5be686dc-fdca-4d54-8548-5d0ed23e962b\"," +
\r
62 "\"invariantUUID\": \"e5962da9-fe4f-433a-bc99-b43e0d88a9a1\"," +
\r
63 "\"name\": \"DE220127\"," +
\r
64 "\"version\": \"0.1\"," +
\r
66 "\"defaultGateway\": {" +
\r
67 "\"type\": \"String\"," +
\r
68 "\"default\": \"192.168.1.1\"," +
\r
69 "\"description\": \"Router default gateway - use any valid IPv4 address\"" +
\r
71 "\"subnetMask\": {" +
\r
72 "\"type\": \"String\"," +
\r
73 "\"default\": \"255.255.255.0\"," +
\r
74 "\"description\": \"Router subnet mask - example (255.255.255.0)\"" +
\r
85 * @param response the response
\r
86 * @throws IOException Signals that an I/O exception has occurred.
\r
88 @ExceptionHandler(Exception.class)
\r
89 private void exception(Exception e, HttpServletResponse response) throws IOException {
\r
92 * This logging step should preferably be replaced with an appropriate
\r
93 * logging method consistent whatever logging mechanism the rest of the
\r
94 * application code uses.
\r
97 e.printStackTrace(System.err);
\r
99 response.setContentType("application/json; charset=UTF-8");
\r
100 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
\r
102 ExceptionResponse exceptionResponse = new ExceptionResponse();
\r
103 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
\r
104 exceptionResponse.setMessage(e.getMessage());
\r
106 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
\r
108 response.flushBuffer();
\r