2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect;
20 import java.util.concurrent.ConcurrentHashMap;
22 import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
23 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmException;
24 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
33 * @version VFC 1.0 Sep 14, 2016
35 public class SslProtocolSocketFactory {
37 private static final Logger LOG = LoggerFactory.getLogger(SslProtocolSocketFactory.class);
39 private static final Map<String, ProtocolSocketFactory> SOCKMAP =
40 new ConcurrentHashMap<String, ProtocolSocketFactory>(2);
42 private static SslProtocolSocketFactory singleinstance = null;
45 * Generate instance of SslProtocolSocketFactory
51 public static synchronized SslProtocolSocketFactory getInstance() {
52 if(singleinstance == null) {
53 singleinstance = new SslProtocolSocketFactory();
55 return singleinstance;
61 * @param authenticateMode
63 * @throws VnfmException
66 public synchronized ProtocolSocketFactory get(String authenticateMode) throws VnfmException {
67 if(SOCKMAP.get(authenticateMode) == null) {
68 if(Constant.ANONYMOUS.equals(authenticateMode)) {
69 SslAnonymousSocket anonymous = new SslAnonymousSocket();
71 SOCKMAP.put(Constant.ANONYMOUS, anonymous);
72 } else if(Constant.CERTIFICATE.equals(authenticateMode)) {
73 SslCertificateSocket certificateSocket = new SslCertificateSocket();
74 certificateSocket.init();
75 SOCKMAP.put(Constant.CERTIFICATE, certificateSocket);
77 LOG.error("funtion=get, msg=ProtocolSocketFactory Unknown AuthenticateMode={}", authenticateMode);
78 throw new VnfmException("Illegal Auth mode: " + authenticateMode);
82 return SOCKMAP.get(authenticateMode);
86 * Refresh local socket map
90 * @throws VnfmException
93 public synchronized void refresh(String autherMode) throws VnfmException {
94 if(Constant.ANONYMOUS.equals(autherMode)) {
95 SslAnonymousSocket anonymous = new SslAnonymousSocket();
97 SOCKMAP.put(Constant.ANONYMOUS, anonymous);