1d6566185f5be9ed224ac38cbe2324bbff43369d
[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
22 import org.onap.msb.sdk.httpclient.ServiceHttpEndPointBeanObject;
23 import org.onap.msb.sdk.httpclient.conf.HttpClientConf;
24 import org.onap.msb.sdk.httpclient.exception.RetrofitServiceRuntimeException;
25 import org.onap.msb.sdk.httpclient.handler.impl.ConnectionParamsBuilder;
26 import org.onap.msb.sdk.httpclient.handler.impl.ConverterFactoryBuilder;
27 import org.onap.msb.sdk.httpclient.handler.impl.LBBuilder;
28 import org.onap.msb.sdk.httpclient.handler.impl.MetricmanagerBuilder;
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 import com.google.common.collect.Lists;
34
35 /**
36  * @author 10071214
37  *
38  */
39
40 public class RetrofitServiceHandlerFactory {
41
42   private List<HandlerContextBuilder> builders = Lists.newArrayList();
43
44   public void init() {
45
46     builders.add(new ServiceHttpEndPointBeanObjectBuilder());
47     builders.add(new MetricmanagerBuilder());
48     builders.add(new LBBuilder());
49     builders.add(new ConnectionParamsBuilder());
50     builders.add(new ConverterFactoryBuilder());
51     builders.add(new RetrofitHandlerContextBuilder());
52
53
54   }
55
56
57
58   public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
59       ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject)
60       throws RetrofitServiceRuntimeException {
61
62     RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
63     ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
64     /* ctx.setLocator(locator); */
65     ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
66
67     for (HandlerContextBuilder builder : builders) {
68       builder.build(ctx);
69     }
70     return new RetrofitServiceHandler(ctx);
71   }
72
73
74   public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz)
75       throws RetrofitServiceRuntimeException {
76
77     RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
78     ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
79     // ctx.setLocator(locator);
80
81     for (HandlerContextBuilder builder : builders) {
82       builder.build(ctx);
83     }
84     return new RetrofitServiceHandler(ctx);
85
86   }
87
88
89
90   public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
91       ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject, HttpClientConf httpClientConf,
92       MSBServiceClient msbClient) {
93
94     RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
95     ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
96     // ctx.setLocator(locator);
97     ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
98
99     ctx.setHttpClientConf(httpClientConf);
100     ctx.setMsbClient(msbClient);
101
102     for (HandlerContextBuilder builder : builders) {
103       builder.build(ctx);
104     }
105     return new RetrofitServiceHandler(ctx);
106
107   }
108
109
110 }