Skip to content

Commit b1ab15a

Browse files
author
codezhang
committed
修改 参数校验工具参数传递错误的bug,完成DescribeVPCIntercom
1 parent ca948ec commit b1ab15a

8 files changed

Lines changed: 282 additions & 12 deletions

File tree

ucloud-sdk-java-common/src/main/java/cn/ucloud/util/ParamConstructor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,26 @@ public class ParamConstructor {
2424
* @throws Exception 可能是NullPointerException(参数对象为空)或者ValidatorException(参数对象属性不满足要求)
2525
*/
2626
public static String getHttpGetParamString(BaseRequestParam baseRequestParam, Account account) throws Exception {
27-
StringBuilder builder = new StringBuilder();
2827
// 设置publicKey
2928
baseRequestParam.setPublicKey(account.getPublicKey());
3029
// 将参数对象转成List<Param>
3130
List<Param> paramList = ObjectToParam.objectToParams(baseRequestParam);
3231
// 获取签名字符串
3332
String signature = Signature.getSignature(paramList, account);
33+
// 设置签名 到参数对象
34+
baseRequestParam.setSignature(signature);
3435
// 参数校验
35-
ParamValidator.validator(paramList);
36+
ParamValidator.validator(baseRequestParam);
3637
// url编码
3738
Signature.urlEncodeParams(paramList);
39+
// 构造url参数
40+
StringBuilder builder = new StringBuilder();
3841
for (Param param : paramList) {
3942
if (StringUtils.isBlank(param.getParamKey())){
4043
continue;
4144
}
4245
builder.append(param.getParamKey() + "=" + param.getParamValue() + "&");
4346
}
44-
4547
// 设置签名
4648
builder.append("Signature" + "=" + signature);
4749
return builder.toString();

ucloud-sdk-java-vpc/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<groupId>junit</groupId>
2222
<artifactId>junit</artifactId>
2323
</dependency>
24+
2425
</dependencies>
2526

2627

ucloud-sdk-java-vpc/src/main/java/cn/ucloud/client/DefaultVPCClient.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,18 @@ public void createVPCIntercom(CreateVPCIntercomParam param, UcloudHandler handle
177177
}
178178

179179
@Override
180-
public BaseResponseResult describeVPCIntercom(BaseRequestParam param) throws Exception {
181-
return null;
180+
public DescribeVPCIntercomResult describeVPCIntercom(DescribeVPCIntercomParam param) throws Exception {
181+
UcloudHttp http = new UcloudHttpImpl(DescribeVPCIntercomResult.class);
182+
DescribeVPCIntercomResult result = (DescribeVPCIntercomResult) http.doGet(param, config, null);
183+
return result;
182184
}
183185

184186
@Override
185-
public void describeVPCIntercom(BaseRequestParam param, UcloudHandler handler, Boolean... asyncFlag) {
186-
187+
public void describeVPCIntercom(DescribeVPCIntercomParam param, UcloudHandler handler, Boolean... asyncFlag) {
188+
UcloudHttp http = new UcloudHttpImpl(DescribeVPCIntercomResult.class);
189+
try {
190+
http.doGet(param, config, handler,asyncFlag);
191+
} catch (Exception e) { }
187192
}
188193

189194
@Override

ucloud-sdk-java-vpc/src/main/java/cn/ucloud/client/VPCClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,20 @@ public interface VPCClient {
186186

187187

188188
/**
189-
*
189+
* 获取VPC互通信息
190190
* @param param 参数对象
191191
* @return 结果对象
192192
* @throws Exception 出错则抛出异常
193193
*/
194-
BaseResponseResult describeVPCIntercom(BaseRequestParam param) throws Exception;
194+
DescribeVPCIntercomResult describeVPCIntercom(DescribeVPCIntercomParam param) throws Exception;
195195

196196
/**
197-
*
197+
* 获取VPC互通信息
198198
* @param param 参数对象
199199
* @param handler 回调处理器
200200
* @param asyncFlag 异步标记,默认异步true
201201
*/
202-
void describeVPCIntercom(BaseRequestParam param, UcloudHandler handler, Boolean... asyncFlag);
202+
void describeVPCIntercom(DescribeVPCIntercomParam param, UcloudHandler handler, Boolean... asyncFlag);
203203

204204

205205
/**

ucloud-sdk-java-vpc/src/main/java/cn/ucloud/model/CreateVPCIntercomParam.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public class CreateVPCIntercomParam extends BaseRequestParam {
3737
/**
3838
* optional 地域。 目的所在地域(如果目的VPC和源VPC不在同一个地域,两个地域需要建立跨域通道,且该字段必选)
3939
*/
40-
@NotEmpty(message = "dstRegion can not be empty")
4140
@UcloudParam("DstRegion")
4241
private String dstRegion;
4342

43+
4444
/**
4545
* optional 目的项目ID
4646
*/
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package cn.ucloud.model;
2+
3+
import cn.ucloud.annotation.UcloudParam;
4+
import cn.ucloud.pojo.BaseRequestParam;
5+
6+
import javax.validation.constraints.NotEmpty;
7+
8+
/**
9+
* @description: 获取VPC互通信息 参数类
10+
* @author: codezhang
11+
* @date: 2018-09-21 17:30
12+
**/
13+
14+
public class DescribeVPCIntercomParam extends BaseRequestParam {
15+
/**
16+
* require 地域。 参见 [地域和可用区列表](../summary/regionlist.html)
17+
*/
18+
@NotEmpty(message = "region can not be empty")
19+
@UcloudParam("Region")
20+
private String region;
21+
22+
/**
23+
* require 源VPC短ID
24+
*/
25+
@NotEmpty(message = "vpcId can not be empty")
26+
@UcloudParam("VPCId")
27+
private String vpcId;
28+
29+
/**
30+
* optional 地域。 目的所在地域(如果目的VPC和源VPC不在同一个地域,两个地域需要建立跨域通道,且该字段必选)
31+
*/
32+
@UcloudParam("DstRegion")
33+
private String dstRegion;
34+
35+
36+
37+
/**
38+
* optional 目的项目ID
39+
*/
40+
@UcloudParam("DstProjectId")
41+
private String dstProjectId;
42+
43+
public DescribeVPCIntercomParam(@NotEmpty(message = "region can not be empty") String region,
44+
@NotEmpty(message = "vpcId can not be empty") String vpcId) {
45+
super("DescribeVPCIntercom");
46+
this.region = region;
47+
this.vpcId = vpcId;
48+
}
49+
50+
public String getDstRegion() {
51+
return dstRegion;
52+
}
53+
54+
public void setDstRegion(String dstRegion) {
55+
this.dstRegion = dstRegion;
56+
}
57+
58+
public String getDstProjectId() {
59+
return dstProjectId;
60+
}
61+
62+
public void setDstProjectId(String dstProjectId) {
63+
this.dstProjectId = dstProjectId;
64+
}
65+
66+
public String getRegion() {
67+
68+
return region;
69+
}
70+
71+
public void setRegion(String region) {
72+
this.region = region;
73+
}
74+
75+
public String getVpcId() {
76+
return vpcId;
77+
}
78+
79+
public void setVpcId(String vpcId) {
80+
this.vpcId = vpcId;
81+
}
82+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package cn.ucloud.model;
2+
3+
import cn.ucloud.pojo.BaseResponseResult;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @description:
10+
* @author: codezhang
11+
* @date: 2018-09-21 17:44
12+
**/
13+
14+
public class DescribeVPCIntercomResult extends BaseResponseResult {
15+
16+
17+
public static class VPCIntercom{
18+
19+
/**
20+
* 项目Id
21+
*/
22+
@SerializedName("ProjectId")
23+
private String projectId;
24+
25+
/**
26+
* VPC的地址空间
27+
*/
28+
@SerializedName("Network")
29+
private List<String> networks;
30+
31+
/**
32+
* 所属地域
33+
*/
34+
@SerializedName("DstRegion")
35+
private String dstRegion;
36+
37+
/**
38+
* VPC名字
39+
*/
40+
@SerializedName("Name")
41+
private String name;
42+
43+
/**
44+
* VPCId
45+
*/
46+
@SerializedName("VPCId")
47+
private String vpcId;
48+
49+
/**
50+
* 业务组(未分组显示为 Default)
51+
*/
52+
@SerializedName("Tag")
53+
private String tag;
54+
55+
public String getProjectId() {
56+
return projectId;
57+
}
58+
59+
public void setProjectId(String projectId) {
60+
this.projectId = projectId;
61+
}
62+
63+
public List<String> getNetworks() {
64+
return networks;
65+
}
66+
67+
public void setNetworks(List<String> networks) {
68+
this.networks = networks;
69+
}
70+
71+
public String getDstRegion() {
72+
return dstRegion;
73+
}
74+
75+
public void setDstRegion(String dstRegion) {
76+
this.dstRegion = dstRegion;
77+
}
78+
79+
public String getName() {
80+
return name;
81+
}
82+
83+
public void setName(String name) {
84+
this.name = name;
85+
}
86+
87+
public String getVpcId() {
88+
return vpcId;
89+
}
90+
91+
public void setVpcId(String vpcId) {
92+
this.vpcId = vpcId;
93+
}
94+
95+
public String getTag() {
96+
return tag;
97+
}
98+
99+
public void setTag(String tag) {
100+
this.tag = tag;
101+
}
102+
103+
104+
@Override
105+
public String toString() {
106+
return "VPCIntercom{" +
107+
"projectId='" + projectId + '\'' +
108+
", networks=" + networks +
109+
", dstRegion='" + dstRegion + '\'' +
110+
", name='" + name + '\'' +
111+
", vpcId='" + vpcId + '\'' +
112+
", tag='" + tag + '\'' +
113+
'}';
114+
}
115+
}
116+
117+
/**
118+
* 联通VPC信息数组
119+
*/
120+
@SerializedName("DataSet")
121+
private List<VPCIntercom> vpcIntercoms;
122+
123+
public List<VPCIntercom> getVpcIntercoms() {
124+
return vpcIntercoms;
125+
}
126+
127+
public void setVpcIntercoms(List<VPCIntercom> vpcIntercoms) {
128+
this.vpcIntercoms = vpcIntercoms;
129+
}
130+
131+
@Override
132+
public String toString() {
133+
return "DescribeVPCIntercomResult{" +
134+
"vpcIntercoms=" + vpcIntercoms +
135+
", retCode=" + retCode +
136+
", action='" + action + '\'' +
137+
", message='" + message + '\'' +
138+
'}';
139+
}
140+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cn.ucloud.client;
2+
3+
import cn.ucloud.model.DescribeVPCIntercomParam;
4+
import cn.ucloud.model.DescribeVPCIntercomResult;
5+
import cn.ucloud.pojo.Account;
6+
import cn.ucloud.pojo.VPCConfig;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
/**
11+
* @description:
12+
* @author: codezhang
13+
* @date: 2018-09-21 17:57
14+
**/
15+
public class DescribeVPCIntercomTest {
16+
17+
private VPCClient client;
18+
19+
private DescribeVPCIntercomParam param;
20+
21+
@Before
22+
public void initData() {
23+
client = new DefaultVPCClient(new VPCConfig(
24+
new Account(System.getenv("UcloudPrivateKey"),
25+
System.getenv("UcloudPublicKey"),
26+
System.getenv("UcloudPassword"))));
27+
param = new DescribeVPCIntercomParam("cn-bj2","uvnet-lsltj0");
28+
param.setProjectId("org-4nfe1i");
29+
}
30+
31+
@Test
32+
public void describeVPCIntercom() {
33+
try {
34+
DescribeVPCIntercomResult describeVPCIntercomResult = client.describeVPCIntercom(param);
35+
System.out.println(describeVPCIntercomResult);
36+
} catch (Exception e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)