2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.client.policy;
23 import java.util.HashMap;
25 import java.util.Map.Entry;
26 import java.util.logging.Logger;
28 import javax.ws.rs.client.ClientBuilder;
29 import javax.ws.rs.client.Invocation.Builder;
30 import javax.ws.rs.client.WebTarget;
33 import org.openecomp.mso.bpmn.core.PropertyConfiguration;
34 import org.openecomp.mso.logger.MsoLogger;
35 import org.springframework.stereotype.Service;
38 public abstract class RestClient {
39 protected static final String ECOMP_COMPONENT_NAME = "MSO";
41 private WebTarget webTarget;
43 protected final Map<String, String> headerMap;
44 protected final MsoLogger msoLogger;
45 protected Map<String, String> properties;
46 protected String host;
48 protected RestClient(String endpointKey) {
49 Logger logger = Logger.getLogger(getClass().getName());
50 msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
52 properties = PropertyConfiguration.getInstance().getProperties("mso.bpmn.urn.properties");
53 headerMap = new HashMap<>();
54 initializeHeaderMap(headerMap);
56 host = this.getHost(endpointKey);
58 webTarget = ClientBuilder.newClient().register(logger).register(new LoggingFilter())
59 .register(new CommonObjectMapperProvider()).target(host);
62 private String getHost(String key) {
63 return properties.get(key);
66 protected Builder getBuilder() {
67 Builder builder = webTarget.request();
69 for (Entry<String, String> entry : headerMap.entrySet()) {
70 builder.header(entry.getKey(), entry.getValue());
75 protected abstract void initializeHeaderMap(Map<String, String> headerMap);