no message

main
이범준 2 months ago
parent 9ca6519294
commit f8dcafc7b4

@ -16,6 +16,13 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.util.ObjectUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
public class MultipartTest {
HttpClient httpClient;
@ -28,6 +35,38 @@ public class MultipartTest {
private static final String DOUBLE_HYPHEN = "--";
private static final String QUTATE = "\"";
public Map<String,Object> getFileList(String url) throws IOException {
String resBody = "";
httpClient = HttpClient.newHttpClient();
httpRequest = HttpRequest.newBuilder()
.uri(URI.create(url))
.setHeader("Accept-Language", "ko")
.setHeader("Content-Type", "application/json")
.GET()
.build();
try {
HttpResponse<String> getResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
resBody = getResponse.body();
} catch (InterruptedException e) {
e.printStackTrace();
}
Map<String, Object> map = null;
try {
JSONParser parser = new JSONParser();
JSONObject jsonResult = (JSONObject)parser.parse(resBody);
map = getMapFromJSONObject(jsonResult);
} catch (ParseException e) {
e.printStackTrace();
}
return map;
}
public void fileDown(String url, String downloadPath) throws IOException {
httpClient = HttpClient.newHttpClient();
@ -67,6 +106,7 @@ public class MultipartTest {
try {
HttpResponse<String> response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
} catch (InterruptedException e) {
e.printStackTrace();
}
@ -126,4 +166,16 @@ public class MultipartTest {
return HttpRequest.BodyPublishers.ofByteArrays(byteArrays);
}
public static Map<String, Object> getMapFromJSONObject(JSONObject obj) {
if (ObjectUtils.isEmpty(obj)) {
throw new IllegalArgumentException(String.format("BAD REQUEST obj %s", obj));
}
try {
return new ObjectMapper().readValue(obj.toJSONString(), Map.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@ -7,7 +7,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import javax.annotation.Resource;
@ -182,15 +184,17 @@ public class NxrpController extends AbstractController {
System.out.println("getSiToTest0 3");
try {
MultipartTest mt = new MultipartTest();
mt.fileDown(url+"/is/rentcar/intf/nxrp/getSiToTest.do", "files/temp/receiveDriver/"
+"EBF_1741000NIS_Z000001LGE_2001_20251020105059452@6510000ECA.zip");
} catch (Exception e) {
System.out.println("down fail");
MultipartTest mt0 = new MultipartTest();
Map<String, Object> map = mt0.getFileList(url+"/is/rentcar/intf/nxrp/getSiToTest1.do");
if(map == null || map.get("names") == null) {
return jsonView;
}
List<String> names = (List<String>)map.get("names");
for(String name : names) {
MultipartTest mt = new MultipartTest();
mt.fileDown(url+"/is/rentcar/intf/nxrp/getSiToTest2.do", "files/temp/receiveDriver/"
+name);
}
System.out.println("getSiToTest0 4");
@ -202,15 +206,9 @@ public class NxrpController extends AbstractController {
System.out.println("1!!!");
return jsonView;
}
System.out.println("getSiToTest0 7");
System.out.println("getSiToTest0 6");
if(fl[0].length() == 0) {
System.out.println("2!!!");
fl[0].delete();
return jsonView;
}
System.out.println("getSiToTest0 7");
List<Hirer> results = nisIndivBean.getCarDriverInfoFromFile();
for(Hirer result : results) {
nisIndivBean.updateDriverInfo(result);
@ -218,13 +216,31 @@ public class NxrpController extends AbstractController {
jsonView.addObject("res", "ok");
return jsonView;
}
//테스트 면허정보응답파일 가져오기
@RequestMapping(name="getSiToTest1", value="/getSiToTest1.do")
public ModelAndView getSiToTest1(NisIndivQuery req) throws IOException {
ModelAndView jsonView = new ModelAndView("jsonView");
nisIndivBean.get_SI_to_DO();
File folder = new File("files/temp/receiveDriver");
File[] fl = folder.listFiles();
if(fl == null || fl.length == 0) {
return jsonView;
}
List<String> names = new ArrayList<String>();
for(File f : fl) {
names.add(f.getName());
}
jsonView.addObject("names", names);
return jsonView;
}
//테스트 면허정보응답파일 가져오기
@RequestMapping(name="getSiToTest", value="/getSiToTest.do")
public ModelAndView getSiToTest(NisIndivQuery req) throws IOException {
@RequestMapping(name="getSiToTest2", value="/getSiToTest2.do")
public ModelAndView getSiToTest2(NisIndivQuery req) throws IOException {
ModelAndView dv = new ModelAndView("downloadView");
nisIndivBean.get_SI_to_DO();
File folder = new File("files/temp/receiveDriver");
File[] fl = folder.listFiles();

Loading…
Cancel
Save