@@ -123,6 +123,8 @@ public final class Novate {
123123 private Map <Object , Observable <ResponseBody >> downMaps = new HashMap <Object , Observable <ResponseBody >>() {
124124 };
125125 private Observable .Transformer exceptTransformer = null ;
126+
127+ public static final String KEY_CACHE = "Novate_Http_cache" ;
126128 private static final int DEFAULT_TIMEOUT = 15 ;
127129 private static final int DEFAULT_MAXIDLE_CONNECTIONS = 5 ;
128130 private static final long DEFAULT_KEEP_ALIVEDURATION = 8 ;
@@ -152,7 +154,6 @@ public final class Novate {
152154 * create ApiService
153155 */
154156 public <T > T create (final Class <T > service ) {
155-
156157 return retrofit .create (service );
157158 }
158159
@@ -181,16 +182,26 @@ public <T> T call(Observable<T> observable, ResponseCallback callback) {
181182 .subscribe (new RxSubscriber <T , ResponseBody >(observable .getClass ().getSimpleName (), callback ));
182183 }
183184
185+
184186 /*public <R> Observable<R> compose() {
185187 return schedulersIo(okhttpBuilder);
186188 }
187189*/
190+
191+ /**
192+ * Thread IO
193+ * @param observable
194+ */
188195 public <T > Observable <T > schedulersIo (Observable <T > observable ) {
189196 return observable .subscribeOn (Schedulers .io ())
190197 .unsubscribeOn (Schedulers .io ())
191198 .observeOn (Schedulers .io ());
192199 }
193200
201+ /**
202+ * Thread mainThread
203+ * @param observable
204+ */
194205 public <T > Observable <T > schedulersMain (Observable <T > observable ) {
195206 return observable .subscribeOn (Schedulers .io ())
196207 .unsubscribeOn (Schedulers .io ())
@@ -211,6 +222,13 @@ public <T> T execute(NovateRequest request, BaseSubscriber<T> subscriber) {
211222 return call (request , subscriber );
212223 }
213224
225+ /**
226+ * call NovateRequest
227+ * @param request
228+ * @param subscriber
229+ * @param <T>
230+ * @return
231+ */
214232 private <T > T call (NovateRequest request , BaseSubscriber <T > subscriber ) {
215233 return (T ) createRx (request )
216234 .compose (schedulersTransformer )
@@ -1574,7 +1592,7 @@ public static final class Builder {
15741592 private int writeTimeout = DEFAULT_TIMEOUT ;
15751593 private int readTimeout = DEFAULT_TIMEOUT ;
15761594 private int default_maxidle_connections = DEFAULT_MAXIDLE_CONNECTIONS ;
1577- private long default_keep_aliveduration = DEFAULT_MAXIDLE_CONNECTIONS ;
1595+ private long default_keep_aliveduration = DEFAULT_KEEP_ALIVEDURATION ;
15781596 private long cacheMaxSize = DEFAULT_CACHEMAXSIZE ;
15791597 private int cacheTimeout = DEFAULT_MAX_STALE ;
15801598 private okhttp3 .Call .Factory callFactory ;
@@ -1583,6 +1601,7 @@ public static final class Builder {
15831601 private Object tag ;
15841602 private Boolean isCookie = false ;
15851603 private Boolean isCache = true ;
1604+ private Boolean isSkip = false ;
15861605 private List <InputStream > certificateList ;
15871606 private HostnameVerifier hostnameVerifier ;
15881607 private CertificatePinner certificatePinner ;
@@ -1887,18 +1906,35 @@ public Builder cookieManager(NovateCookieManager cookie) {
18871906 }
18881907
18891908 /**
1890- *
1909+ *skipSSLSocketFactory
1910+ */
1911+ public Builder skipSSLSocketFactory (boolean isSkip ) {
1912+ this .isSkip = isSkip ;
1913+ return this ;
1914+ }
1915+
1916+ /**
1917+ * addSSLSocketFactory
18911918 */
18921919 public Builder addSSLSocketFactory (SSLSocketFactory sslSocketFactory ) {
1920+ if (sslSocketFactory == null ) throw new NullPointerException ("sslSocketFactory == null" );
18931921 this .sslSocketFactory = sslSocketFactory ;
18941922 return this ;
18951923 }
18961924
1925+ /**
1926+ * HostnameVerifier
1927+ * @param hostnameVerifier
1928+ * @return Builder
1929+ */
18971930 public Builder addHostnameVerifier (HostnameVerifier hostnameVerifier ) {
18981931 this .hostnameVerifier = hostnameVerifier ;
18991932 return this ;
19001933 }
19011934
1935+ /**
1936+ * addCertificatePinner
1937+ */
19021938 public Builder addCertificatePinner (CertificatePinner certificatePinner ) {
19031939 this .certificatePinner = certificatePinner ;
19041940 return this ;
@@ -1922,6 +1958,7 @@ public Builder addSSL(String[] hosts, int[] certificates) {
19221958 }
19231959
19241960 public Builder addNetworkInterceptor (Interceptor interceptor ) {
1961+ if (interceptor == null ) throw new NullPointerException ("interceptor == null" );
19251962 okhttpBuilder .addNetworkInterceptor (interceptor );
19261963 return this ;
19271964 }
@@ -2023,17 +2060,23 @@ public Novate build() {
20232060 new HttpLoggingInterceptor ().setLevel (HttpLoggingInterceptor .Level .BODY ));
20242061 }
20252062
2026- if (sslSocketFactory != null ) {
2063+ if (isSkip ) {
2064+ okhttpBuilder .sslSocketFactory (NovateHttpsFactroy .getSSLSocketFactory (),
2065+ NovateHttpsFactroy .creatX509TrustManager ());
2066+
2067+ okhttpBuilder .hostnameVerifier (NovateHttpsFactroy .creatSkipHostnameVerifier ());
2068+ }
2069+
2070+ if (!isSkip && sslSocketFactory != null ) {
20272071 okhttpBuilder .sslSocketFactory (sslSocketFactory );
20282072 }
20292073
20302074 if (hostnameVerifier != null ) {
20312075 okhttpBuilder .hostnameVerifier (hostnameVerifier );
20322076 }
20332077
2034-
20352078 if (httpCacheDirectory == null ) {
2036- httpCacheDirectory = new File (mContext .getCacheDir (), "Novate_Http_cache" );
2079+ httpCacheDirectory = new File (mContext .getCacheDir (), KEY_CACHE );
20372080 }
20382081
20392082 if (isCache ) {
@@ -2077,7 +2120,7 @@ public Novate build() {
20772120 * <p>If unset, a new connection pool will be used.
20782121 */
20792122 if (connectionPool == null ) {
2080- connectionPool = new ConnectionPool (default_maxidle_connections , default_maxidle_connections , TimeUnit .SECONDS );
2123+ connectionPool = new ConnectionPool (default_maxidle_connections , default_keep_aliveduration , TimeUnit .SECONDS );
20812124 }
20822125 okhttpBuilder .connectionPool (connectionPool );
20832126
@@ -2102,6 +2145,11 @@ public Novate build() {
21022145 }
21032146
21042147 if (isCookie ) {
2148+ /**
2149+ * Returns a modifiable list of interceptors that observe a single network request and response.
2150+ * These interceptors must call {@link Interceptor.Chain#proceed} exactly once: it is an error
2151+ * for a network interceptor to short-circuit or repeat a network request.
2152+ */
21052153 okhttpBuilder .addInterceptor (new ReceivedCookiesInterceptor (context ));
21062154 okhttpBuilder .addInterceptor (new AddCookiesInterceptor (context , "" ));
21072155 }
@@ -2187,16 +2235,16 @@ public Observable<?> call(Throwable throwable) {
21872235 @ Deprecated
21882236 public interface ResponseCallBack <T > {
21892237
2190- public void onStart ();
2238+ void onStart ();
21912239
2192- public void onCompleted ();
2240+ void onCompleted ();
21932241
2194- public abstract void onError (Throwable e );
2242+ void onError (Throwable e );
21952243
21962244 @ Deprecated
2197- public abstract void onSuccee (NovateResponse <T > response );
2245+ void onSuccee (NovateResponse <T > response );
21982246
2199- public void onsuccess (int code , String msg , T response , String originalResponse );
2247+ void onsuccess (int code , String msg , T response , String originalResponse );
22002248
22012249 }
22022250}
0 commit comments