Web服务返回null并且客户端挂起

时间:2015-06-23 09:34:17

标签: json web-services rest jersey

@GET
@Path("/employee/{empId}")
@Produces(MediaType.APPLICATION_JSON)
public EmployeeBean retriveEmployee(@PathParam("empId") String empId) {
    Connection conn = null;

    int status = 503;
    EmployeeBean eBeanResponce = null;//new EmployeeBean();
    List<EmployeeBean> empBeansFetched = null;
    String msg = null;

    try {
        int id = Integer.parseInt(empId);
        String sql = "select * from user where(userId = ?)";
        conn = DataSource.getInstance().getConnection();

        QueryRunner qRun = new QueryRunner();
        ResultSetHandler<List<EmployeeBean>> rsh = new BeanListHandler<EmployeeBean>(
                EmployeeBean.class);

        empBeansFetched = qRun.query(conn, sql, rsh,id);

    } catch (NumberFormatException nfe) {
        msg = "Employee ID must be numeric received " + empId ;

    } catch (SQLException | IOException | PropertyVetoException e) {
        loger.error(e.getMessage());
        e.printStackTrace();
    } finally {
        if (empBeansFetched != null) {

            if (empBeansFetched.size() > 1){
                msg = "More than one row per empId";
                loger.error(msg);
                status=300;
                if(loger.isDebugEnabled()){
                    Iterator<EmployeeBean> itr = empBeansFetched.iterator();
                    while(itr.hasNext()){
                        EmployeeBean e = itr.next();
                        System.out.println(e.getUserId());

                    }
                }
            }
            else if(empBeansFetched.size() == 0){
                msg = "No Such Employee "+ empId;
                loger.error(msg);
                status = 404;
            }
            else {
                status = 201;
                msg = "Sucess";
                eBeanResponce = empBeansFetched.get(0);
            }
        } else {
            loger.error("Retrived NULL from DB");
        }
        closeConnection(conn);
    }
    System.out.println(status + " STATUS");
    Response.status(status).entity(msg).build();
    return eBeanResponce;
}

//这是Web服务的代码片段。 //如果数据库查询无法获取行,则该员工将为null。 //如果我返回null的employee bean对象,我看不到调用完成了。它只是在客户端等待。我已经使用海报插件进行了测试。

0 个答案:

没有答案