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 NFVO 0.5 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;
62 * @param authenticateMode
64 * @throws VnfmException
67 public synchronized ProtocolSocketFactory get(String authenticateMode) throws VnfmException {
68 if(SOCKMAP.get(authenticateMode) == null) {
69 if(Constant.ANONYMOUS.equals(authenticateMode)) {
70 SslAnonymousSocket anonymous = new SslAnonymousSocket();
72 SOCKMAP.put(Constant.ANONYMOUS, anonymous);
73 }else if (Constant.CERTIFICATE.equals(authenticateMode)){
74 SslCertificateSocket certificateSocket = new SslCertificateSocket();
75 certificateSocket.init();
76 SOCKMAP.put(Constant.CERTIFICATE, certificateSocket);
78 LOG.error("funtion=get, msg=ProtocolSocketFactory Unknown AuthenticateMode={}", authenticateMode);
79 throw new VnfmException(String.format("Illegal Auth mode", authenticateMode));
83 return SOCKMAP.get(authenticateMode);
87 * Refresh local socket map
91 * @throws VnfmException
94 public synchronized void refresh(String autherMode) throws VnfmException {
95 if(Constant.ANONYMOUS.equals(autherMode)) {
96 SslAnonymousSocket anonymous = new SslAnonymousSocket();
98 SOCKMAP.put(Constant.ANONYMOUS, anonymous);