ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len = inStream.read(buffer)) !=-1 ){
outStream.write(buffer, 0, len);
}
byte[] data = outStream.toByteArray();//网页的二进制数据
outStream.close();
inStream.close();
return data;
}
public static void main(String args[]) throws Exception {
URL url = new URL("http://10.118.40.55:9004/sasp/saspupload/uploadBase64");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");// 提交模式
// conn.setConnectTimeout(10000);//连接超时 单位毫秒
// conn.setReadTimeout(2000);//读取超时 单位毫秒
conn.setDoOutput(true);// 是否输入参数
conn.setRequestProperty("Content-type", "application/json");
StringBuffer params = new StringBuffer();
// 表单参数与get形式一样
// params.append("aaaaaa");
byte[] bypes = params.toString().getBytes();
conn.getOutputStream().write(bypes);// 输入参数
InputStream inStream=conn.getInputStream();
System.out.println(new String(readInputStream(inStream), "gbk"));
}
@Override
public Result<List<DemoResp>> queryList(Request<String> request) {
HttpServletRequest httpRequest = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class);
HttpHeaders httpHeaders = ResteasyProviderFactory.getContextData(HttpHeaders.class);
logger.info("httpRequest={}, uriInfo={}, httpHeaders={}", httpRequest, uriInfo, httpHeaders);
Result<List<DemoResp>> result = new Result<List<DemoResp>>(true);
List<DemoTestExtend> all = demoManager.selectAll();
if (CollectionUtils.isNotEmpty(all)) {
List<DemoResp> list = ConvertDomainUtils.convertList(all, DemoResp.class);
result.setObj(list);
}
HttpResponse response = ResteasyProviderFactory.getContextData(HttpResponse.class);
response.getOutputHeaders().putSingle("X-Some-Header", "value");
return result;
}
public String uploadBase64( ResultFileUpLoad result) {
//String config = ConfigUtils.getProperty("dubbo.container");
//System.out.println("-----------------------------"+config);
FileOutputStream out = null;
try {
out = new FileOutputStream("E:\\wokertemp\\image\\"+"i"+result.getUsername()+result.getFileName()+"."+result.getImageTypeName());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
out.write( Base64Utils.decodeFromString(result.getBase64Date()));
out.close();
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "sucess";
}
mvn clean package -Puat -Dmaven.test.skip=true