diff options
author | 2017-09-08 13:27:46 -0400 | |
---|---|---|
committer | 2017-09-08 13:32:24 -0400 | |
commit | 62cd6aaaf74aa91ee0037c0e155c8e7284f07567 (patch) | |
tree | 68c0c53c9156f5aa3c6b3599ac940770f986633d /bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java | |
parent | fa1a211d28a912892fcd888569df033900eb01ee (diff) |
1710 Rebase - Second Attempt
This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit:
54483fc6606ddb1591a2e9da61bff8712325f924
Wed Sep 6 18:12:56 2017 -0400
Rebasing was done on a branch on top of this commit in so/master in ONAP:
93fbdfbe46104f8859d4754040f979cb7997c157
Thu Sep 7 16:42:59 2017 +0000
Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59
Issue-id: SO-107
Signed-off-by: Arthur Martella <amartell@research.att.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java new file mode 100644 index 0000000000..f8e1ffd74f --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.policy; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.logging.Logger; + +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; + + +import org.openecomp.mso.bpmn.core.PropertyConfiguration; +import org.openecomp.mso.logger.MsoLogger; +import org.springframework.stereotype.Service; + +@Service +public abstract class RestClient { + protected static final String ECOMP_COMPONENT_NAME = "MSO"; + + private WebTarget webTarget; + + protected final Map<String, String> headerMap; + protected final MsoLogger msoLogger; + protected Map<String, String> properties; + protected String host; + + protected RestClient(String endpointKey) { + Logger logger = Logger.getLogger(getClass().getName()); + msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + + properties = PropertyConfiguration.getInstance().getProperties("mso.bpmn.urn.properties"); + headerMap = new HashMap<>(); + initializeHeaderMap(headerMap); + + host = this.getHost(endpointKey); + + webTarget = ClientBuilder.newClient().register(logger).register(new LoggingFilter()) + .register(new CommonObjectMapperProvider()).target(host); + } + + private String getHost(String key) { + return properties.get(key); + } + + protected Builder getBuilder() { + Builder builder = webTarget.request(); + + for (Entry<String, String> entry : headerMap.entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + return builder; + } + + protected abstract void initializeHeaderMap(Map<String, String> headerMap); +} |