Example usage for com.fasterxml.jackson.core JsonProcessingException printStackTrace

List of usage examples for com.fasterxml.jackson.core JsonProcessingException printStackTrace

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonProcessingException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.venice.piazza.servicecontroller.messaging.ServiceMessageWorker.java

/**
 * This method is for demonstrating ingest of raster data This will be
 * refactored once the API changes have been communicated to other team
 * members/*from w ww.ja v  a  2 s. c o  m*/
 */
public void handleRasterType(ExecuteServiceJob executeJob, Job job, Producer<String, String> producer) {
    RestTemplate restTemplate = new RestTemplate();
    ExecuteServiceData data = executeJob.data;
    // Get the id from the data
    String serviceId = data.getServiceId();
    Service sMetadata = accessor.getServiceById(serviceId);
    // Default request mimeType application/json
    String requestMimeType = "application/json";
    new LinkedMultiValueMap<String, String>();

    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(sMetadata.getUrl());
    Map<String, DataType> postObjects = new HashMap<String, DataType>();
    Iterator<Entry<String, DataType>> it = data.getDataInputs().entrySet().iterator();
    String postString = "";

    while (it.hasNext()) {
        Entry<String, DataType> entry = it.next();
        String inputName = entry.getKey();

        if (entry.getValue() instanceof URLParameterDataType) {
            String paramValue = ((TextDataType) entry.getValue()).getContent();
            if (inputName.length() == 0) {
                builder = UriComponentsBuilder.fromHttpUrl(sMetadata.getUrl() + "?" + paramValue);
            } else {
                builder.queryParam(inputName, paramValue);
            }
        } else if (entry.getValue() instanceof BodyDataType) {
            BodyDataType bdt = (BodyDataType) entry.getValue();
            postString = bdt.getContent();
            requestMimeType = bdt.getMimeType();
        }
        // Default behavior for other inputs, put them in list of objects
        // which are transformed into JSON consistent with default
        // requestMimeType
        else {
            postObjects.put(inputName, entry.getValue());
        }
    }
    if (postString.length() > 0 && postObjects.size() > 0) {
        return;
    } else if (postObjects.size() > 0) {
        ObjectMapper mapper = makeNewObjectMapper();
        try {
            postString = mapper.writeValueAsString(postObjects);
        } catch (JsonProcessingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    URI url = URI.create(builder.toUriString());
    HttpHeaders headers = new HttpHeaders();

    // Set the mimeType of the request
    MediaType mediaType = createMediaType(requestMimeType);
    headers.setContentType(mediaType);
    // Set the mimeType of the request
    // headers.add("Content-type",
    // sMetadata.getOutputs().get(0).getDataType().getMimeType());

    if (postString.length() > 0) {

        coreLogger.log("The postString is " + postString, PiazzaLogger.DEBUG);

        HttpHeaders theHeaders = new HttpHeaders();
        // headers.add("Authorization", "Basic " + credentials);
        theHeaders.setContentType(MediaType.APPLICATION_JSON);

        // Create the Request template and execute
        HttpEntity<String> request = new HttpEntity<String>(postString, theHeaders);

        try {
            coreLogger.log("About to call special service " + url, PiazzaLogger.DEBUG);

            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request,
                    String.class);
            coreLogger.log("The Response is " + response.getBody(), PiazzaLogger.DEBUG);

            String serviceControlString = response.getBody();
            coreLogger.log("Service Control String " + serviceControlString, PiazzaLogger.DEBUG);

            ObjectMapper tempMapper = makeNewObjectMapper();
            DataResource dataResource = tempMapper.readValue(serviceControlString, DataResource.class);
            coreLogger.log("dataResource type is " + dataResource.getDataType().getClass().getSimpleName(),
                    PiazzaLogger.DEBUG);

            dataResource.dataId = uuidFactory.getUUID();
            coreLogger.log("dataId " + dataResource.dataId, PiazzaLogger.DEBUG);

            PiazzaJobRequest pjr = new PiazzaJobRequest();
            pjr.createdBy = "pz-sc-ingest-raster-test";

            IngestJob ingestJob = new IngestJob();
            ingestJob.data = dataResource;
            ingestJob.host = true;
            pjr.jobType = ingestJob;

            ProducerRecord<String, String> newProdRecord = JobMessageFactory.getRequestJobMessage(pjr,
                    uuidFactory.getUUID(), SPACE);
            producer.send(newProdRecord);

            coreLogger.log("newProdRecord sent " + newProdRecord.toString(), PiazzaLogger.DEBUG);

            StatusUpdate statusUpdate = new StatusUpdate(StatusUpdate.STATUS_SUCCESS);

            // Create a text result and update status
            DataResult textResult = new DataResult(dataResource.dataId);
            statusUpdate.setResult(textResult);
            ProducerRecord<String, String> prodRecord = JobMessageFactory.getUpdateStatusMessage(job.getJobId(),
                    statusUpdate, SPACE);

            producer.send(prodRecord);
            coreLogger.log("prodRecord sent " + prodRecord.toString(), PiazzaLogger.DEBUG);

        } catch (JsonProcessingException jpe) {
            jpe.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

From source file:org.croudtrip.gcm.GcmIntentService.java

private void handleRequestAccepted(Intent intent) {
    Timber.d("REQUEST_ACCEPTED");

    // extract join request and offer from message
    final long joinTripRequestId = Long
            .parseLong(intent.getExtras().getString(GcmConstants.GCM_MSG_JOIN_REQUEST_ID));
    long offerId = Long.parseLong(intent.getExtras().getString(GcmConstants.GCM_MSG_JOIN_REQUEST_OFFER_ID));

    // download the join trip request
    tripsResource.getJoinRequest(joinTripRequestId).observeOn(Schedulers.io())
            .subscribeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<JoinTripRequest>() {
                @Override/*from  w  w  w  . j  ava2 s.co m*/
                public void call(JoinTripRequest joinTripRequest) {

                    //Check the two starting positions. If they are the same, this was the declined message from the first driver
                    RouteLocation r1 = joinTripRequest.getSuperTrip().getQuery().getStartLocation();
                    RouteLocation r2 = joinTripRequest.getSubQuery().getStartLocation();
                    boolean firstDriver = r1.equals(r2);

                    //save the accepted status only if the first driver accepted
                    if (firstDriver) {
                        final SharedPreferences prefs = getApplicationContext().getSharedPreferences(
                                Constants.SHARED_PREF_FILE_PREFERENCES, Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.putBoolean(Constants.SHARED_PREF_KEY_ACCEPTED, true);
                        editor.putBoolean(Constants.SHARED_PREF_KEY_WAITING, false);
                        editor.putBoolean(Constants.SHARED_PREF_KEY_SEARCHING, false);
                        editor.putLong(Constants.SHARED_PREF_KEY_TRIP_ID, joinTripRequest.getId());
                        editor.apply();
                    }

                    Bundle extras = new Bundle();
                    ObjectMapper mapper = new ObjectMapper();
                    try {
                        extras.putString(JoinDispatchFragment.KEY_JOIN_TRIP_REQUEST_RESULT,
                                mapper.writeValueAsString(joinTripRequest));
                    } catch (JsonProcessingException e) {
                        Timber.e("Could not map join trip result");
                        e.printStackTrace();
                    }

                    if (LifecycleHandler.isApplicationInForeground()) {
                        if (firstDriver) {
                            Intent startingIntent = new Intent(Constants.EVENT_CHANGE_JOIN_UI);
                            startingIntent.putExtras(extras);
                            LocalBroadcastManager.getInstance(getApplicationContext())
                                    .sendBroadcast(startingIntent);
                        } else {
                            Intent startingIntent = new Intent(Constants.EVENT_SECONDARY_DRIVER_ACCEPTED);
                            startingIntent.putExtras(extras);
                            LocalBroadcastManager.getInstance(getApplicationContext())
                                    .sendBroadcast(startingIntent);
                        }
                    } else {
                        // create notification for the user only if the first driver accepts
                        Intent startingIntent = new Intent(getApplicationContext(), MainActivity.class);
                        startingIntent.putExtras(extras);
                        PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                                startingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                        createNotification(getString(R.string.join_request_accepted_title),
                                getString(R.string.join_request_accepted_msg,
                                        joinTripRequest.getOffer().getDriver().getFirstName()),
                                GcmConstants.GCM_NOTIFICATION_REQUEST_ACCEPTED_ID, contentIntent);
                    }
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    Timber.e("Something went wrong when downloading join request: " + throwable.getMessage());
                }
            });
}

From source file:org.opendatakit.aggregate.odktables.impl.api.TableServiceImpl.java

@Override
public Response putJsonTableProperties(ArrayList<Map<String, Object>> propertiesList)
        throws ODKDatastoreException, PermissionDeniedException, ODKTaskLockException, TableNotFoundException {
    ArrayList<PropertyEntryXml> properties = new ArrayList<PropertyEntryXml>();
    for (Map<String, Object> tpe : propertiesList) {
        // bogus type and value...
        String partition = (String) tpe.get("partition");
        String aspect = (String) tpe.get("aspect");
        String key = (String) tpe.get("key");
        String type = (String) tpe.get("type");
        PropertyEntryXml e = new PropertyEntryXml(partition, aspect, key, type, null);

        // and figure out the correct type and value...
        Object value = tpe.get("value");
        if (value == null) {
            e.setValue(null);//w ww  .j a v  a 2 s .c o m
        } else if (value instanceof Boolean) {
            e.setValue(Boolean.toString((Boolean) value));
        } else if (value instanceof Integer) {
            e.setValue(Integer.toString((Integer) value));
        } else if (value instanceof Float) {
            e.setValue(Float.toString((Float) value));
        } else if (value instanceof Double) {
            e.setValue(Double.toString((Double) value));
        } else if (value instanceof List) {
            try {
                e.setValue(mapper.writeValueAsString(value));
            } catch (JsonProcessingException ex) {
                ex.printStackTrace();
                e.setValue("[]");
            }
        } else {
            try {
                e.setValue(mapper.writeValueAsString(value));
            } catch (JsonProcessingException ex) {
                ex.printStackTrace();
                e.setValue("{}");
            }
        }

        properties.add(e);
    }
    PropertyEntryXmlList pl = new PropertyEntryXmlList(properties);
    return putInternalTableProperties(pl);
}

From source file:ch.icclab.cyclops.resource.impl.GenerateResource.java

/**
 * Saves a TSDB dataObj into the database
 * <p>/*from w  ww  . j  a  va 2 s .  c  om*/
 * Pseudo Code
 * 1. Create a TSDB client object (POJO object)
 * 2. Convert the data object into a json string
 * 3. Save the string into the database
 *
 * @param rateObj A TSDBData object containing the content to be saved into the db
 * @return boolean
 */
private boolean saveRate(TSDBData rateObj) {
    InfluxDBClient dbClient = new InfluxDBClient();

    ObjectMapper mapper = new ObjectMapper();
    String jsonData = null;
    boolean result;
    try {
        jsonData = mapper.writeValueAsString(rateObj);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    result = dbClient.saveData(jsonData);
    return result;
}

From source file:org.opencb.opencga.storage.mongodb.variant.converters.DocumentToVariantAnnotationConverter.java

private <T> List<Document> generateClinicalDBList(List<T> objectList) {
    if (objectList != null) {
        List<Document> list = new ArrayList<>(objectList.size());
        for (T object : objectList) {
            try {
                if (object instanceof GenericRecord) {
                    list.add(Document.parse(object.toString()));
                } else {
                    list.add(Document.parse(writer.writeValueAsString(object)));
                }//from  ww w .j  a  v a 2s. com
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                logger.error("Error serializing Clinical Data " + object.getClass(), e);
            }
        }
        return list;
    }
    return null;
}

From source file:ch.icclab.cyclops.resource.impl.GenerateResource.java

/**
 * Save the price generated into the DB/*from w w  w .ja va 2  s  .  co  m*/
 * <p>
 * Pseudo Code
 * 1. Create the dataobj containing the details
 * 2. Save it into the db
 *
 * @param objArr Response from the DB for containing the list of rates
 * @return boolean
 */
private boolean savePrice(ArrayList<ArrayList<Object>> objArr) {
    //TODO: create string array construction method with String... array
    //TODO: create generic method to create POJO object from objArr and map to JSON data
    logger.trace("BEGIN boolean savePrice(ArrayList<ArrayList<Object>> objArr)");
    boolean result = false;
    TSDBData pricingData = new TSDBData();
    ArrayList<String> strArr = new ArrayList<String>();
    InfluxDBClient dbClient = new InfluxDBClient();
    ObjectMapper mapper = new ObjectMapper();
    String jsonData = null;

    strArr.add("resource");
    strArr.add("userid");
    strArr.add("usage");
    strArr.add("price");
    pricingData.setName("cdr3");//changed to cdr3 from cdr to avoid influxdb client problems till db is dumped
    pricingData.setColumns(strArr);
    pricingData.setPoints(objArr);
    //get tags and put them into pricingData
    logger.trace("DATA boolean savePrice(ArrayList<ArrayList<Object>> objArr): pricingData=" + pricingData);

    try {
        jsonData = mapper.writeValueAsString(pricingData);
    } catch (JsonProcessingException e) {
        logger.error(
                "EXCEPTION JSONPROCESSINGEXCEPTION boolean savePrice(ArrayList<ArrayList<Object>> objArr)");
        e.printStackTrace();
    }

    //System.out.println(jsonData);
    logger.trace("DATA boolean savePrice(ArrayList<ArrayList<Object>> objArr): jsonData=" + jsonData);
    result = dbClient.saveData(jsonData);
    logger.trace("END boolean savePrice(ArrayList<ArrayList<Object>> objArr)");
    return result;
}

From source file:org.opendatakit.api.odktables.TableService.java

/**
 * Replace the properties.csv with the supplied propertiesList.
 * This does not preserve the existing properties in the properties.csv,
 * but does a wholesale, atomic, replacement of those properties.
 * /*from  www  .  jav a 2 s.com*/
 * This is the JSON variant of this API. See putXmlTableProperties, above.
 * 
 * @param odkClientVersion
 * @param propertiesList
 * @return
 * @throws ODKDatastoreException
 * @throws PermissionDeniedException
 * @throws ODKTaskLockException
 * @throws TableNotFoundException
 */
@PUT
@Path("properties/{odkClientVersion}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON, ApiConstants.MEDIA_TEXT_XML_UTF8,
        ApiConstants.MEDIA_APPLICATION_XML_UTF8 })
public Response putJsonTableProperties(@PathParam("odkClientVersion") String odkClientVersion,
        ArrayList<Map<String, Object>> propertiesList)
        throws ODKDatastoreException, PermissionDeniedException, ODKTaskLockException, TableNotFoundException {
    ArrayList<PropertyEntryXml> properties = new ArrayList<PropertyEntryXml>();
    for (Map<String, Object> tpe : propertiesList) {
        // bogus type and value...
        String partition = (String) tpe.get("partition");
        String aspect = (String) tpe.get("aspect");
        String key = (String) tpe.get("key");
        String type = (String) tpe.get("type");
        PropertyEntryXml e = new PropertyEntryXml(partition, aspect, key, type, null);

        // and figure out the correct type and value...
        Object value = tpe.get("value");
        if (value == null) {
            e.setValue(null);
        } else if (value instanceof Boolean) {
            e.setValue(Boolean.toString((Boolean) value));
        } else if (value instanceof Integer) {
            e.setValue(Integer.toString((Integer) value));
        } else if (value instanceof Float) {
            e.setValue(Float.toString((Float) value));
        } else if (value instanceof Double) {
            e.setValue(Double.toString((Double) value));
        } else if (value instanceof List) {
            try {
                e.setValue(mapper.writeValueAsString(value));
            } catch (JsonProcessingException ex) {
                ex.printStackTrace();
                e.setValue("[]");
            }
        } else {
            try {
                e.setValue(mapper.writeValueAsString(value));
            } catch (JsonProcessingException ex) {
                ex.printStackTrace();
                e.setValue("{}");
            }
        }

        properties.add(e);
    }
    PropertyEntryXmlList pl = new PropertyEntryXmlList(properties);
    return putInternalTableProperties(odkClientVersion, pl);
}

From source file:i5.las2peer.services.gamificationActionService.GamificationActionService.java

/**
 * Function to be accessed via RMI to get list of action
 * @param appId applicationId/*from  w ww.ja v a 2s.c o m*/
 * @return serialized JSON notification data caused by triggered action
 */
public String getActionsRMI(String appId) {
    List<ActionModel> achs = null;
    Connection conn = null;

    try {
        conn = dbm.getConnection();
        JSONArray arr = new JSONArray();

        int offset = 0;
        int totalNum = actionAccess.getNumberOfActions(conn, appId);
        int windowSize = totalNum;

        achs = actionAccess.getActionsWithOffsetAndSearchPhrase(conn, appId, offset, windowSize, "");

        ObjectMapper objectMapper = new ObjectMapper();
        //Set pretty printing of json
        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);

        String actionString;
        try {
            actionString = objectMapper.writeValueAsString(achs);
            return actionString;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return null;
        }
    } catch (SQLException e1) {
        e1.printStackTrace();
        return null;
    }
    // always close connections
    finally {
        try {
            conn.close();
        } catch (SQLException e) {
            logger.printStackTrace(e);
        }
    }

}

From source file:org.opendatakit.common.android.utilities.TableUtil.java

/**
 * Set the group-by columns.//from  ww  w .  j a va  2s . c o  m
 *
 * @param ctxt
 * @param appName
 * @param db
 * @param tableId
 * @param elementKeys
 * @throws RemoteException 
 */
public void setGroupByColumns(CommonApplication ctxt, String appName, OdkDbHandle db, String tableId,
        ArrayList<String> elementKeys) throws RemoteException {
    String list = null;
    try {
        list = ODKFileUtils.mapper.writeValueAsString(elementKeys);
    } catch (JsonProcessingException e1) {
        e1.printStackTrace();
        throw new IllegalArgumentException("Unexpected groupByCols conversion failure!");
    }
    KeyValueStoreEntry e = KeyValueStoreUtils.buildEntry(tableId, KeyValueStoreConstants.PARTITION_TABLE,
            KeyValueStoreConstants.ASPECT_DEFAULT, KeyValueStoreConstants.TABLE_GROUP_BY_COLS,
            ElementDataType.array, list);
    ctxt.getDatabase().replaceDBTableMetadata(appName, db, e);
}

From source file:org.opendatakit.common.android.utilities.TableUtil.java

/**
 * Set the order of display of the columns in the spreadsheet view.
 *
 * @param ctxt/*from w  w  w. ja v a  2s.co  m*/
 * @param appName
 * @param db
 * @param tableId
 * @param elementKeys
 * @throws RemoteException 
 */
public void setColumnOrder(CommonApplication ctxt, String appName, OdkDbHandle db, String tableId,
        ArrayList<String> elementKeys) throws RemoteException {
    String list = null;
    try {
        list = ODKFileUtils.mapper.writeValueAsString(elementKeys);
    } catch (JsonProcessingException e1) {
        e1.printStackTrace();
        throw new IllegalArgumentException("Unexpected columnOrder conversion failure!");
    }
    KeyValueStoreEntry e = KeyValueStoreUtils.buildEntry(tableId, KeyValueStoreConstants.PARTITION_TABLE,
            KeyValueStoreConstants.ASPECT_DEFAULT, KeyValueStoreConstants.TABLE_COL_ORDER,
            ElementDataType.array, list);
    ctxt.getDatabase().replaceDBTableMetadata(appName, db, e);
}