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
21 import javax.servlet.http.HttpServletRequest;
\r
22 import javax.servlet.http.HttpServletResponse;
\r
24 import org.springframework.beans.factory.annotation.Autowired;
\r
25 import org.springframework.context.annotation.Bean;
\r
26 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r
27 import org.springframework.web.bind.annotation.PathVariable;
\r
28 import org.springframework.web.bind.annotation.RequestMapping;
\r
29 import org.springframework.web.bind.annotation.RequestMethod;
\r
30 import org.springframework.web.bind.annotation.RestController;
\r
31 import org.springframework.web.client.RestClientException;
\r
32 import org.springframework.web.client.RestTemplate;
\r
33 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
\r
35 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
36 import org.openecomp.portalapp.controller.EPUnRestrictedBaseController;
\r
37 import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
\r
38 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
\r
39 import org.openecomp.portalapp.portal.service.ConsulHealthService;
\r
41 @SuppressWarnings("unchecked")
\r
43 @org.springframework.context.annotation.Configuration
\r
44 @EnableAspectJAutoProxy
\r
46 public class WidgetsCatalogMarkupController extends EPUnRestrictedBaseController {
\r
48 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogMarkupController.class);
\r
49 RestTemplate template = new RestTemplate();
\r
50 String whatService = "widgets-service";
\r
54 private ConsulHealthService consulHealthService;
\r
57 public CommonsMultipartResolver multipartResolver() {
\r
58 return new CommonsMultipartResolver();
\r
62 //for localhost testing only
\r
63 javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
\r
64 new javax.net.ssl.HostnameVerifier(){
\r
66 public boolean verify(String hostname,
\r
67 javax.net.ssl.SSLSession sslSession) {
\r
68 if (hostname.equals("localhost")) {
\r
77 @RequestMapping(value = "/portalApi/microservices/markup/{widgetId}", method = RequestMethod.GET)
\r
78 public String getWidgetMarkup(HttpServletRequest request, HttpServletResponse response,
\r
79 @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
\r
80 return template.getForObject("https://" + consulHealthService.getServiceLocation(whatService) + "/widget/microservices/markup/" + widgetId, String.class,
\r
81 WidgetServiceHeaders.getInstance());
\r