001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.components.http; 017 018import io.jboot.Jboot; 019import io.jboot.components.http.jboot.JbootHttpImpl; 020import io.jboot.components.http.okhttp.OKHttpImpl; 021import io.jboot.core.spi.JbootSpiLoader; 022 023public class JbootHttpManager { 024 025 private static JbootHttpManager me = new JbootHttpManager(); 026 private JbootHttp jbootHttp; 027 private JbootHttpConfig httpConfig; 028 029 030 public static JbootHttpManager me() { 031 return me; 032 } 033 034 private JbootHttpManager() { 035 httpConfig = Jboot.config(JbootHttpConfig.class); 036 } 037 038 039 public JbootHttp getJbootHttp() { 040 if (jbootHttp == null) { 041 jbootHttp = buildJbootHttp(); 042 } 043 return jbootHttp; 044 } 045 046 047 public JbootHttpConfig getHttpConfig() { 048 return httpConfig; 049 } 050 051 052 private JbootHttp buildJbootHttp() { 053 switch (httpConfig.getType()) { 054 case JbootHttpConfig.TYPE_DEFAULT: 055 return new JbootHttpImpl(); 056 case JbootHttpConfig.TYPE_OKHTTP: 057 return new OKHttpImpl(); 058 case JbootHttpConfig.TYPE_HTTPCLIENT: 059 throw new RuntimeException("not finished!!!!"); 060 default: 061 return JbootSpiLoader.load(JbootHttp.class, httpConfig.getType()); 062 } 063 064 } 065 066 067}