Search in sources :

Example 1 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project hadoop by apache.

the class DomainLogInfo method parseForStore.

public long parseForStore(TimelineDataManager tdm, Path appDirPath, boolean appCompleted, JsonFactory jsonFactory, ObjectMapper objMapper, FileSystem fs) throws IOException {
    LOG.debug("Parsing for log dir {} on attempt {}", appDirPath, attemptDirName);
    Path logPath = getPath(appDirPath);
    FileStatus status = fs.getFileStatus(logPath);
    long numParsed = 0;
    if (status != null) {
        long startTime = Time.monotonicNow();
        try {
            LOG.debug("Parsing {} at offset {}", logPath, offset);
            long count = parsePath(tdm, logPath, appCompleted, jsonFactory, objMapper, fs);
            LOG.info("Parsed {} entities from {} in {} msec", count, logPath, Time.monotonicNow() - startTime);
            numParsed += count;
        } catch (RuntimeException e) {
            // If AppLogs cannot parse this log, it may be corrupted or just empty
            if (e.getCause() instanceof JsonParseException && (status.getLen() > 0 || offset > 0)) {
                // log on parse problems if the file as been read in the past or
                // is visibly non-empty
                LOG.info("Log {} appears to be corrupted. Skip. ", logPath);
            }
        }
    } else {
        LOG.warn("{} no longer exists. Skip for scanning. ", logPath);
    }
    return numParsed;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 2 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project hadoop by apache.

the class RemoteSASKeyGenerationResponse method makeRemoteRequest.

/**
   * Helper method to make a remote request.
   * @param uri - Uri to use for the remote request
   * @return RemoteSASKeyGenerationResponse
   */
private RemoteSASKeyGenerationResponse makeRemoteRequest(URI uri) throws SASKeyGenerationException {
    try {
        String responseBody = remoteCallHelper.makeRemoteGetRequest(new HttpGet(uri));
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.readValue(responseBody, RemoteSASKeyGenerationResponse.class);
    } catch (WasbRemoteCallException remoteCallEx) {
        throw new SASKeyGenerationException("Encountered RemoteCallException" + " while retrieving SAS key from remote service", remoteCallEx);
    } catch (JsonParseException jsonParserEx) {
        throw new SASKeyGenerationException("Encountered JsonParseException " + "while parsing the response from remote" + " service into RemoteSASKeyGenerationResponse object", jsonParserEx);
    } catch (JsonMappingException jsonMappingEx) {
        throw new SASKeyGenerationException("Encountered JsonMappingException" + " while mapping the response from remote service into " + "RemoteSASKeyGenerationResponse object", jsonMappingEx);
    } catch (IOException ioEx) {
        throw new SASKeyGenerationException("Encountered IOException while " + "accessing remote service to retrieve SAS Key", ioEx);
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project midpoint by Evolveum.

the class ItemPathDeserializer method deserialize.

@Override
public ItemPath deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    // TODO : implement..this is only for test
    if (jp.getCurrentToken() != JsonToken.VALUE_STRING) {
        throw new JsonParseException("Cannot parse path value. Expected that the value will be string but it is: " + jp.getCurrentTokenId(), jp.getCurrentLocation());
    }
    String path = jp.getText();
    if (StringUtils.isBlank(path)) {
        throw new IllegalStateException("Error while deserializing path. No path specified.");
    }
    //System.out.println("path: " + path);
    //		if (path.startsWith("declare.*")){
    XPathHolder holder = new XPathHolder(path);
    return holder.toItemPath();
//		}
//		else {
//			String[] segments = path.split("/");
//			if (segments.length == 1){
//				String[] pathItems = segments[0].split(":");
//				if (pathItems.length == 1){
//					return new ItemPath(QNameUtil.nullNamespace(pathItems[0]));
//				}
//				
//			} else
//		}
//		return new ItemPath(new QName("http://midpoint.evolveum.com/xml/ns/test/foo-1.xsd", "name"));
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 4 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project midpoint by Evolveum.

the class ItemPathTypeDeserializer method deserialize.

@Override
public ItemPathType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    if (jp.getCurrentToken() != JsonToken.VALUE_STRING) {
        throw new JsonParseException("Cannot parse path value. Expected that the value will be string but it is: " + jp.getCurrentTokenId(), jp.getCurrentLocation());
    }
    String path = jp.getText();
    if (StringUtils.isBlank(path)) {
        throw new IllegalStateException("Error while deserializing path. No path specified.");
    }
    //System.out.println("path: " + path);
    //		if (path.startsWith("declare.*")){
    XPathHolder holder = new XPathHolder(path);
    ItemPath itemPath = holder.toItemPath();
    ItemPathType itemPathType = new ItemPathType(itemPath);
    return itemPathType;
//		ItemPathType itemPathType = new ItemPathType();
//		itemPathType.getContent().add(jp.getText());
//		
//		return itemPathType;
}
Also used : XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with JsonParseException

use of com.fasterxml.jackson.core.JsonParseException in project OpenClinica by OpenClinica.

the class XformMetaDataService method executeIndividualCrf.

public void executeIndividualCrf(ExecuteIndividualCrfObject eicObject) {
    for (OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef : eicObject.formLayoutDefs) {
        List<String> fileLinks = null;
        String vForm = "";
        RestTemplate rest = new RestTemplate();
        if (eicObject.form != null) {
            List<FormVersion> versions = eicObject.form.getVersions();
            for (FormVersion version : versions) {
                if (version.getName().equals(formLayoutDef.getOID())) {
                    fileLinks = version.getFileLinks();
                    for (String fileLink : fileLinks) {
                        if (fileLink.endsWith(VERSION)) {
                            vForm = rest.getForObject(fileLink, String.class);
                            break;
                        }
                    }
                    if (!eicObject.errors.hasErrors()) {
                        ObjectMapper mapper = new ObjectMapper();
                        TypeReference<List<XformGroup>> mapType = new TypeReference<List<XformGroup>>() {
                        };
                        List<XformGroup> jsonList = null;
                        try {
                            jsonList = mapper.readValue(vForm, mapType);
                        } catch (JsonParseException 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();
                        }
                        XformContainer xformContainer = new XformContainer();
                        xformContainer.setGroups(jsonList);
                        eicObject.setContainer(xformContainer);
                        if (eicObject.errors.hasErrors()) {
                            return;
                        }
                        // Save meta-data in database
                        saveFormMetadata(eicObject, version, eicObject.container, formLayoutDef, fileLinks);
                    }
                }
            }
        }
    }
}
Also used : OCodmComplexTypeDefinitionFormLayoutDef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutDef) XformGroup(org.akaza.openclinica.domain.xform.XformGroup) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) XformContainer(org.akaza.openclinica.domain.xform.XformContainer) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) FormVersion(org.akaza.openclinica.service.dto.FormVersion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)135 IOException (java.io.IOException)69 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)58 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)37 JsonParser (com.fasterxml.jackson.core.JsonParser)23 Map (java.util.Map)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)17 InputStream (java.io.InputStream)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 JsonToken (com.fasterxml.jackson.core.JsonToken)12 HashMap (java.util.HashMap)12 File (java.io.File)11 JsonFactory (com.fasterxml.jackson.core.JsonFactory)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4