2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 package org.openecomp.portalapp.portal.controller;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
25 import org.openecomp.portalapp.controller.EPUnRestrictedBaseController;
26 import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
27 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
28 import org.openecomp.portalapp.portal.service.ConsulHealthService;
29 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
30 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
31 import org.openecomp.portalsdk.core.util.SystemProperties;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestMethod;
38 import org.springframework.web.bind.annotation.RestController;
39 import org.springframework.web.client.RestClientException;
40 import org.springframework.web.client.RestTemplate;
41 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
44 @org.springframework.context.annotation.Configuration
45 @EnableAspectJAutoProxy
47 public class WidgetsCatalogMarkupController extends EPUnRestrictedBaseController {
49 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogMarkupController.class);
50 private RestTemplate template = new RestTemplate();
51 private final String whatService = "widgets-service";
54 private ConsulHealthService consulHealthService;
57 public CommonsMultipartResolver multipartResolver() {
58 return new CommonsMultipartResolver();
62 // for localhost testing only
63 javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
65 public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
66 if (hostname.equals("localhost")) {
74 @RequestMapping(value = "/portalApi/microservices/markup/{widgetId}", method = RequestMethod.GET)
75 public String getWidgetMarkup(HttpServletRequest request, HttpServletResponse response,
76 @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
79 EcompPortalUtils.widgetMsProtocol() + "://"
80 + consulHealthService.getServiceLocation(whatService,
81 SystemProperties.getProperty("microservices.widget.local.port"))
82 + "/widget/microservices/markup/" + widgetId,
83 String.class, WidgetServiceHeaders.getInstance());