TestGateWay.java
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.diligrp.getway.test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.diligrp.mobsite.getway.domain.protocol.saler.order.GetOutOrderListReq;
import com.diligrp.mobsite.getway.domain.protocol.saler.order.GetOutOrderListResp;
import com.diligrp.titan.sdk.http.BasicHttpClient;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
/**
* Created by david on 2015/10/30.
*/
public class TestGateWay {
private final static String ENCODE = "UTF8";
public static void main(String [] args) {
for (int i = 0 ; i< Long.parseLong(args[0]);i++) {
GetOutOrderListReq req = new GetOutOrderListReq();
// req.setGuardId(248l);
// req.setBuyerId(4154l);
req.setGuardId(Long.parseLong(args[1]));
req.setBuyerId(Long.parseLong(args[2]));
req.setTimeEnd(1446134400000l);
GetOutOrderListResp output = new GetOutOrderListResp();
output = execute("http://mobapi.nong12.com/mobsiteApp/outorder/order/getOrders.do", req, output, new TypeReference<GetOutOrderListResp>() {
});
System.out.println(output);
}
}
private static <T extends GetOutOrderListResp> T execute(String path, Object paramObj, T output, TypeReference type) {
try {
HttpPost post = new HttpPost(path);
post.addHeader("Content-type", "application/json");
String body = JSON.toJSONString(paramObj);
StringEntity entity = new StringEntity(body, ENCODE);
post.setEntity(entity);
HttpResponse response = BasicHttpClient.getHttpClient(0).execute(post);
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
String message = EntityUtils.toString(response.getEntity(), ENCODE);
output = (T) JSON.parseObject(message, type);
} else {
output.setCode(status);
}
} catch (Exception e) {
System.err.println(e);
output.setMsg(e.getMessage());
}
return output;
}
}