|
| 1 | +package com.aliyuncs; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +import com.aliyuncs.http.FormatType; |
| 7 | +import com.aliyuncs.http.MethodType; |
| 8 | +import com.aliyuncs.http.ProtocolType; |
| 9 | +import com.aliyuncs.regions.ProductDomain; |
| 10 | + |
| 11 | +public class CommonRequest { |
| 12 | + |
| 13 | + private String version = null; |
| 14 | + private String product = null; |
| 15 | + private String action = null; |
| 16 | + private String locationProduct = null; |
| 17 | + private String endpointType = null; |
| 18 | + private String regionId = null; |
| 19 | + private ProtocolType protocol = null; |
| 20 | + private final Map<String, String> queryParameters = new HashMap<String, String>(); |
| 21 | + private final Map<String, String> bodyParameters = new HashMap<String, String>(); |
| 22 | + private final Map<String, String> headParameters = new HashMap<String, String>(); |
| 23 | + |
| 24 | + private Integer connectTimeout = null; |
| 25 | + private Integer readTimeout = null; |
| 26 | + private MethodType method = null; |
| 27 | + private FormatType httpContentType = null; |
| 28 | + private byte[] httpContent = null; |
| 29 | + private String encoding = null; |
| 30 | + |
| 31 | + private String uriPattern = null; |
| 32 | + private Map<String, String> pathParameters = new HashMap<String, String>(); |
| 33 | + |
| 34 | + private String domain = null; |
| 35 | + |
| 36 | + @SuppressWarnings("rawtypes") |
| 37 | + public AcsRequest buildRequest() { |
| 38 | + if (uriPattern != null) { |
| 39 | + CommonRoaRequest request = new CommonRoaRequest(product); |
| 40 | + request.setUriPattern(uriPattern); |
| 41 | + for (String pathParamKey : pathParameters.keySet()) { |
| 42 | + request.putPathParameter(pathParamKey, pathParameters.get(pathParamKey)); |
| 43 | + } |
| 44 | + fillParams(request); |
| 45 | + |
| 46 | + return request; |
| 47 | + } else { |
| 48 | + CommonRpcRequest request = new CommonRpcRequest(product); |
| 49 | + fillParams(request); |
| 50 | + |
| 51 | + return request; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @SuppressWarnings("rawtypes") |
| 56 | + private void fillParams(AcsRequest request) { |
| 57 | + request.putHeaderParameter("x-sdk-invoke-type", "common"); |
| 58 | + |
| 59 | + if (version != null) { |
| 60 | + request.setVersion(version); |
| 61 | + } |
| 62 | + if (action != null) { |
| 63 | + request.setActionName(action); |
| 64 | + } |
| 65 | + if (regionId != null) { |
| 66 | + request.setRegionId(regionId); |
| 67 | + } |
| 68 | + if (locationProduct != null) { |
| 69 | + request.setLocationProduct(locationProduct); |
| 70 | + } |
| 71 | + if (endpointType != null) { |
| 72 | + request.setEndpointType(endpointType); |
| 73 | + } |
| 74 | + if (connectTimeout != null) { |
| 75 | + request.setConnectTimeout(connectTimeout); |
| 76 | + } |
| 77 | + if (readTimeout != null) { |
| 78 | + request.setReadTimeout(readTimeout); |
| 79 | + } |
| 80 | + if (method != null) { |
| 81 | + request.setMethod(method); |
| 82 | + } |
| 83 | + if (protocol != null) { |
| 84 | + request.setProtocol(protocol); |
| 85 | + } |
| 86 | + if (domain != null) { |
| 87 | + ProductDomain productDomain = new ProductDomain(product, domain); |
| 88 | + request.setProductDomain(productDomain); |
| 89 | + } |
| 90 | + if (httpContent != null) { |
| 91 | + request.setHttpContent(httpContent, encoding, httpContentType); |
| 92 | + } |
| 93 | + for (String queryParamKey : queryParameters.keySet()) { |
| 94 | + request.putQueryParameter(queryParamKey, queryParameters.get(queryParamKey)); |
| 95 | + } |
| 96 | + for (String bodyParamKey : bodyParameters.keySet()) { |
| 97 | + request.putBodyParameter(bodyParamKey, bodyParameters.get(bodyParamKey)); |
| 98 | + } |
| 99 | + for (String headParamKey : headParameters.keySet()) { |
| 100 | + request.putHeaderParameter(headParamKey, headParameters.get(headParamKey)); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + public String getVersion() { |
| 105 | + return version; |
| 106 | + } |
| 107 | + |
| 108 | + public void setVersion(String version) { |
| 109 | + this.version = version; |
| 110 | + } |
| 111 | + |
| 112 | + public String getProduct() { |
| 113 | + return product; |
| 114 | + } |
| 115 | + |
| 116 | + public void setProduct(String product) { |
| 117 | + this.product = product; |
| 118 | + } |
| 119 | + |
| 120 | + public String getAction() { |
| 121 | + return action; |
| 122 | + } |
| 123 | + |
| 124 | + public void setAction(String action) { |
| 125 | + this.action = action; |
| 126 | + } |
| 127 | + |
| 128 | + public String getLocationProduct() { |
| 129 | + return locationProduct; |
| 130 | + } |
| 131 | + |
| 132 | + public void setLocationProduct(String locationProduct) { |
| 133 | + this.locationProduct = locationProduct; |
| 134 | + } |
| 135 | + |
| 136 | + public String getEndpointType() { |
| 137 | + return endpointType; |
| 138 | + } |
| 139 | + |
| 140 | + public void setEndpointType(String endpointType) { |
| 141 | + this.endpointType = endpointType; |
| 142 | + } |
| 143 | + |
| 144 | + public String getRegionId() { |
| 145 | + return regionId; |
| 146 | + } |
| 147 | + |
| 148 | + public void setRegionId(String regionId) { |
| 149 | + this.regionId = regionId; |
| 150 | + } |
| 151 | + |
| 152 | + public ProtocolType getProtocol() { |
| 153 | + return protocol; |
| 154 | + } |
| 155 | + |
| 156 | + public void setProtocol(ProtocolType protocol) { |
| 157 | + this.protocol = protocol; |
| 158 | + } |
| 159 | + |
| 160 | + public void putBodyParameter(String name, Object value) { |
| 161 | + setParameter(this.bodyParameters, name, value); |
| 162 | + } |
| 163 | + |
| 164 | + public void putQueryParameter(String name, String value) { |
| 165 | + setParameter(this.queryParameters, name, value); |
| 166 | + } |
| 167 | + |
| 168 | + public void putHeadParameter(String name, String value) { |
| 169 | + setParameter(this.headParameters, name, value); |
| 170 | + } |
| 171 | + |
| 172 | + private void setParameter(Map<String, String> map, String name, Object value) { |
| 173 | + if (null == map || null == name || null == value) { |
| 174 | + return; |
| 175 | + } |
| 176 | + map.put(name, String.valueOf(value)); |
| 177 | + } |
| 178 | + |
| 179 | + public Integer getConnectTimeout() { |
| 180 | + return connectTimeout; |
| 181 | + } |
| 182 | + |
| 183 | + public void setConnectTimeout(Integer connectTimeout) { |
| 184 | + this.connectTimeout = connectTimeout; |
| 185 | + } |
| 186 | + |
| 187 | + public Integer getReadTimeout() { |
| 188 | + return readTimeout; |
| 189 | + } |
| 190 | + |
| 191 | + public void setReadTimeout(Integer readTimeout) { |
| 192 | + this.readTimeout = readTimeout; |
| 193 | + } |
| 194 | + |
| 195 | + public MethodType getMethod() { |
| 196 | + return method; |
| 197 | + } |
| 198 | + |
| 199 | + public void setMethod(MethodType method) { |
| 200 | + this.method = method; |
| 201 | + } |
| 202 | + |
| 203 | + public String getUriPattern() { |
| 204 | + return uriPattern; |
| 205 | + } |
| 206 | + |
| 207 | + public void setUriPattern(String uriPattern) { |
| 208 | + this.uriPattern = uriPattern; |
| 209 | + } |
| 210 | + |
| 211 | + public void putPathParameter(String name, String value) { |
| 212 | + setParameter(this.pathParameters, name, value); |
| 213 | + } |
| 214 | + |
| 215 | + public String getDomain() { |
| 216 | + return domain; |
| 217 | + } |
| 218 | + |
| 219 | + public void setDomain(String domain) { |
| 220 | + this.domain = domain; |
| 221 | + } |
| 222 | + |
| 223 | + public void setHttpContent(byte[] content, String encoding, FormatType format) { |
| 224 | + if (content == null || encoding == null || format == null) { |
| 225 | + return; |
| 226 | + } |
| 227 | + this.httpContent = content; |
| 228 | + this.httpContentType = format; |
| 229 | + this.encoding = encoding; |
| 230 | + } |
| 231 | + |
| 232 | +} |
0 commit comments