1 /*******************************************************************************
2 * Copyright 2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
13 ******************************************************************************/
17 package org.onap.msb.sdk.httpclient.handler;
19 import java.lang.reflect.InvocationHandler;
20 import java.util.List;
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;
33 import com.google.common.collect.Lists;
40 public class RetrofitServiceHandlerFactory {
42 private List<HandlerContextBuilder> builders = Lists.newArrayList();
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());
58 public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
59 ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject)
60 throws RetrofitServiceRuntimeException {
62 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
63 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
64 /* ctx.setLocator(locator); */
65 ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
67 for (HandlerContextBuilder builder : builders) {
70 return new RetrofitServiceHandler(ctx);
74 public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz)
75 throws RetrofitServiceRuntimeException {
77 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
78 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
79 // ctx.setLocator(locator);
81 for (HandlerContextBuilder builder : builders) {
84 return new RetrofitServiceHandler(ctx);
90 public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
91 ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject, HttpClientConf httpClientConf,
92 MSBServiceClient msbClient) {
94 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
95 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
96 // ctx.setLocator(locator);
97 ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
99 ctx.setHttpClientConf(httpClientConf);
100 ctx.setMsbClient(msbClient);
102 for (HandlerContextBuilder builder : builders) {
105 return new RetrofitServiceHandler(ctx);