e94f186c603653d505436470d0ff9913235f56a9
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / onap / so / apihandler / common / RequestClientFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.apihandler.common;
22
23
24
25
26 import org.apache.http.impl.client.DefaultHttpClient;
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) throws IllegalStateException{
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                 }
46                 else{
47                         url = env.getProperty(CommonConstants.CAMUNDA_URL) + orchestrationURI;
48                         retClient = new CamundaClient();
49                 }
50                 retClient.setClient(new DefaultHttpClient());
51                 retClient.setProps(env);
52                 retClient.setUrl(url);
53                 return retClient;
54                 
55         }
56
57         public Environment getEnv() {
58                 return env;
59         }
60
61         public void setEnv(Environment env) {
62                 this.env = env;
63         }
64         
65         
66
67
68 }