Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我无法发送HTTP请求(500内部服务器错误)_Java_Spring_Http_Post - Fatal编程技术网

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

Java 我无法发送HTTP请求(500内部服务器错误),java,spring,http,post,Java,Spring,Http,Post,我当前收到以下关于我正在发送的http请求的错误。我试图发送一个JSON数组列表来触发接收端的一个方法,以便它将列表保存在数据库中 500内部服务器错误是一个非常通用的HTTP状态代码,这意味着网站的服务器出现了问题,但服务器无法更具体地说明确切的问题是什么 网站在很多方面都会指出500个错误,但它们基本上都在说同样的事情:现在有一个普遍的服务器问题。 大多数情况下,你除了直接联系网站,然后等待他们修复外,别无选择。 如果您的终端出现问题,请尝试清除缓存并删除站点中的任何cookie,并显示错误

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

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

网站在很多方面都会指出500个错误,但它们基本上都在说同样的事情:现在有一个普遍的服务器问题。 大多数情况下,你除了直接联系网站,然后等待他们修复外,别无选择。 如果您的终端出现问题,请尝试清除缓存并删除站点中的任何cookie,并显示错误

请在下面查找错误:


org.springframework.web.client.HttpServerErrorException: 500 Internal Server 
publicstaticstringfront\uurl;
公共静态字符串返回URL;
公共静态最终字符串REST\u SYNC=“REST/SYNC”;
公共静态最终字符串REST\u API=“REST/API”;
专用记录器log=Logger.getLogger(FrontSynchronizer.class);
静态最终记录器synclog=Logger.getLogger(“同步”);
ResourceBundle rb=ResourceBundle.getBundle(“bundles.sync应用程序资源”,Locale.getDefault());
//方法发送请求
公共应用程序(列表帐户列表){
schemeApplicationDto=新schemeApplicationDto();
FRONT\u URL=rb.getString(“sync.FRONT.URL”).concat(REST\u sync);
BACK\u URL=rb.getString(“sync.BACK.URL”).concat(REST\u API);
JSONArray数组=新的JSONArray();
if(accList!=null&&accList.size()>0){
for(SchemeApplication学生:accList){
schemeApplicationDto.setId(student.getId());
schemeApplicationDto.setAccountID(student.getAccountID());
schemeApplicationDto.setNoofpersonEmployedLocal(student.getNoofpersonEmployedLocal());
schemeApplicationDto.SetLocalMainClient(student.GetLocalMainClient());
JSONObject studentJSON=新的JSONObject(schemeApplicationDto);
put(studentJSON);
}
}
HttpHeaders=新的HttpHeaders();
JSONObject对象=新的JSONObject();
put(“数组”,数组);
headers.setContentType(MediaType.APPLICATION_JSON);
RestTemplate RestTemplate=this.createnewTemplate();
字符串url=BACK_url.concat(“/application”);
HttpEntity requestEntity=新的HttpEntity(object.toString(),headers);
ResponseEntity ResponseEntity=restTemplate.exchange(url、HttpMethod.POST、requestEntity、,
布尔类);
if(responseEntity.getBody())
{
for(SchemeApplication scheme:accList){
schemeApplicationService.getDao().delete(方案);
}
}
}
公共RestTemplate createnewTemplate(){
//RestTemplate RestTemplate=新的RestTemplate(clientHttpRequestFactory());
HttpComponents客户端httpRequestFactory httpRequestFactory=新的HttpComponents客户端httpRequestFactory();
httpRequestFactory.setConnectTimeout(120000);
RestTemplate RestTemplate=新的RestTemplate(httpRequestFactory);
返回REST模板;
}
//需要处理请求的方法
//该方法尝试发送一个数组列表,以便接收端可以接收该列表并将其保存在其数据库中。
@RequestMapping(value=“application”,method=RequestMethod.POST)
公共布尔GetAllArchivedApplication(@RequestBody String schemeJson){
List accList=null;
试一试{
accList=newarraylist();
if(StringUtils.isNotEmpty(schemeJson)){
JSONObject listObject=新的JSONObject(schemeJson);
JSONArray entryArray=listObject.getJSONArray(“数组”);
对于(int i=0;i
@RequestBody必须在对象上工作。

执行此类工作的标准方法有两种:

  • 通过
    @RequestBody
    注释形成一个类,该类的类文件与您要发送的json数据具有相同的名称和结构,并捕获该数据
  • 当您以字符串形式发送数据时,请将其作为请求参数发送,并使用
    @RequestParam
    而不是
    @RequestBody
    ,并解析您需要执行操作的方式。因为我认为对于您正在处理的这种大容量数据的arrayList,选项1会更好/可行。 有关详细信息,您可以在此处查看:

  • 欢迎来到SO!请详细说明你的答案,在目前的形式下,它将立即被否决或删除。有关更多指导,请参见对象已转换为请求实体的字符串。
        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;
            }
        }