gpt4 book ai didi

java - 我无法发送 HTTP 请求(500 内部服务器错误)

转载 作者:行者123 更新时间:2023-12-01 18:28:01 24 4
gpt4 key购买 nike

我目前在发送的 http 请求中收到以下错误。我正在尝试发送一个 JSON 数组列表来触发接收端的一个方法,以便它将列表保存在数据库中。

500 内部服务器错误是一个非常通用的 HTTP 状态代码,表示网站服务器上出现了问题,但服务器无法更具体地说明具体问题是什么。

网站以多种方式表述 500 错误,但它们基本上都在说同一件事:现在存在一般服务器问题。大多数情况下,您无能为力,只能直接联系网站,然后等待他们修复问题。万一您出现问题,请尝试清除缓存并从出现错误的网站中删除所有 Cookie。

请找出以下错误:


org.springframework.web.client.HttpServerErrorException: 500 Internal Server
    public static String FRONT_URL;

public static String BACK_URL;

public static final String REST_SYNC = "rest/sync";
public static final String REST_API = "rest/api";


private Logger log = Logger.getLogger(FrontSynchronizer.class);
static final Logger synclog = Logger.getLogger("sync");

ResourceBundle rb = ResourceBundle.getBundle("bundles.sync-application-resources", Locale.getDefault());
//method sending the request
public void syncApplications(List<SchemeApplication> accList) {

schemeApplicationDto=new SchemeApplicationDto();

FRONT_URL = rb.getString("sync.front.url").concat(REST_SYNC);
BACK_URL = rb.getString("sync.back.url").concat(REST_API);

JSONArray array = new JSONArray();
if (accList != null && accList.size() > 0) {

for (SchemeApplication student : accList) {

schemeApplicationDto.setId(student.getId());
schemeApplicationDto.setAccountID(student.getAccountID());
schemeApplicationDto.setNoOfPersonsEmployedLocal(student.getNoOfPersonsEmployedLocal());
schemeApplicationDto.setLocalmainclients(student.getLocalmainclients());

JSONObject studentJSON = new JSONObject(schemeApplicationDto);
array.put(studentJSON);
}
}
HttpHeaders headers = new HttpHeaders();
JSONObject object = new JSONObject();
object.put("array", array);
headers.setContentType(MediaType.APPLICATION_JSON);
RestTemplate restTemplate = this.createnewTemplate();
String url = BACK_URL.concat("/application");
HttpEntity<String> requestEntity = new HttpEntity<String>(object.toString(), headers);
ResponseEntity<Boolean> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity,
Boolean.class);

if (responseEntity.getBody())

{

for(SchemeApplication scheme:accList) {

schemeApplicationService.getDao().delete(scheme);

}

}

}

public RestTemplate createnewTemplate() {
// RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory());

HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setConnectTimeout(120000);

RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
return restTemplate;
}



// method that needs to process the request
//The method is trying to send an Array list so as the receiving end can receive the list and save it in its database.



@RequestMapping(value = "application", method = RequestMethod.POST)
public Boolean getAllArchivedpplications(@RequestBody String schemeJson) {
List<SchemeApplication> accList = null;
try {
accList = new ArrayList<SchemeApplication>();
if (StringUtils.isNotEmpty(schemeJson)) {

JSONObject listObject = new JSONObject(schemeJson);
JSONArray entryArray = listObject.getJSONArray("array");

for (int i = 0; i < entryArray.length(); i++) {
JSONObject res = new JSONObject(entryArray.get(i).toString());
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
schemeApplication doc = mapper.readValue(res.toString(),
new TypeReference<schemeApplication>() {
});
accList.add(doc);
}
schemeService.getDao().save(accList); // Service.save accountlist;

}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

最佳答案

@RequestBody 必须作用于对象。

关于java - 我无法发送 HTTP 请求(500 内部服务器错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60203280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com