2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
41 import java.io.FileInputStream;
42 import java.io.FileOutputStream;
43 import java.io.OutputStream;
44 import java.util.ArrayList;
45 import java.util.List;
47 import javax.servlet.ServletContext;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
51 import org.apache.commons.lang.StringUtils;
52 import org.onap.portalapp.controller.EPUnRestrictedBaseController;
53 import org.onap.portalapp.portal.domain.EPUser;
54 import org.onap.portalapp.portal.domain.MicroserviceParameter;
55 import org.onap.portalapp.portal.domain.WidgetCatalog;
56 import org.onap.portalapp.portal.domain.WidgetCatalogParameter;
57 import org.onap.portalapp.portal.domain.WidgetParameterResult;
58 import org.onap.portalapp.portal.domain.WidgetServiceHeaders;
59 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
60 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
61 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
62 import org.onap.portalapp.portal.service.WidgetMService;
63 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
64 import org.onap.portalapp.portal.utils.EcompPortalUtils;
65 import org.onap.portalapp.util.EPUserUtils;
66 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
67 import org.onap.portalsdk.core.util.SystemProperties;
68 import org.springframework.beans.factory.annotation.Autowired;
69 import org.springframework.context.annotation.Bean;
70 import org.springframework.context.annotation.EnableAspectJAutoProxy;
71 import org.springframework.core.io.FileSystemResource;
72 import org.springframework.http.HttpEntity;
73 import org.springframework.http.HttpHeaders;
74 import org.springframework.http.HttpMethod;
75 import org.springframework.http.MediaType;
76 import org.springframework.http.ResponseEntity;
77 import org.springframework.util.LinkedMultiValueMap;
78 import org.springframework.util.MultiValueMap;
79 import org.springframework.web.bind.annotation.PathVariable;
80 import org.springframework.web.bind.annotation.RequestBody;
81 import org.springframework.web.bind.annotation.GetMapping;
82 import org.springframework.web.bind.annotation.RestController;
83 import org.springframework.web.client.RestClientException;
84 import org.springframework.web.client.RestTemplate;
85 import org.springframework.web.multipart.MultipartFile;
86 import org.springframework.web.multipart.MultipartHttpServletRequest;
87 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
89 @SuppressWarnings("unchecked")
91 @org.springframework.context.annotation.Configuration
92 @EnableAspectJAutoProxy
94 public class WidgetsCatalogUnRestrictedController extends EPUnRestrictedBaseController {
96 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogUnRestrictedController.class);
98 private static final String MS_WIDGET_LOCAL_PORT = "microservices.widget.local.port";
100 private static final String MS_WIDGET_URL = "/widget/microservices/";
102 private RestTemplate template = new RestTemplate();
104 private String whatService = "widgets-service";
107 private WidgetMService widgetMService;
111 public CommonsMultipartResolver multipartResolver() {
112 return new CommonsMultipartResolver();
116 // for localhost testing only
117 javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
118 public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
119 if ("localhost".equals(hostname))
125 @GetMapping(value = "/portalApi/microservices/{widgetId}/controller.js")
126 public String getWidgetController(@PathVariable("widgetId") long widgetId) throws Exception {
127 return template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://"
128 + widgetMService.getServiceLocation(whatService,
129 SystemProperties.getProperty(MS_WIDGET_LOCAL_PORT))
130 + MS_WIDGET_URL + widgetId + "/controller.js", String.class,
131 WidgetServiceHeaders.getInstance());