Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.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/8/mysql/60.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 RestFul服务问题_Java_Rest - Fatal编程技术网

Java RestFul服务问题

Java RestFul服务问题,java,rest,Java,Rest,正在尝试设置用于更新数据库表的restful服务组件。尝试同时使用SpringRESTTemplate和ApacheCommonsRESTfulImpl,但两种方法似乎都无效 关于使用 选项1:使用Spring RestTemplate:导致以下错误 com.fasterxml.jackson.databind.JsonMappingException:无法从START\u数组令牌中反序列化java.util.LinkedHashMap的实例 选项2:使用org.apache.commons.h

正在尝试设置用于更新数据库表的restful服务组件。尝试同时使用SpringRESTTemplate和ApacheCommonsRESTfulImpl,但两种方法似乎都无效

关于使用
选项1:使用Spring RestTemplate:导致以下错误
com.fasterxml.jackson.databind.JsonMappingException:无法从START\u数组令牌中反序列化java.util.LinkedHashMap的实例
选项2:使用org.apache.commons.httpclient.methods.PostMethod;导致以下错误
服务器端错误:

org.codehaus.jackson.JsonParseException:意外字符(“之后,我更改了方法UpdateMainPtData的签名,并添加了returntype和@ResponseBy以解决此问题。

在选项1中,您将formModelData发送到哪里?在我看来,您发送的是一个空列表,但服务器需要一个映射。感谢您指出这一点。我已修改了我的问题,以包括formModelData。我重新部署了我的code但我仍然看到选项1的HTTP 404错误,这是由错误com.fasterxml.jackson.databind.JsonMappingException引起的:无法从选项1的START_数组令牌中反序列化java.util.LinkedHashMap实例,在选项1中直接作为SOI传递模型数据,直接作为so传递模型数据:'新HTTP实体(formmodeldata,headers)“。我正在努力使用智能手机。@amadeus:我做了您建议的更改,但错误仍然存在。错误:org.springframework.web.servlet.FrameworkServlet.processRequest:910 |无法完成请求。找不到org.springframework.web.client.HttpClientErrorException:404
    @RequestMapping(value="/update", consumes="application/json")
public void updateMaintReport(
        @RequestBody Map<String, String> formModelData, 
        HttpServletRequest request, 
        HttpServletResponse response) 
        throws IOException,JsonMappingException {
    logger.log(LogLevel.DEBUG, "REACHED method updateMaintReport..");
    System.out.println("Reached method updateMaintReport.....");
    boolean errorEncountered = false;
    ReportingSession repSession = null;
    HttpSession session = request.getSession(false);

    if(session==null) {
        // TODO: code for handling invalid/expired session
    } else {
        repSession = (ReportingSession)session.getAttribute(ReportingWebConstants.REPORTING_SESSION);
        if(repSession==null) {
            errorEncountered = true;
        } 
    }

    if(!errorEncountered) {

        ServiceClient serviceClient = new ServiceClient();

        String servicesUrl = this.environment.getProperty("service_url_reports_data");
        String servicesName = this.environment.getProperty("service_name_reports_update_fnol");
        String serviceUrl = VIPUrlFactory.getServiceUrl(servicesUrl+servicesName);
        logger.log(LogLevel.DEBUG, "For update : serviceUrl: "+serviceUrl);

//Option 1: Using Spring RestTemplate :             
        LinkedMultiValueMap<String,String> headers = new LinkedMultiValueMap<String,String>();
        headers.add("Accept","application/json");
        headers.add("Content-type","application/json");
        List list = new ArrayList<Map<String, String>>(); list.add(formModelData);
        RestTemplate restTemplate = new RestTemplate();
        HttpEntity<List> requestEntity = new HttpEntity<List>(list, headers);

        ResponseEntity<List> fList = restTemplate.exchange(serviceUrl,
                HttpMethod.POST, 
                 requestEntity,
                List.class);


//Option 2: using org.apache.commons.httpclient.methods.PostMethod; -- Will be commented when option 1 block is uncommented     
        serviceClient.setParams(formModelData);
        serviceClient.setServiceUrl(serviceUrl);
        serviceClient.callRestServicePost();

        logger.log(LogLevel.DEBUG, "Posting data to service - to execute the update");

    }

}        
    @RequestMapping(value = "/update", method = RequestMethod.POST)
public void updateMainRptData(@RequestBody Map<String, String> formModelData) throws ReportingIntegrationException,
        IOException, JsonMappingException {
    String updateStmt = "UPDATE CL_SCRIPTS SET DELETE_IND = #{delete_ind},  SCRIPT_DESC = #{script_desc}, SCRIPT_TXT = #{script_txt}WHERE   COMPANY_CD = #{company_cd} AND SCRIPT_NAME = #{script_name}AND PROMPT_ID = #{prompt_id}";
    ParameterObjectDTO paramObjDTO = new ParameterObjectDTO();

    logger.log(LogLevel.DEBUG,"In Services Web: updateMainRptData()");

    if(!formModelData.isEmpty()) {
        Set<String> keySet = formModelData.keySet();
        StringBuilder sb = new StringBuilder();
        for (String key : keySet) {
            sb.append(key).append(" -- ").append(formModelData.get(key)).append("\n");
        }
        logger.log(LogLevel.DEBUG, sb.toString());
    }

    paramObjDTO.setModalForQuery(formModelData);
    paramObjDTO.setUpdateSqlStmt(updateStmt);
    maintReportingSvc.updateMaintReport(paramObjDTO);

}