remove the heavy (many MB) unused dependencies
[msb/java-sdk.git] / src / main / java / org / onap / msb / sdk / httpclient / handler / RetrofitServiceHandlerFactory.java
1 /*******************************************************************************
2  * Copyright 2017 ZTE, Inc. and others.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 /**
15  * 
16  */
17 package org.onap.msb.sdk.httpclient.handler;
18
19 import java.lang.reflect.InvocationHandler;
20 import java.util.List;
21 import java.util.ArrayList;
22
23 import org.onap.msb.sdk.httpclient.ServiceHttpEndPointBeanObject;
24 import org.onap.msb.sdk.httpclient.conf.HttpClientConf;
25 import org.onap.msb.sdk.httpclient.exception.RetrofitServiceRuntimeException;
26 import org.onap.msb.sdk.httpclient.handler.impl.ConnectionParamsBuilder;
27 import org.onap.msb.sdk.httpclient.handler.impl.ConverterFactoryBuilder;
28 import org.onap.msb.sdk.httpclient.handler.impl.LBBuilder;
29 import org.onap.msb.sdk.httpclient.handler.impl.RetrofitHandlerContextBuilder;
30 import org.onap.msb.sdk.httpclient.handler.impl.ServiceHttpEndPointBeanObjectBuilder;
31 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
32
33 /**
34  * @author 10071214
35  *
36  */
37
38 public class RetrofitServiceHandlerFactory {
39
40   private List<HandlerContextBuilder> builders = new ArrayList<>();
41
42   public void init() {
43
44     builders.add(new ServiceHttpEndPointBeanObjectBuilder());
45     builders.add(new LBBuilder());
46     builders.add(new ConnectionParamsBuilder());
47     builders.add(new ConverterFactoryBuilder());
48     builders.add(new RetrofitHandlerContextBuilder());
49
50
51   }
52
53
54
55   public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
56       ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject)
57       throws RetrofitServiceRuntimeException {
58
59     RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
60     ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
61     /* ctx.setLocator(locator); */
62     ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
63
64     for (HandlerContextBuilder builder : builders) {
65       builder.build(ctx);
66     }
67     return new RetrofitServiceHandler(ctx);
68   }
69
70
71   public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz)
72       throws RetrofitServiceRuntimeException {
73
74     RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
75     ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
76     // ctx.setLocator(locator);
77
78     for (HandlerContextBuilder builder : builders) {
79       builder.build(ctx);
80     }
81     return new RetrofitServiceHandler(ctx);
82
83   }
84
85
86
87   public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
88       ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject, HttpClientConf httpClientConf,
89       MSBServiceClient msbClient) {
90
91     RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
92     ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
93     // ctx.setLocator(locator);
94     ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
95
96     ctx.setHttpClientConf(httpClientConf);
97     ctx.setMsbClient(msbClient);
98
99     for (HandlerContextBuilder builder : builders) {
100       builder.build(ctx);
101     }
102     return new RetrofitServiceHandler(ctx);
103
104   }
105
106
107 }