Issue-id: OCS-9
[msb/apigateway.git] / msb-core / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / util / RouteUtil.java
1 /**
2  * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openo.msb.wrapper.util;
17
18 import org.apache.commons.lang3.StringUtils;
19 import org.openo.msb.api.DiscoverInfo;
20
21
22 public class RouteUtil {
23
24     public static String IUI_ROOT_PATH="iui";  
25     
26     public static  String API_ROOT_PATH="api"; 
27     
28         public static final String ROUTE_PATH="msb:routing";   
29         
30         public static final String APIROUTE="api";  
31         
32         public static final String IUIROUTE="iui";  
33         
34         public static final String CUSTOMROUTE="custom";  
35         
36         public static final String P2PROUTE="p2p";  
37         
38         
39         public static final String ROUTE_PATH_INFO="info";  
40         
41         public static final String ROUTE_PATH_LOADBALANCE="lb"; 
42         
43         public static final String APIROUTE_PATH_LIFE="life";  
44         
45
46         public static final String REQUEST_SUCCESS = "SUCCESS";
47         
48         public static final String REQUEST_FAIL = "FAIL";
49         
50     public static String PROTOCOL_LIST="REST,UI,MQ,FTP,SNMP,TCP,UDP"; 
51     
52     public static DiscoverInfo discoverInfo=new DiscoverInfo();
53     
54     
55     public static String[] visualRangeRange={"0","1"};
56     
57     public static String[] controlRangeMatches={"0","1","2"};
58     
59     public static String[] statusRangeMatches={"0","1"};
60     
61     public static String[] useOwnUpstreamRangeMatches={"0","1"};
62     
63     public static String[] visualRangeMatches={"1"};
64         
65         /** 
66         * @Title: getPrefixedKey  
67         * @Description: TODO(Add base path prefix radis assembly path) 
68         * @param: @param serviceName
69         * @param: @param version
70         * @param: @param type
71         * @param: @return      
72         * @return: String    
73         */
74         
75         public static String getPrefixedKey(String...paths){
76                 StringBuffer sb= new StringBuffer();
77                 
78                     if(paths[0].trim().equals("") || paths[0].equals(String.valueOf(JedisUtil.serverPort))){
79                     sb.append(ROUTE_PATH);
80                 }
81                 else{
82                    sb.append(paths[0]); 
83                 }
84         
85                 for (int i = 1; i < paths.length; i++) {
86                         sb.append(":");
87                         sb.append(paths[i]);
88                 }
89                 return sb.toString();
90         }
91         
92         
93         public static Object[] concat(Object[] a, Object[] b) {
94             Object[] c= new Object[a.length+b.length];
95         System.arraycopy(a, 0, c, 0, a.length);
96         System.arraycopy(b, 0, c, a.length, b.length);
97         return c;
98      }
99         
100         public static boolean contain(String[] array,String str){
101             for(int i=0;i<array.length;i++){
102                   if(array[i].equals(str)){
103                      return true;  
104                   }
105             }
106             return false;
107
108           }
109         
110         public static boolean contain(String[] array,String value[]){
111         for(int i=0;i<array.length;i++){
112             for(int n=0;n<value.length;n++){
113               if(array[i].equals(value[n])){
114                  return true;  
115               }
116             }
117         }
118         return false;
119
120       }
121         
122         public static String show(String[] array){
123             
124         return StringUtils.join(array, "|");
125
126       }
127         
128         public static void main(String[] args) {
129             String array[]={"1","2"};
130             System.out.println(StringUtils.join(array, "|"));
131     }
132         
133
134 }