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.onap.so.client.dmaap;
23 import java.io.IOException;
24 import java.util.Base64;
26 import java.util.Optional;
27 import java.util.Properties;
29 import org.onap.so.client.defaultproperties.DefaultDmaapPropertiesImpl;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.core.io.ClassPathResource;
33 import org.springframework.core.io.Resource;
36 public abstract class DmaapClient {
38 protected static Logger logger = LoggerFactory.getLogger(DmaapClient.class);
39 protected final Map<String, String> msoProperties;
40 protected final Properties properties;
41 public DmaapClient(String filepath) throws IOException {
42 Resource resource = new ClassPathResource(filepath);
43 DmaapProperties dmaapProperties = DmaapPropertiesLoader.getInstance().getNewImpl();
44 if (dmaapProperties == null) {
45 logger.error("No RestProperty implementation found on classpath, loading default");
46 dmaapProperties = new DefaultDmaapPropertiesImpl();
48 this.msoProperties = dmaapProperties.getProperties();
49 this.properties = new Properties();
50 this.properties.load(resource.getInputStream());
51 this.properties.put("password", this.deobfuscatePassword(this.getPassword()));
52 this.properties.put("username", this.getUserName());
53 this.properties.put("topic", this.getTopic());
54 Optional<String> host = this.getHost();
55 if (host.isPresent()) {
56 this.properties.put("host", host.get());
59 protected String deobfuscatePassword(String password) {
62 return new String(Base64.getDecoder().decode(password.getBytes()));
63 } catch(IllegalArgumentException iae) {
64 logger.error("llegal Arguments",iae);
70 public abstract String getUserName();
71 public abstract String getPassword();
72 public abstract String getTopic();
73 public abstract Optional<String> getHost();