c2ffa7e0040c9e37597b866947714415b75cc6ee
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.so.apihandler.common;
25
26 import org.apache.http.impl.client.HttpClientBuilder;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.core.env.Environment;
29 import org.springframework.stereotype.Component;
30
31 @Component
32 public class RequestClientFactory {
33
34     @Autowired
35     private Environment env;
36
37     // based on URI, returns BPEL, CamundaTask or Camunda client
38     public RequestClient getRequestClient(String orchestrationURI) {
39         RequestClient retClient;
40
41         String url;
42         if (orchestrationURI.contains(CommonConstants.TASK_SEARCH_STR)) {
43             url = env.getProperty(CommonConstants.CAMUNDA_URL) + orchestrationURI;
44             retClient = new CamundaTaskClient();
45         } else {
46             url = env.getProperty(CommonConstants.CAMUNDA_URL) + orchestrationURI;
47             retClient = new CamundaClient();
48         }
49         retClient.setClient(HttpClientBuilder.create().build());
50         retClient.setProps(env);
51         retClient.setUrl(url);
52         return retClient;
53
54     }
55
56     public Environment getEnv() {
57         return env;
58     }
59
60     public void setEnv(Environment env) {
61         this.env = env;
62     }
63
64
65
66 }