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;
21 import java.util.ArrayList;
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;
38 public class RetrofitServiceHandlerFactory {
40 private List<HandlerContextBuilder> builders = new ArrayList<>();
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());
55 public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
56 ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject)
57 throws RetrofitServiceRuntimeException {
59 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
60 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
61 /* ctx.setLocator(locator); */
62 ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
64 for (HandlerContextBuilder builder : builders) {
67 return new RetrofitServiceHandler(ctx);
71 public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz)
72 throws RetrofitServiceRuntimeException {
74 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
75 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
76 // ctx.setLocator(locator);
78 for (HandlerContextBuilder builder : builders) {
81 return new RetrofitServiceHandler(ctx);
87 public InvocationHandler buildInvocationHandler(Class<?> retrofitSrvInterfaceClazz,
88 ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject, HttpClientConf httpClientConf,
89 MSBServiceClient msbClient) {
91 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
92 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
93 // ctx.setLocator(locator);
94 ctx.setServiceHttpEndPointBeanObject(serviceHttpEndPointBeanObject);
96 ctx.setHttpClientConf(httpClientConf);
97 ctx.setMsbClient(msbClient);
99 for (HandlerContextBuilder builder : builders) {
102 return new RetrofitServiceHandler(ctx);