Search in sources :

Example 21 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project portal by ixinportal.

the class HomeController method register.

// @RequestMapping(value = "/s/{name}")
public String register(@PathVariable("name") String name, @RequestParam(value = "login", required = false) String login, HttpSession session, Model uiModel) {
    ProductExample productExample = new ProductExample();
    ProductExample.Criteria pe = productExample.createCriteria();
    pe.andProNameEqualTo(name);
    Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByExample", productExample);
    // return
    // "forward:/userInfoWeb/zhuce.html?projectId="+product.getProject()+"&productId="+product.getId();
    uiModel.addAttribute("projectId", product.getProject());
    uiModel.addAttribute("productId", product.getId());
    if (StringUtils.isNotBlank(login) && login.equals("1")) {
        List<String> allIssUerDn = new ArrayList<String>();
        allIssUerDn = sqlSession.selectList("com.itrus.portal.db.CrlContextMapper.selectAllIssUerDn");
        try {
            uiModel.addAttribute("allIssUerDn", jsonTool.writeValueAsString(allIssUerDn));
            // 返回随机数
            String random = UniqueIDUtils.genUUID();
            uiModel.addAttribute("random", random);
            session.setAttribute("webrandom", random);
        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "ixinweb/denglu2";
    }
    if (null != product.getIsBan() && product.getIsBan() == true) {
        EnterpriseQqExample enterprise = new EnterpriseQqExample();
        EnterpriseQqExample.Criteria qqEx = enterprise.createCriteria();
        qqEx.andProjectIdEqualTo(product.getProject());
        EnterpriseQq enterpriseqq = sqlSession.selectOne("com.itrus.portal.db.EnterpriseQqMapper.selectByExample", enterprise);
        uiModel.addAttribute("enterpriseqq", enterpriseqq.getEnterpriseQqLinks());
        // 产品已经下架
        return "ixinweb/chanpinxiajia";
    }
    return "ixinweb/zhuce";
}
Also used : EnterpriseQq(com.itrus.portal.db.EnterpriseQq) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ProductExample(com.itrus.portal.db.ProductExample) Product(com.itrus.portal.db.Product) EnterpriseQqExample(com.itrus.portal.db.EnterpriseQqExample) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 22 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project portal by ixinportal.

the class UserInfoWebController method choiceEnterprise.

/**
 * 选择企业
 *
 * @param request
 * @return
 */
@RequestMapping("/choiceEnterprise")
public String choiceEnterprise(@RequestParam(value = "noProduct", required = false) String noProduct, HttpServletRequest request, Model uiModel) {
    HttpSession session = request.getSession();
    UserInfo userInfo = (UserInfo) session.getAttribute("webuserInfo");
    Boolean webnoProduct = (Boolean) session.getAttribute("webnoProduct");
    if (null == userInfo) {
        // 登录状态失效,跳转到登录页面
        return "redirect:/userInfoWeb/denglu.html";
    }
    // 查询用户关联的企业list
    List<Enterprise> enterpriseList = new ArrayList<Enterprise>();
    List<Long> enterpriseIds = userInfoEnterpriseServiceImpl.getEnterpriseByUserInfo(userInfo.getId());
    if (null != enterpriseIds && !enterpriseIds.isEmpty()) {
        enterpriseList = enterpriseService.getEnterpriseListByIds(enterpriseIds);
    }
    uiModel.addAttribute("enterpriseSize", enterpriseList.size());
    try {
        uiModel.addAttribute("enterpriseList", jsonTool.writeValueAsString(enterpriseList));
        uiModel.addAttribute("enterprises", enterpriseList);
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // 存在有未关联企业的填写中订单,则添加填写中企业按钮:
    uiModel.addAttribute("hasEditBill", 0);
    List<EditBill> ebList = editBillService.getEditBill(userInfo.getId(), null);
    if (0 != ebList.size() && !ebList.isEmpty()) {
        uiModel.addAttribute("hasEditBill", 1);
        if (0 == enterpriseList.size()) {
            return "redirect:/userInfoWeb/editBillList";
        }
    }
    session.removeAttribute("sessionPlist");
    session.removeAttribute("enterpriseqqE");
    if (session.getAttribute("webprojectId") != null) {
        Long pid = Long.parseLong(session.getAttribute("webprojectId").toString());
        System.out.println("userInfo_=" + pid);
        if (null != pid) {
            // userInfo = userInfoService.getUserInfoById(userInfo.getId());
            EnterpriseQqExample enterpriseE = new EnterpriseQqExample();
            EnterpriseQqExample.Criteria qqEx = enterpriseE.createCriteria();
            qqEx.andProjectIdEqualTo(pid);
            EnterpriseQq enterpriseqq = sqlSession.selectOne("com.itrus.portal.db.EnterpriseQqMapper.selectByExample", enterpriseE);
            if (enterpriseqq != null && enterpriseqq.getEnterpriseQqLinks() != null) {
                uiModel.addAttribute("enterpriseqq", enterpriseqq.getEnterpriseQqLinks());
                session.setAttribute("enterpriseqqE", enterpriseqq.getEnterpriseQqLinks());
            }
        }
    }
    if ("1".equals(noProduct)) {
        session.setAttribute("webnoProduct", true);
        return "ixinweb/xuanzeqiyeNoProduct";
    }
    if (null == webnoProduct || webnoProduct) {
        // 未携带产品信息
        session.setAttribute("webnoProduct", true);
        return "ixinweb/xuanzeqiyeNoProduct";
    }
    return "ixinweb/xuanzeqiye";
}
Also used : HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project appsly-android-rest by 47deg.

the class JacksonBodyConverter method toRequestBody.

@Override
public <T> HttpEntity toRequestBody(T object, String contentType) {
    Logger.d("JacksonBodyConverter.toRequestBody: object: " + object);
    try {
        String json = mapper.writeValueAsString(object);
        Logger.d("JacksonHttpFormValuesConverter.toRequestBody: json: " + json);
        StringEntity result = new StringEntity(json, "UTF-8");
        result.setContentType(contentType);
        Logger.d("JacksonBodyConverter.toRequestBody: result: " + result);
        return result;
    } catch (UnsupportedEncodingException e) {
        throw new SerializationException(e);
    } catch (JsonMappingException e) {
        throw new SerializationException(e);
    } catch (JsonGenerationException e) {
        throw new SerializationException(e);
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) SerializationException(ly.apps.android.rest.exceptions.SerializationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 24 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project spring-data-document-examples by spring-projects.

the class MappingJacksonHttpMessageConverter method writeInternal.

@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    JsonEncoding encoding = getEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
    try {
        if (this.prefixJson) {
            jsonGenerator.writeRaw("{} && ");
        }
        this.objectMapper.writeValue(jsonGenerator, o);
    } catch (JsonGenerationException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
Also used : HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) JsonEncoding(org.codehaus.jackson.JsonEncoding) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 25 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project coprhd-controller by CoprHD.

the class KHRequests method postRequest.

/*
     * Send POST request to KittyHawk server, and handle redirect/cookies
     * 
     * @param resource webResource
     * 
     * @param ParamBase parameters for post
     * 
     * @throws VNXeException
     */
public ClientResponse postRequest(ParamBase param) throws VNXeException {
    _logger.debug("post data: " + _url);
    ObjectMapper mapper = new ObjectMapper();
    String parmString = null;
    if (param != null) {
        try {
            parmString = mapper.writeValueAsString(param);
            _logger.debug("Content of the post: {}", parmString);
        } catch (JsonGenerationException e) {
            _logger.error("Post request param is not valid. ", e);
            throw VNXeException.exceptions.vnxeCommandFailed("Post request param is not valid.", e);
        } catch (JsonMappingException e) {
            _logger.error("Post request param is not valid. ", e);
            throw VNXeException.exceptions.vnxeCommandFailed("Post request param is not valid.", e);
        } catch (IOException e) {
            _logger.error("Post request param is not valid. ", e);
            throw VNXeException.exceptions.vnxeCommandFailed("Post request param is not valid.", e);
        }
    }
    ClientResponse response = buildRequest(addQueryParameters(buildResource(_resource)).getRequestBuilder()).entity(parmString).post(ClientResponse.class);
    Status statusCode = response.getClientResponseStatus();
    if (statusCode == ClientResponse.Status.CREATED || statusCode == ClientResponse.Status.ACCEPTED || statusCode == ClientResponse.Status.OK || statusCode == ClientResponse.Status.NO_CONTENT) {
        return response;
    } else if (statusCode == ClientResponse.Status.UNAUTHORIZED) {
        authenticate();
        response = buildRequest(addQueryParameters(buildResource(_resource)).getRequestBuilder()).entity(parmString).post(ClientResponse.class);
        ;
        statusCode = response.getClientResponseStatus();
        if (statusCode == ClientResponse.Status.OK || statusCode == ClientResponse.Status.ACCEPTED || statusCode == ClientResponse.Status.NO_CONTENT || statusCode == ClientResponse.Status.CREATED) {
            return response;
        }
    }
    int redirectTimes = 1;
    // handle redirect
    while (response.getClientResponseStatus() == ClientResponse.Status.FOUND && redirectTimes < VNXeConstants.REDIRECT_MAX) {
        String code = response.getClientResponseStatus().toString();
        String data = response.getEntity(String.class);
        _logger.debug("Returned code: {}, returned data {}", code, data);
        WebResource newResource = handelRedirect(response);
        if (newResource != null) {
            response = buildRequest(newResource.getRequestBuilder()).entity(parmString).post(ClientResponse.class);
            redirectTimes++;
        } else {
            // could not find the redirect url, return
            _logger.error(String.format("The post request to: %s failed with: %s %s", _url, response.getClientResponseStatus().toString(), response.getEntity(String.class)));
            throw VNXeException.exceptions.unexpectedDataError("Got redirect status code, but could not get redirected URL");
        }
    }
    if (redirectTimes >= VNXeConstants.REDIRECT_MAX) {
        _logger.error("redirected too many times for the request {}", _url);
        throw VNXeException.exceptions.unexpectedDataError("Redirected too many times while sending the request for " + _url);
    }
    checkResponse(response, POST_REQUEST);
    return response;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Status(com.sun.jersey.api.client.ClientResponse.Status) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

JsonGenerationException (org.codehaus.jackson.JsonGenerationException)34 IOException (java.io.IOException)30 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)27 Response (javax.ws.rs.core.Response)13 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 ArrayList (java.util.ArrayList)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 JsonGenerator (org.codehaus.jackson.JsonGenerator)7 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Enterprise (com.itrus.portal.db.Enterprise)4 UserCert (com.itrus.portal.db.UserCert)4 UserInfo (com.itrus.portal.db.UserInfo)4 HttpSession (javax.servlet.http.HttpSession)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 Bill (com.itrus.portal.db.Bill)3