Commit bfbe4105 by 徐高华

TEST

parent 176ddcd1
......@@ -5,10 +5,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.net.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
......@@ -31,6 +28,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
......@@ -605,4 +603,58 @@ public class TestController extends WebBaseController {
}
return null;
}
public static String httpRequest(String requestUrl, String requestMethod, String outputStr, int timeOut) {
if (timeOut == 0) {
timeOut = 1000;
}
try {
URL url = new URL(requestUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setReadTimeout(timeOut);
conn.setRequestMethod(requestMethod);
if (null != outputStr) {
OutputStream outputStream = conn.getOutputStream();
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
InputStream inputStream = conn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
StringBuilder buffer = new StringBuilder();
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
inputStream = null;
conn.disconnect();
return buffer.toString();
} catch (ConnectException ce) {
ce.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping("self-check")
@ResponseBody
public Object self(String ips){
if(StringUtils.isEmpty(ips)) {
ips = "121.36.247.198,60.204.155.186,123.60.35.52,124.70.140.207,121.37.130.214,122.9.64.47,116.63.51.145,122.9.68.94,122.9.190.110" ;
}
String[] arr = ips.split(",") ;
Map<String,String> map = new HashMap<>() ;
for(String ip : arr) {
String s = httpRequest("http://"+ip+":8990/api-qywx-self/index.html","GET",null,3) ;
map.put("ip",s) ;
}
return map ;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment