2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\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 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.controller;
\r
22 import java.util.List;
\r
24 import javax.servlet.http.HttpServletRequest;
\r
25 import javax.servlet.http.HttpServletResponse;
\r
27 import org.openecomp.portalapp.controller.EPUnRestrictedBaseController;
\r
28 import org.openecomp.portalapp.portal.domain.EPUser;
\r
29 import org.openecomp.portalapp.portal.domain.WidgetParameterResult;
\r
30 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
\r
31 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
\r
32 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
\r
33 import org.openecomp.portalapp.portal.service.MicroserviceProxyService;
\r
34 import org.openecomp.portalapp.util.EPUserUtils;
\r
35 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
36 import org.springframework.beans.factory.annotation.Autowired;
\r
37 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r
38 import org.springframework.web.bind.annotation.PathVariable;
\r
39 import org.springframework.web.bind.annotation.RequestMapping;
\r
40 import org.springframework.web.bind.annotation.RequestMethod;
\r
41 import org.springframework.web.bind.annotation.RestController;
\r
42 import org.springframework.web.client.HttpClientErrorException;
\r
44 import com.fasterxml.jackson.core.JsonProcessingException;
\r
45 import com.fasterxml.jackson.databind.ObjectMapper;
\r
47 @SuppressWarnings("unchecked")
\r
49 @org.springframework.context.annotation.Configuration
\r
50 @EnableAspectJAutoProxy
\r
52 public class MicroserviceProxyController extends EPUnRestrictedBaseController {
\r
55 private MicroserviceProxyService microserviceProxyService;
\r
57 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MicroserviceProxyController.class);
\r
59 @RequestMapping(value = { "/portalApi/microservice/proxy/{serviceId}" }, method = {
\r
60 RequestMethod.GET }, produces = "application/json")
\r
61 public String getMicroserviceProxy(HttpServletRequest request, HttpServletResponse response,
\r
62 @PathVariable("serviceId") long serviceId) throws Exception {
\r
63 EPUser user = EPUserUtils.getUserSession(request);
\r
66 answer = microserviceProxyService.proxyToDestination(serviceId, user, request);
\r
67 }catch(HttpClientErrorException e){
\r
68 //Check whether the error message is valid JSON format
\r
69 boolean valid = true;
\r
70 ObjectMapper objectMapper = new ObjectMapper();
\r
72 objectMapper.readTree(e.getResponseBodyAsString());
\r
73 } catch(JsonProcessingException exception){
\r
77 return e.getResponseBodyAsString();
\r
79 return "{\"error\":\""+ e.getResponseBodyAsString() +"\"}";
\r
84 @RequestMapping(value = { "/portalApi/microservice/proxy/parameter/{widgetId}" }, method = {
\r
85 RequestMethod.GET }, produces = "application/json")
\r
86 public String getMicroserviceProxyByWidgetId(HttpServletRequest request, HttpServletResponse response,
\r
87 @PathVariable("widgetId") long widgetId) throws Exception {
\r
88 EPUser user = EPUserUtils.getUserSession(request);
\r
91 answer = microserviceProxyService.proxyToDestinationByWidgetId(widgetId, user, request);
\r
92 }catch(HttpClientErrorException e){
\r
93 //Check whether the error message is valid JSON format
\r
94 boolean valid = true;
\r
95 ObjectMapper objectMapper = new ObjectMapper();
\r
97 objectMapper.readTree(e.getResponseBodyAsString());
\r
98 } catch(JsonProcessingException exception){
\r
102 return e.getResponseBodyAsString();
\r
104 return "{\"error\":\""+ e.getResponseBodyAsString() +"\"}";
\r