Search in sources :

Example 31 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project voldemort by voldemort.

the class R2Store method parseGetAllResults.

private Map<ByteArray, List<Versioned<byte[]>>> parseGetAllResults(ByteString entity) {
    Map<ByteArray, List<Versioned<byte[]>>> results = new HashMap<ByteArray, List<Versioned<byte[]>>>();
    try {
        // Build the multipart object
        byte[] bytes = new byte[entity.length()];
        entity.copyBytes(bytes, 0);
        // Get the outer multipart object
        ByteArrayDataSource ds = new ByteArrayDataSource(bytes, "multipart/mixed");
        MimeMultipart mp = new MimeMultipart(ds);
        for (int i = 0; i < mp.getCount(); i++) {
            // Get an individual part. This contains all the versioned
            // values for a particular key referenced by content-location
            MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);
            // Get the key
            String contentLocation = part.getHeader("Content-Location")[0];
            String base64Key = contentLocation.split("/")[2];
            ByteArray key = new ByteArray(RestUtils.decodeVoldemortKey(base64Key));
            if (logger.isDebugEnabled()) {
                logger.debug("Content-Location : " + contentLocation);
                logger.debug("Base 64 key : " + base64Key);
            }
            // Create an array list for holding all the (versioned values)
            List<Versioned<byte[]>> valueResultList = new ArrayList<Versioned<byte[]>>();
            /*
                 * Get the nested Multi-part object. This contains one part for each unique versioned value.
                 *
                 * GetContent method can corrupt the embedded data, for example 0x8c be converted to 0xc2, 0x8c,
                 * hence use getInputStream.
                 *
                 * This thread tracks this question
                 * http://stackoverflow.com/questions/23023583/mimebodypart-getcontent-corrupts-binary-data
                 *
                 * getInputStream() : Return a decoded input stream for this Message's "content.
                 *
                 * getRawInputStream() : Return an InputStream to the raw data with any Content-Transfer-Encoding
                 * intact. This method is useful if the "Content-Transfer-Encoding" header is incorrect or corrupt,
                 * which would prevent the getInputStream method from returning the correct data. In such a case
                 * the application may use this method and attempt to decode the raw data itself.
                 *
                 */
            ByteArrayDataSource nestedDS = new ByteArrayDataSource(part.getInputStream(), "multipart/mixed");
            MimeMultipart valueParts = new MimeMultipart(nestedDS);
            for (int valueId = 0; valueId < valueParts.getCount(); valueId++) {
                MimeBodyPart valuePart = (MimeBodyPart) valueParts.getBodyPart(valueId);
                String serializedVC = valuePart.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
                int contentLength = Integer.parseInt(valuePart.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
                if (logger.isDebugEnabled()) {
                    logger.debug("Received serialized Vector Clock : " + serializedVC);
                }
                VectorClockWrapper vcWrapper = mapper.readValue(serializedVC, VectorClockWrapper.class);
                // get the value bytes
                InputStream input = valuePart.getInputStream();
                byte[] bodyPartBytes = new byte[contentLength];
                input.read(bodyPartBytes);
                VectorClock clock = new VectorClock(vcWrapper.getVersions(), vcWrapper.getTimestamp());
                valueResultList.add(new Versioned<byte[]>(bodyPartBytes, clock));
            }
            results.put(key, valueResultList);
        }
    } catch (MessagingException e) {
        throw new VoldemortException("Messaging exception while trying to parse GET response " + e.getMessage(), e);
    } catch (JsonParseException e) {
        throw new VoldemortException("JSON parsing exception while trying to parse GET response " + e.getMessage(), e);
    } catch (JsonMappingException e) {
        throw new VoldemortException("JSON mapping exception while trying to parse GET response " + e.getMessage(), e);
    } catch (IOException e) {
        throw new VoldemortException("IO exception while trying to parse GET response " + e.getMessage(), e);
    }
    return results;
}
Also used : Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) MessagingException(javax.mail.MessagingException) InputStream(java.io.InputStream) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) ByteString(com.linkedin.data.ByteString) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) VoldemortException(voldemort.VoldemortException) MimeMultipart(javax.mail.internet.MimeMultipart) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ByteArray(voldemort.utils.ByteArray) List(java.util.List) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) VectorClockWrapper(voldemort.rest.VectorClockWrapper)

Example 32 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project head by mifos.

the class CenterRESTController method createCenter.

@RequestMapping(value = "/center/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createCenter(@RequestBody String request) throws Throwable {
    ObjectMapper om = createCenterMaping();
    CreateCenterDetailsDto creationDetail = null;
    MeetingBO meetingBO = null;
    try {
        creationDetail = om.readValue(request, CreateCenterDetailsDto.class);
    } catch (JsonMappingException e) {
        throw e.getCause();
    }
    validate(creationDetail);
    meetingBO = (MeetingBO) creationDetail.getMeeting().toBO();
    CenterCreationDetail center = createCenter(creationDetail);
    CustomerDetailsDto details = this.centerServiceFacade.createNewCenter(center, meetingBO.toDto());
    CenterInformationDto centerInfo = this.centerServiceFacade.getCenterInformationDto(details.getGlobalCustNum());
    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("globalCustNum", centerInfo.getCenterDisplay().getGlobalCustNum());
    map.put("accountNum", centerInfo.getCustomerAccountSummary().getGlobalAccountNum());
    map.put("name", center.getDisplayName());
    map.put("externalId", center.getExternalId());
    map.put("mfiDate", center.getMfiJoiningDate().toString());
    map.put("address", center.getAddressDto().getDisplayAddress());
    map.put("city", center.getAddressDto().getCity());
    map.put("state", center.getAddressDto().getState());
    map.put("country", center.getAddressDto().getCountry());
    map.put("postal code", center.getAddressDto().getZip());
    map.put("phone", center.getAddressDto().getPhoneNumber());
    return map;
}
Also used : CenterCreationDetail(org.mifos.dto.domain.CenterCreationDetail) HashMap(java.util.HashMap) MeetingBO(org.mifos.application.meeting.business.MeetingBO) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) CreateCenterDetailsDto(org.mifos.application.servicefacade.CreateCenterDetailsDto) CenterInformationDto(org.mifos.dto.domain.CenterInformationDto) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 33 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project head by mifos.

the class ClientRESTController method createClient.

@RequestMapping(value = "client/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createClient(@RequestBody String request) throws Throwable {
    ObjectMapper om = createClientMapping();
    CreateClientCreationDetail creationDetail = null;
    MeetingBO meetingBO = null;
    try {
        creationDetail = om.readValue(request, CreateClientCreationDetail.class);
    } catch (JsonMappingException e) {
        e.getCause();
    }
    validate(creationDetail);
    meetingBO = (MeetingBO) creationDetail.getMeeting().toBO();
    ClientCreationDetail client = createClient(creationDetail);
    CustomerDetailsDto clientDetails = clientServiceFacade.createNewClient(client, meetingBO.toDto(), null);
    ClientInformationDto clientInfo = clientServiceFacade.getClientInformationDto(clientDetails.getGlobalCustNum());
    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("globalCustNum", clientInfo.getClientDisplay().getGlobalCustNum());
    map.put("accountNum", clientInfo.getCustomerAccountSummary().getGlobalAccountNum());
    map.put("address", clientInfo.getAddress().getDisplayAddress());
    map.put("city", clientInfo.getAddress().getCity());
    map.put("state", clientInfo.getAddress().getState());
    map.put("country", clientInfo.getAddress().getCountry());
    map.put("postal code", clientInfo.getAddress().getZip());
    map.put("phone", clientInfo.getAddress().getPhoneNumber());
    map.put("dispalyName", clientInfo.getClientDisplay().getDisplayName());
    map.put("externalId", clientInfo.getClientDisplay().getExternalId());
    map.put("loanOfficer", clientInfo.getClientDisplay().getLoanOfficerName());
    return map;
}
Also used : CreateClientCreationDetail(org.mifos.application.servicefacade.CreateClientCreationDetail) CreateClientCreationDetail(org.mifos.application.servicefacade.CreateClientCreationDetail) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) HashMap(java.util.HashMap) MeetingBO(org.mifos.application.meeting.business.MeetingBO) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) ClientInformationDto(org.mifos.dto.screen.ClientInformationDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 34 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project spring-security-oauth by spring-projects.

the class OAuth2AccessTokenJackson1SerializerTests method writeValueAsStringWithNullScope.

@Test
public void writeValueAsStringWithNullScope() throws JsonGenerationException, JsonMappingException, IOException {
    thrown.expect(JsonMappingException.class);
    thrown.expectMessage("Scopes cannot be null or empty. Got [null]");
    accessToken.getScope().clear();
    try {
        accessToken.getScope().add(null);
    } catch (NullPointerException e) {
        // short circuit NPE from Java 7 (which is correct but only relevant for this test)
        throw new JsonMappingException("Scopes cannot be null or empty. Got [null]");
    }
    mapper.writeValueAsString(accessToken);
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project OpenAttestation by OpenAttestation.

the class DemoPortalDataController method saveNewHostInfo.

public ModelAndView saveNewHostInfo(HttpServletRequest req, HttpServletResponse res) {
    log.info("WLMDataController.saveNewHostInfo >>");
    ModelAndView responseView = new ModelAndView(new JSONView());
    String hostObject = null;
    boolean newhost = false;
    try {
        hostObject = req.getParameter("hostObject");
        newhost = Boolean.parseBoolean(req.getParameter("newhost"));
    } catch (Exception e1) {
        responseView.addObject("result", false);
        responseView.addObject("message", e1.getMessage());
    }
    System.out.println(hostObject);
    ObjectMapper mapper = new ObjectMapper();
    HostDetailsEntityVO dataVO = new HostDetailsEntityVO();
    try {
        dataVO = mapper.readValue(hostObject, HostDetailsEntityVO.class);
    } catch (JsonParseException e) {
        log.error("Error While Parsing request parameters Data. " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", "Error While Parsing request parameters Data.");
        return responseView;
    } catch (JsonMappingException e) {
        log.error("Error While Mapping request parameters to Mle Data Object. " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
        return responseView;
    } catch (IOException e) {
        log.error("IO Exception " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
        return responseView;
    }
    dataVO.setUpdatedOn(new Date(System.currentTimeMillis()));
    try {
        if (newhost) {
            System.err.println("dataForNew : " + dataVO);
            responseView.addObject("result", demoPortalServices.saveNewHostData(dataVO, getAttestationService(req, AttestationService.class)));
        } else {
            System.err.println("dataForOLD : " + dataVO);
            responseView.addObject("result", demoPortalServices.updateHostData(dataVO, getAttestationService(req, AttestationService.class)));
        }
    } catch (DemoPortalException e) {
        log.error(e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", e.getMessage());
        return responseView;
    }
    log.info("WLMDataController.saveNewHostInfo <<<");
    return responseView;
}
Also used : JSONView(com.intel.mountwilson.util.JSONView) HostDetailsEntityVO(com.intel.mountwilson.datamodel.HostDetailsEntityVO) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Date(java.util.Date)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)42 IOException (java.io.IOException)34 JsonParseException (org.codehaus.jackson.JsonParseException)33 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)15 TypeReference (org.codehaus.jackson.type.TypeReference)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 Map (java.util.Map)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 BlogsMoreResponse (cn.eoe.app.entity.BlogsMoreResponse)2 NewsMoreResponse (cn.eoe.app.entity.NewsMoreResponse)2 WikiMoreResponse (cn.eoe.app.entity.WikiMoreResponse)2 ByteString (com.linkedin.data.ByteString)2 PhysicalSourceConfig (com.linkedin.databus2.relay.config.PhysicalSourceConfig)2 InputStream (java.io.InputStream)2