1710 Rebase - Second Attempt
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / openecomp / mso / apihandler / common / RequestClientFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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.openecomp.mso.apihandler.common;
22
23
24 import java.util.Properties;
25
26 import org.apache.http.impl.client.DefaultHttpClient;
27
28 import org.openecomp.mso.properties.MsoJavaProperties;
29
30 public class RequestClientFactory {
31         
32         //based on URI, returns BPEL, CamundaTask or Camunda client
33         public static RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
34                 RequestClient retClient;
35                 if(props ==null){
36                         throw new IllegalStateException("properties is null");
37                 }
38                 String url = null;
39                 if(orchestrationURI.contains(CommonConstants.BPEL_SEARCH_STR)){
40                         url = props.getProperty(CommonConstants.BPEL_URL,null) + orchestrationURI;
41                         retClient= new BPELRestClient();
42                         
43                 }else if(orchestrationURI.contains(CommonConstants.TASK_SEARCH_STR)){
44                         url = props.getProperty(CommonConstants.CAMUNDA_URL,null) + orchestrationURI;
45                         retClient = new CamundaTaskClient();
46                 }
47                 else{
48                         url = props.getProperty(CommonConstants.CAMUNDA_URL,null) + orchestrationURI;
49                         retClient = new CamundaClient();
50                 }
51                 retClient.setClient(new DefaultHttpClient());
52                 retClient.setProps(props);
53                 retClient.setUrl(url);
54                 return retClient;
55                 
56         }
57         
58
59
60 }