Example usage for org.apache.commons.lang3.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang3.builder ToStringBuilder reflectionToString

Introduction

In this page you can find the example usage for org.apache.commons.lang3.builder ToStringBuilder reflectionToString.

Prototype

public static String reflectionToString(final Object object, final ToStringStyle style) 

Source Link

Document

Uses ReflectionToStringBuilder to generate a toString for the specified object.

Usage

From source file:com.vaporwarecorp.mirror.feature.alexa.AlexaCommandManagerImpl.java

private void checkQueue() {
    //if we're out of things, hang up the phone and move on
    if (mAvsQueue.size() == 0) {
        removeVoiceView();// ww w .java2s  .c o m
        mEventManager.post(new SpeechEvent(""));
        return;
    }

    AvsItem current = mAvsQueue.removeFirst();
    Timber.d("Got %s", ToStringBuilder.reflectionToString(current, ToStringStyle.MULTI_LINE_STYLE));
    if (current instanceof AvsPlayRemoteItem) {
        removeVoiceView();
        //play a URL
        if (!mAudioPlayer.isPlaying()) {
            mAudioPlayer.playItem((AvsPlayRemoteItem) current);
        }
    } else if (current instanceof AvsPlayContentItem) {
        removeVoiceView();
        //play a URL
        if (!mAudioPlayer.isPlaying()) {
            mAudioPlayer.playItem((AvsPlayContentItem) current);
        }
    } else if (current instanceof AvsSpeakItem) {
        //play a sound file
        if (!mAudioPlayer.isPlaying()) {
            mAudioPlayer.playItem((AvsSpeakItem) current);
        }
    } else if (current instanceof AvsStopItem) {
        removeVoiceView();
        //stop our play
        mAudioPlayer.stop();
        mAvsQueue.remove(current);
    } else if (current instanceof AvsReplaceAllItem) {
        removeVoiceView();
        mAudioPlayer.stop();
        mAvsQueue.remove(current);
    } else if (current instanceof AvsReplaceEnqueuedItem) {
        removeVoiceView();
        mAvsQueue.remove(current);
    } else if (current instanceof AvsExpectSpeechItem) {
        //listen for user input
        mAudioPlayer.stop();
        voiceSearch();
    } else {
        removeVoiceView();
        mAudioPlayer.stop();
    }
}

From source file:gobblin.writer.http.SalesforceRestWriter.java

private HttpUriRequest newRequest(RequestBuilder builder, JsonElement payload) {
    try {//  w  ww .j a v a 2s  . co m
        builder.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType())
                .addHeader(HttpHeaders.AUTHORIZATION, "OAuth " + accessToken)
                .setEntity(new StringEntity(payload.toString(), ContentType.APPLICATION_JSON));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (getLog().isDebugEnabled()) {
        getLog().debug("Request builder: "
                + ToStringBuilder.reflectionToString(builder, ToStringStyle.SHORT_PREFIX_STYLE));
    }
    return builder.build();
}

From source file:eu.openanalytics.rsb.Util.java

/**
 * Marshals an {@link ErrorResult} to XML.
 * /*from w  w  w.ja v  a  2  s  . c o m*/
 * @param errorResult
 * @return
 */
public static String toXml(final ErrorResult errorResult) {
    try {
        final Marshaller marshaller = ERROR_RESULT_JAXB_CONTEXT.createMarshaller();
        final StringWriter sw = new StringWriter();
        marshaller.marshal(errorResult, sw);
        return sw.toString();
    } catch (final JAXBException je) {
        final String objectAsString = ToStringBuilder.reflectionToString(errorResult,
                ToStringStyle.SHORT_PREFIX_STYLE);
        throw new RuntimeException("Failed to XML marshall: " + objectAsString, je);
    }
}

From source file:eu.openanalytics.rsb.Util.java

/**
 * Marshals an {@link Object} to a JSON string.
 * //from  w  w  w  .  j ava  2  s  .c  om
 * @param o
 * @return
 */
public static String toJson(final Object o) {
    try {
        return PRETTY_JSON_OBJECT_MAPPER.writeValueAsString(o);
    } catch (final IOException ioe) {
        final String objectAsString = ToStringBuilder.reflectionToString(o, ToStringStyle.SHORT_PREFIX_STYLE);
        throw new RuntimeException("Failed to JSON marshall: " + objectAsString, ioe);
    }
}

From source file:com.omertron.slackbot.listeners.GoogleSheetsListener.java

/**
 * Retrieve and display the next game information from the sheet
 *
 * @param session/*  w  w w.j a v a 2 s.co  m*/
 * @param msgChannel
 */
private synchronized static void readSheetInfo() {
    sheetInfo = new SheetInfo();
    ValueRange response = GoogleSheets.getSheetData(SS_ID, RANGE_NEXT_GAME_DATA);

    List<List<Object>> values = response.getValues();
    if (values != null && !values.isEmpty()) {
        for (List row : values) {
            if (!row.isEmpty()) {
                decodeRowFromSheet(row);
            }
        }
    }

    GameLogRow row = readGameLogRow(sheetInfo.getLastRow());
    if (row.getAttendees() != null) {
        String players = row.getAttendees();
        for (String p : StringUtils.split(players, ",")) {
            sheetInfo.addPlayer(findPlayer(p));
        }
    }

    // Deal with the issue that the game ID may have been read as "#NAME?" due to the sheet recalculating
    if (sheetInfo.getNextGameId() <= 0) {
        LOG.info("Updated game ID from {} to {}", sheetInfo.getNextGameId(), row.getGameId());
        sheetInfo.setNextGameId(row.getGameId());
    }

    LOG.info("SheetInfo READ:\n{}",
            ToStringBuilder.reflectionToString(sheetInfo, ToStringStyle.MULTI_LINE_STYLE));
}

From source file:eu.openanalytics.rsb.Util.java

/**
 * Marshals an {@link Object} to a pretty-printed JSON file.
 * /*from  w w w .ja  v a 2s. c  om*/
 * @param o
 * @throws IOException
 */
public static void toPrettyJsonFile(final Object o, final File f) throws IOException {
    try {
        PRETTY_JSON_OBJECT_MAPPER.writeValue(f, o);
    } catch (final JsonProcessingException jpe) {
        final String objectAsString = ToStringBuilder.reflectionToString(o, ToStringStyle.SHORT_PREFIX_STYLE);
        throw new RuntimeException("Failed to JSON marshall: " + objectAsString, jpe);
    }
}

From source file:gobblin.writer.http.SalesforceRestWriter.java

/**
 * Make it fail (throw exception) if status code is greater or equal to 400 except,
 * the status code is 400 and error code is duplicate value, regard it as success(do not throw exception).
 *
 * If status code is 401 or 403, re-acquire access token before make it fail -- retry will take care of rest.
 *
 * {@inheritDoc}//from w w w . j av  a 2 s. c  o m
 * @see gobblin.writer.http.HttpWriter#processResponse(org.apache.http.HttpResponse)
 */
@Override
public void processResponse(CloseableHttpResponse response) throws IOException, UnexpectedResponseException {
    if (getLog().isDebugEnabled()) {
        getLog().debug("Received response "
                + ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE));
    }

    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode == 401 || statusCode == 403) {
        getLog().info("Reacquiring access token.");
        accessToken = null;
        onConnect(oauthEndPoint);
        throw new RuntimeException(
                "Access denied. Access token has been reacquired and retry may solve the problem. "
                        + ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE));

    }
    if (batchSize > 1) {
        processBatchRequestResponse(response);
        numRecordsWritten += batchRecords.get().size();
        batchRecords = Optional.absent();
    } else {
        processSingleRequestResponse(response);
        numRecordsWritten++;
    }
}

From source file:cognitivej.vision.computervision.action.TagImageResponse.java

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}

From source file:gobblin.writer.http.SalesforceRestWriter.java

private void processSingleRequestResponse(CloseableHttpResponse response)
        throws IOException, UnexpectedResponseException {
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode < 400) {
        return;/*  ww w.  j  a  v a 2  s  .co  m*/
    }
    String entityStr = EntityUtils.toString(response.getEntity());
    if (statusCode == 400 && Operation.INSERT_ONLY_NOT_EXIST.equals(operation) && entityStr != null) { //Ignore if it's duplicate entry error code

        JsonArray jsonArray = new JsonParser().parse(entityStr).getAsJsonArray();
        JsonObject jsonObject = jsonArray.get(0).getAsJsonObject();
        if (isDuplicate(jsonObject, statusCode)) {
            return;
        }
    }
    throw new RuntimeException("Failed due to " + entityStr + " (Detail: "
            + ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE) + " )");
}

From source file:com.omertron.yamjtrakttv.tools.TraktTools.java

/**
 * Remove a show from the account completely
 *
 * @param shows/*w  ww .ja  va  2s. c om*/
 */
public static void removeShows(List<TvShow> shows) {
    ShowService service = MANAGER.showService();

    for (TvShow show : shows) {
        LOG.debug("Removing '" + show.title + "' (IMDB: " + show.imdbId + ", TVDB: " + show.tvdbId + ")");
        try {
            if (StringUtils.isNotBlank(show.tvdbId)) {
                int tvdbId = NumberUtils.toInt(show.tvdbId);
                ShowService.EpisodeUnseenBuilder unseen = service.episodeUnseen(tvdbId);
                ShowService.EpisodeUnwatchlistBuilder unwatch = service.episodeUnwatchlist(tvdbId);

                for (TvShowSeason season : show.seasons) {
                    for (Integer epnum : season.episodes.numbers) {
                        unseen = unseen.episode(season.season, epnum);
                        unwatch = unwatch.episode(season.season, epnum);
                    }
                }

                unseen.fire();
                unwatch.fire();
                LOG.debug("Done '" + show.title + "'");
            } else {
                LOG.warn("Failed to delete show! "
                        + ToStringBuilder.reflectionToString(show, ToStringStyle.SIMPLE_STYLE));
            }
        } catch (TraktException ex) {
            LOG.info("Exception: " + ex.getMessage(), ex);
        }
    }

    LOG.debug("Done");
}