parent
cc228d40eb
commit
6fa803c714
@ -1,17 +0,0 @@
|
|||||||
package ${domain}.frame;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ApiRequest - 基类
|
|
||||||
*
|
|
||||||
* @author wangbing
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 2017-01-01
|
|
||||||
*/
|
|
||||||
public interface ApiRequest<T extends ApiResponse> {
|
|
||||||
|
|
||||||
void check();
|
|
||||||
|
|
||||||
String path();
|
|
||||||
|
|
||||||
Class<T> responseClass();
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package ${domain}.frame;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.wb.api.auth.request.LoginRequest;
|
|
||||||
import com.wb.api.auth.response.LoginResponse;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws ClassNotFoundException {
|
|
||||||
|
|
||||||
//实例化API请求客户端
|
|
||||||
DefaultApiClient defaultApiClient = new DefaultApiClient("http://localhost:8080/api", "qwe", "asd");
|
|
||||||
//设置发送网络请求前的统一操作
|
|
||||||
defaultApiClient.setBefore(new DefaultApiClient.Before() {
|
|
||||||
public void call(ApiRequest request) {
|
|
||||||
System.out.println("请求参数" + JSON.toJSONString(request));
|
|
||||||
System.out.println("请求方法" + request.apiMethod());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//设置网络请求完成后的统一操作
|
|
||||||
defaultApiClient.setAfter(new DefaultApiClient.After() {
|
|
||||||
public void call(ApiRequest request, ApiResponse response) {
|
|
||||||
System.out.println("响应参数" + JSON.toJSONString(response));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
|
|
||||||
|
|
||||||
{
|
|
||||||
//同步接口请求实例
|
|
||||||
System.out.println("--------------------同步接口请求实例-------------------");
|
|
||||||
Date start = new Date();
|
|
||||||
System.out.println(simpleDateFormat.format(start));
|
|
||||||
LoginRequest loginRequest = new LoginRequest();
|
|
||||||
loginRequest.setUserName("admin");
|
|
||||||
loginRequest.setPassword("123456");
|
|
||||||
LoginResponse execute = defaultApiClient.execute(loginRequest);
|
|
||||||
Date end = new Date();
|
|
||||||
System.out.println(simpleDateFormat.format(end));
|
|
||||||
System.out.println("共用" + (end.getTime() - start.getTime()) + "毫秒");
|
|
||||||
System.out.println("--------------------同步接口请求实例-------------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
//文件上传接口请求实例
|
|
||||||
System.out.println("--------------------文件上传接口请求实例-------------------");
|
|
||||||
Date start = new Date();
|
|
||||||
System.out.println(simpleDateFormat.format(start));
|
|
||||||
FileUploadRequest fileUploadRequest = new FileUploadRequest();
|
|
||||||
fileUploadRequest.setFile(new File("E:\\doc\\pic\\QQ截图20160918164514.jpg"));
|
|
||||||
defaultApiClient.fileUpload(fileUploadRequest, new ApiClient.Callback<FileUploadResponse>() {
|
|
||||||
public void call(FileUploadResponse response) {
|
|
||||||
System.out.println("文件上传接口请求实例" + JSON.toJSONString(response));
|
|
||||||
Date end = new Date();
|
|
||||||
System.out.println(simpleDateFormat.format(end));
|
|
||||||
System.out.println("共用" + (end.getTime() - start.getTime()) + "毫秒");
|
|
||||||
System.out.println("--------------------文件上传接口请求实例-------------------");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
//异步接口请求实例
|
|
||||||
System.out.println("--------------------异步接口请求实例-------------------");
|
|
||||||
final Date start = new Date();
|
|
||||||
System.out.println(simpleDateFormat.format(start));
|
|
||||||
LoginRequest loginRequest = new LoginRequest();
|
|
||||||
loginRequest.setUserName("admin");
|
|
||||||
loginRequest.setPassword("123456");
|
|
||||||
defaultApiClient.asyncExecute(loginRequest, 1L, new ApiClient.Callback<LoginResponse>() {
|
|
||||||
public void call(LoginResponse response) {
|
|
||||||
System.out.println("异步接口请求响应" + JSON.toJSONString(response));
|
|
||||||
|
|
||||||
Date end = new Date();
|
|
||||||
System.out.println(simpleDateFormat.format(end));
|
|
||||||
System.out.println("共用" + (end.getTime() - start.getTime()) + "毫秒");
|
|
||||||
System.out.println("--------------------异步接口请求实例-------------------");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,23 @@
|
|||||||
|
package ${domain}.frame.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class BaseRequest<T extends BaseResponse> {
|
||||||
|
|
||||||
|
void check() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String path() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<T> responseClass() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package ${domain}.frame.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BaseUpdateRequest - 基类
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class BaseUpdateRequest extends BaseRequest{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本戳
|
||||||
|
*/
|
||||||
|
private long rowVersion;
|
||||||
|
|
||||||
|
public long getRowVersion() {
|
||||||
|
return rowVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRowVersion(long rowVersion) {
|
||||||
|
this.rowVersion = rowVersion;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.base;
|
||||||
|
|
||||||
public class Error {
|
public class Error {
|
||||||
private ErrorType type;
|
private ErrorType type;
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.base;
|
||||||
|
|
||||||
public enum ErrorType {
|
public enum ErrorType {
|
||||||
BUSINESS_ERROR,
|
BUSINESS_ERROR,
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SortType - 排序方式
|
* SortType - 排序方式
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.okhttp3;
|
||||||
|
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
import okhttp3.MultipartBody;
|
import okhttp3.MultipartBody;
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BytesUtil - 字节数组工具类
|
* BytesUtil - 字节数组工具类
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.TreeNode;
|
import com.fasterxml.jackson.core.TreeNode;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
private StringUtils() {
|
private StringUtils() {
|
@ -1,4 +1,4 @@
|
|||||||
package ${domain}.frame;
|
package ${domain}.frame.utils;
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.Validation;
|
import javax.validation.Validation;
|
Loading…
Reference in new issue