Add portal property; correct docker build script.
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / WidgetsCatalogMarkupController.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.controller;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
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;
42
43 @RestController
44 @org.springframework.context.annotation.Configuration
45 @EnableAspectJAutoProxy
46 @EPAuditLog
47 public class WidgetsCatalogMarkupController extends EPUnRestrictedBaseController {
48
49         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogMarkupController.class);
50         private RestTemplate template = new RestTemplate();
51         private final String whatService = "widgets-service";
52
53         @Autowired
54         private ConsulHealthService consulHealthService;
55
56         @Bean
57         public CommonsMultipartResolver multipartResolver() {
58                 return new CommonsMultipartResolver();
59         }
60
61         static {
62                 // for localhost testing only
63                 javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
64
65                         public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
66                                 if (hostname.equals("localhost")) {
67                                         return true;
68                                 }
69                                 return false;
70                         }
71                 });
72         }
73
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 {
77                 return template
78                                 .getForObject(
79                                                 EcompPortalUtils.widgetMsProtocol() + "://"
80                                                                 + consulHealthService.getServiceLocation(whatService,
81                                                                                 SystemProperties.getProperty("microservices.widget.local.port"))
82                                                                 + "/widget/microservices/markup/" + widgetId,
83                                                 String.class, WidgetServiceHeaders.getInstance());
84         }
85 }