Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

In this page you can find the example usage for java.io IOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:fi.iki.murgo.irssinotifier.Server.java

private boolean authenticate(int retryCount) throws IOException {
    if (usingDevServer) {
        BasicClientCookie2 cookie = new BasicClientCookie2("dev_appserver_login",
                "irssinotifier@gmail.com:False:118887942201532232498");
        cookie.setDomain("10.0.2.2");
        cookie.setPath("/");
        http_client.getCookieStore().addCookie(cookie);

        return true;
    }/*from  w w w .j a  v a  2  s . com*/

    String token = preferences.getAuthToken();
    try {
        if (token == null) {
            String accountName = preferences.getAccountName();
            if (accountName == null) {
                return false;
            }

            token = generateToken(accountName);
            preferences.setAuthToken(token);
        }

        boolean success = doAuthenticate(token);
        if (success) {
            Log.v(TAG, "Succesfully logged in.");
            return true;
        }
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        Log.e(TAG, "Unable to send settings: " + e.toString());
        e.printStackTrace();
        preferences.setAccountName(null); // reset because authentication or unforeseen error
        return false;
    }

    Log.w(TAG, "Login failed, retrying... Retry count " + (retryCount + 1));
    http_client = new DefaultHttpClient();
    preferences.setAuthToken(null);

    if (retryCount >= maxRetryCount) {
        preferences.setAccountName(null); // reset because it's not accepted by the server
        return false;
    }

    return authenticate(retryCount + 1);
}

From source file:com.altcanvas.asocial.Twitter.java

public JSONObject update(String status) throws AsocialException {
    HashMap<String, String> postParams = new HashMap<String, String>();
    postParams.put("status", status);
    postParams.put("source", SOURCE);

    setOAuth("POST", updateURL, postParams);

    try {/*from  ww  w. j  a v  a  2 s.c om*/
        return new JSONObject(Http.post(updateURL, headers, postParams));
    } catch (HttpException he) {
        throw new AsocialException(he.responseCode, he.toString());
    } catch (JSONException je) {
        throw new AsocialException(AsocialException.JSONE, je.toString());
    } catch (IOException ioe) {
        throw new AsocialException(AsocialException.IOE, ioe.toString());
    }
}

From source file:com.panet.imeta.job.entries.fileexists.JobEntryFileExists.java

public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) {
    LogWriter log = LogWriter.getInstance();
    Result result = previousResult;
    result.setResult(false);//  w  w  w . ja  v  a 2 s .co m

    if (filename != null) {
        String realFilename = getRealFilename();
        try {
            FileObject file = KettleVFS.getFileObject(realFilename);
            if (file.exists() && file.isReadable()) {
                log.logDetailed(toString(), Messages.getString("JobEntryFileExists.File_Exists", realFilename)); //$NON-NLS-1$
                result.setResult(true);
            } else {
                log.logDetailed(toString(),
                        Messages.getString("JobEntryFileExists.File_Does_Not_Exist", realFilename)); //$NON-NLS-1$
            }
        } catch (IOException e) {
            result.setNrErrors(1);
            log.logError(toString(),
                    Messages.getString("JobEntryFileExists.ERROR_0004_IO_Exception", e.toString())); //$NON-NLS-1$
        }
    } else {
        result.setNrErrors(1);
        log.logError(toString(), Messages.getString("JobEntryFileExists.ERROR_0005_No_Filename_Defined")); //$NON-NLS-1$
    }

    return result;
}

From source file:com.streamsets.datacollector.execution.store.FilePipelineStateStore.java

@Override
public List<PipelineState> getHistory(String pipelineName, String rev, boolean fromBeginning)
        throws PipelineStoreException {
    if (!pipelineDirExists(pipelineName, rev) || !pipelineStateHistoryFileExists(pipelineName, rev)) {
        return Collections.emptyList();
    }// www. j a  v  a 2  s .  c o m
    try (Reader reader = new FileReader(getPipelineStateHistoryFile(pipelineName, rev))) {
        ObjectMapper objectMapper = ObjectMapperFactory.get();
        JsonParser jsonParser = objectMapper.getFactory().createParser(reader);
        MappingIterator<PipelineStateJson> pipelineStateMappingIterator = objectMapper.readValues(jsonParser,
                PipelineStateJson.class);
        List<PipelineStateJson> pipelineStateJsons = pipelineStateMappingIterator.readAll();
        Collections.reverse(pipelineStateJsons);
        if (fromBeginning) {
            return BeanHelper.unwrapPipelineStatesNewAPI(pipelineStateJsons);
        } else {
            int toIndex = pipelineStateJsons.size() > 100 ? 100 : pipelineStateJsons.size();
            return BeanHelper.unwrapPipelineStatesNewAPI(pipelineStateJsons.subList(0, toIndex));
        }
    } catch (IOException e) {
        throw new PipelineStoreException(ContainerError.CONTAINER_0115, pipelineName, rev, e.toString(), e);
    }
}

From source file:com.streamsets.pipeline.lib.parser.log.LogDataParserFactory.java

private DataParser createParser(String id, OverrunReader reader, long offset) throws DataParserException {
    Utils.checkState(reader.getPos() == 0,
            Utils.formatL("reader must be in position '0', it is at '{}'", reader.getPos()));
    try {//from w w w.  j  av  a 2s .c  o m
        switch (logMode) {
        case COMMON_LOG_FORMAT:
            return new GrokParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    getMaxStackTraceLines(),
                    createGrok(Constants.GROK_COMMON_APACHE_LOG_FORMAT, Collections.<String>emptyList()),
                    "Common Log Format", currentLineBuilderPool, previousLineBuilderPool);
        case COMBINED_LOG_FORMAT:
            return new GrokParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    getMaxStackTraceLines(),
                    createGrok(Constants.GROK_COMBINED_APACHE_LOG_FORMAT, Collections.<String>emptyList()),
                    "Combined Log Format", currentLineBuilderPool, previousLineBuilderPool);
        case APACHE_CUSTOM_LOG_FORMAT:
            return new GrokParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    getMaxStackTraceLines(),
                    createGrok(ApacheCustomLogHelper.translateApacheLayoutToGrok(customLogFormat),
                            Collections.<String>emptyList()),
                    "Apache Access Log Format", currentLineBuilderPool, previousLineBuilderPool);
        case APACHE_ERROR_LOG_FORMAT:
            return new GrokParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    getMaxStackTraceLines(),
                    createGrok(Constants.GROK_APACHE_ERROR_LOG_FORMAT,
                            ImmutableList.of(Constants.GROK_APACHE_ERROR_LOG_PATTERNS_FILE_NAME)),
                    "Apache Error Log Format", currentLineBuilderPool, previousLineBuilderPool);
        case REGEX:
            return new RegexParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    createPattern(regex), fieldPathToGroup, currentLineBuilderPool, previousLineBuilderPool);
        case GROK:
            return new GrokParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    getMaxStackTraceLines(), createGrok(grokPattern, grokDictionaries), "Grok Format",
                    currentLineBuilderPool, previousLineBuilderPool);
        case LOG4J:
            return new GrokParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    getMaxStackTraceLines(),
                    createGrok(Log4jHelper.translateLog4jLayoutToGrok(log4jCustomLogFormat),
                            ImmutableList.of(Constants.GROK_LOG4J_LOG_PATTERNS_FILE_NAME)),
                    "Log4j Log Format", currentLineBuilderPool, previousLineBuilderPool);
        case CEF:
            return new CEFParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    currentLineBuilderPool, previousLineBuilderPool);
        case LEEF:
            return new LEEFParser(context, id, reader, offset, maxObjectLen, retainOriginalText,
                    currentLineBuilderPool, previousLineBuilderPool);
        default:
            return null;
        }
    } catch (IOException ex) {
        throw new DataParserException(Errors.LOG_PARSER_00, id, offset, ex.toString(), ex);
    }
}

From source file:com.altcanvas.asocial.Twitter.java

public JSONObject verifyCreds() throws AsocialException {
    try {//from w  ww .  j av a 2 s.  c o m
        JSONObject json = new JSONObject(Http.get(twitterURL + "account/verify_credentials.json", headers));

        // Authentication failed
        if (json.optString("error", null) != null)
            return null;

        return json;

    } catch (HttpException he) {
        throw new AsocialException(he.responseCode, he.toString());
    } catch (JSONException je) {
        throw new AsocialException(AsocialException.JSONE, je.toString());
    } catch (IOException ioe) {
        throw new AsocialException(AsocialException.IOE, ioe.toString());
    }
}

From source file:alfio.plugin.mailchimp.MailChimpPlugin.java

private boolean send(int eventId, String address, String apiKey, String email, CustomerName name,
        String language, String eventKey) {
    Map<String, Object> content = new HashMap<>();
    content.put("email_address", email);
    content.put("status", "subscribed");
    Map<String, String> mergeFields = new HashMap<>();
    mergeFields.put("FNAME", name.isHasFirstAndLastName() ? name.getFirstName() : name.getFullName());
    mergeFields.put(ALFIO_EVENT_KEY, eventKey);
    content.put("merge_fields", mergeFields);
    content.put("language", language);
    Request request = new Request.Builder().url(address)
            .header("Authorization", Credentials.basic("alfio", apiKey))
            .put(RequestBody.create(MediaType.parse(APPLICATION_JSON), Json.GSON.toJson(content, Map.class)))
            .build();//from www.  ja va2  s . c o  m
    try (Response response = httpClient.newCall(request).execute()) {

        if (response.isSuccessful()) {
            pluginDataStorage.registerSuccess(String.format("user %s has been subscribed to list", email),
                    eventId);
            return true;
        }
        ResponseBody body = response.body();
        if (body == null) {
            return false;
        }
        String responseBody = body.string();
        if (response.code() != 400 || responseBody.contains("\"errors\"")) {
            pluginDataStorage.registerFailure(String.format(FAILURE_MSG, email, name, language, responseBody),
                    eventId);
            return false;
        } else {
            pluginDataStorage.registerWarning(String.format(FAILURE_MSG, email, name, language, responseBody),
                    eventId);
        }
        return true;
    } catch (IOException e) {
        pluginDataStorage.registerFailure(String.format(FAILURE_MSG, email, name, language, e.toString()),
                eventId);
        return false;
    }
}

From source file:com.altcanvas.asocial.Twitter.java

public void getRequestToken() throws AsocialException {
    Map<String, String> noPostParams = new HashMap<String, String>();

    setOAuth("POST", reqtokenURL, noPostParams);

    try {/*w ww  .j  a  v a2 s .c o  m*/
        String response = Http.post(reqtokenURL, headers, noPostParams);
        if (response == null) {
            throw new AsocialException(AsocialException.EMPTY_RESP, "Empty response");
        }
        HashMap<String, String> map = parseResponse(response);
        this.token = map.get("oauth_token");
        this.tokenSecret = map.get("oauth_token_secret");
    } catch (HttpException he) {
        throw new AsocialException(he.responseCode, he.toString());
    } catch (IOException ioe) {
        throw new AsocialException(AsocialException.IOE, ioe.toString());
    }
}

From source file:com.walmart.gatling.commons.ScriptExecutor.java

private Object runJob(Object message) {
    Master.Job job = (Master.Job) message;
    TaskEvent taskEvent = (TaskEvent) job.taskEvent;

    CommandLine cmdLine = new CommandLine(agentConfig.getJob().getCommand());
    log.info("Verified Script worker received task: {}", message);
    Map<String, Object> map = new HashMap<>();

    if (StringUtils.isNotEmpty(agentConfig.getJob().getMainClass()))
        cmdLine.addArgument(agentConfig.getJob().getCpOrJar());

    map.put("path", new File(agentConfig.getJob().getJobArtifact(taskEvent.getJobName())));
    cmdLine.addArgument("${path}");

    if (!StringUtils.isEmpty(agentConfig.getJob().getMainClass())) {
        cmdLine.addArgument(agentConfig.getJob().getMainClass());
    }//from   www.  j  a  v a  2 s  .c om
    //parameters come from the task event
    for (Pair<String, String> pair : taskEvent.getParameters()) {
        cmdLine.addArgument(pair.getValue());
    }
    cmdLine.addArgument("-rf").addArgument(agentConfig.getJob().getResultPath(job.roleId, job.jobId));

    cmdLine.setSubstitutionMap(map);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValues(agentConfig.getJob().getExitValues());
    ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
    executor.setWatchdog(watchdog);
    executor.setWorkingDirectory(new File(agentConfig.getJob().getPath()));
    FileOutputStream outFile = null;
    FileOutputStream errorFile = null;
    String outPath = "", errPath = "";
    try {
        outPath = agentConfig.getJob().getOutPath(taskEvent.getJobName(), job.jobId);
        errPath = agentConfig.getJob().getErrorPath(taskEvent.getJobName(), job.jobId);
        //create the std and err files
        outFile = FileUtils.openOutputStream(new File(outPath));
        errorFile = FileUtils.openOutputStream(new File(errPath));

        PumpStreamHandler psh = new PumpStreamHandler(new ExecLogHandler(outFile),
                new ExecLogHandler(errorFile));
        executor.setStreamHandler(psh);
        log.info("command: {}", cmdLine);
        int exitResult = executor.execute(cmdLine);
        //executor.getWatchdog().destroyProcess().
        Worker.Result result = new Worker.Result(exitResult, agentConfig.getUrl(errPath),
                agentConfig.getUrl(outPath), null, job);
        log.info("Exit code: {}", exitResult);
        if (executor.isFailure(exitResult) || exitResult == 1) {
            log.info("Script Executor Failed, job: " + job.jobId);
            //getSender().tell(new Worker.WorkFailed(result), getSelf());
            return new Worker.WorkFailed(result);
        } else {
            result = new Worker.Result(exitResult, agentConfig.getUrl(errPath), agentConfig.getUrl(outPath),
                    agentConfig.getUrl(getMetricsPath(job)), job);
            log.info("Script Executor Completed, job: " + result);
            //getSender().tell(new Worker.WorkComplete(result), getSelf());
            return new Worker.WorkComplete(result);
        }

    } catch (IOException e) {
        log.error(e.toString());
        Worker.Result result = new Worker.Result(-1, agentConfig.getUrl(errPath), agentConfig.getUrl(outPath),
                null, job);
        log.info("Executor Encountered run time exception, result: " + result.toString());
        //getSender().tell(new Worker.WorkFailed(result), getSelf());
        return new Worker.WorkFailed(result);
    } finally {
        IOUtils.closeQuietly(outFile);
        IOUtils.closeQuietly(errorFile);
    }
}