Example usage for java.io IOException getStackTrace

List of usage examples for java.io IOException getStackTrace

Introduction

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

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.adslabs.adsfulltext.Worker.java

public boolean purge_all() {

    logger.info("Purging queues:");
    Queues[] queues = config.data.QUEUES;
    for (int i = 0; i < queues.length; i++) {
        try {/*from  w w  w  .  j a  v a  2  s  .co  m*/
            logger.info("{}: {}", i, queues[i].queue);
            // System.out.println("Purging queue: " + queues[i].queue);
            this.channel.queuePurge(queues[i].queue);

        } catch (java.io.IOException error) {

            logger.error("IO Error, is RabbitMQ running, check the passive/active settings!: {}, {}",
                    error.getMessage(), error.getStackTrace());
            return false;
        }
    }
    return true;
}

From source file:org.adslabs.adsfulltext.Worker.java

public boolean declare_all() {

    Exchanges[] exchange = config.data.EXCHANGES;

    for (int i = 0; i < exchange.length; i++) {
        try {/*from www  .  j  ava 2s .c  om*/
            // OUTDATED
            // Parameters are exchange name, type, passive, durable, autoDelete, arguments
            // OUTDATED
            // On github of the client api: exchange name, type, durable, autoDelete, internal
            // internal: internal true if the exchange is internal, i.e. can't be directly published to by a client.
            logger.info("Declaring the following queue; exchange: {}, type: {}, durable: {}, auto-delete: {}",
                    exchange[i].exchange, exchange[i].exchange_type, exchange[i].durable,
                    exchange[i].autoDelete);
            this.channel.exchangeDeclare(exchange[i].exchange, exchange[i].exchange_type, exchange[i].durable,
                    exchange[i].autoDelete, null);

        } catch (java.io.IOException error) {

            logger.error("IO Error, is RabbitMQ running, check the passive/active settings!: {},{}",
                    error.getMessage(), error.getStackTrace());
            return false;
        }
    }
    return true;
}

From source file:net.itransformers.idiscover.v2.core.node_discoverers.snmpdiscoverer.SnmpSequentialNodeDiscoverer.java

@Override
public NodeDiscoveryResult discover(ConnectionDetails connectionDetails) {
    Map<String, String> params1 = new HashMap<String, String>();
    String deviceName = connectionDetails.getParam("deviceName");

    NodeDiscoveryResult result = new NodeDiscoveryResult();

    if (deviceName != null && !deviceName.isEmpty()) {
        params1.put("deviceName", deviceName);

    }/*  ww w.ja  v  a2s .c o  m*/
    String deviceType = connectionDetails.getParam("deviceType");
    if (deviceType != null && !deviceType.isEmpty()) {
        params1.put("deviceType", deviceType);

    }
    String ipAddressStr = connectionDetails.getParam("ipAddress");

    if (ipAddressStr != null && !ipAddressStr.isEmpty()) {
        params1.put("ipAddress", ipAddressStr);

    }
    String dnsCanonicalName = null;
    String dnsShortName = null;
    InetAddress inetAddress = null;
    SnmpManager snmpManager = null;
    Map<String, String> snmpConnParams = new HashMap<String, String>();

    ResourceType snmpResource = this.discoveryResource.returnResourceByParam(params1);
    List<ResourceType> snmpResources = this.discoveryResource.returnResourcesByConnectionType("snmp");
    String sysDescr;
    snmpConnParams = this.discoveryResource.getParamMap(snmpResource, "snmp");
    snmpConnParams.put("ipAddress", ipAddressStr);
    boolean reachable;
    SnmpManagerCreator snmpManagerCreator = new SnmpManagerCreator(mibLoaderHolder);

    try {
        reachable = inetAddress.isReachable(Integer.parseInt(snmpConnParams.get("timeout")));
        logger.info("Device with " + inetAddress.getHostAddress() + "is " + reachable);
        //Try first with the most probable snmp Resource
        snmpManager = snmpManagerCreator.create(snmpConnParams);
        snmpManager.init();
        sysDescr = snmpGet(snmpManager, "1.3.6.1.2.1.1.1.0");

        //If it does not work try with the rest

        if (sysDescr == null) {
            snmpManager.closeSnmp();
            logger.info("Can't connect to: " + ipAddressStr + " with " + snmpConnParams);

            for (ResourceType resourceType : snmpResources) {
                snmpConnParams = this.discoveryResource.getParamMap(resourceType, "snmp");
                snmpConnParams.put("ipAddress", ipAddressStr);

                if (!resourceType.getName().equals(snmpResource.getName())) {

                    snmpManager = snmpManagerCreator.create(snmpConnParams);
                    snmpManager.init();
                    sysDescr = snmpGet(snmpManager, "1.3.6.1.2.1.1.1.0");
                    if (sysDescr == null) {
                        logger.info("Can't connect to: " + ipAddressStr + " with " + snmpConnParams);
                        snmpManager.closeSnmp();
                    } else {
                        deviceType = DeviceTypeResolver.getDeviceType(sysDescr);
                        logger.info("Connected to: " + ipAddressStr + " with " + snmpConnParams);
                        deviceName = StringUtils.substringBefore(snmpGet(snmpManager, "1.3.6.1.2.1.1.5.0"),
                                ".");
                        break;
                    }
                }
            }
        } else {
            deviceType = DeviceTypeResolver.getDeviceType(sysDescr);
            logger.info("Connected to: " + ipAddressStr + " with " + snmpConnParams);
            deviceName = StringUtils.substringBefore(snmpGet(snmpManager, "1.3.6.1.2.1.1.5.0"), ".");
        }
    } catch (IOException e) {
        logger.error("Something went wrong in SNMP communication with " + ipAddressStr
                + ":Check the stacktrace \n" + e.getStackTrace());
        return null;
    }

    //Despite all our efforts we got nothing from that device!
    if (sysDescr == null) {
        if (deviceName != null) {
            result = new NodeDiscoveryResult(deviceName, null, null);
        } else if (dnsCanonicalName != null) {
            result = new NodeDiscoveryResult(dnsShortName, null, null);
        } else {
            result = new NodeDiscoveryResult(ipAddressStr, null, null);
        }

        return result;
    }
    DiscoveryHelper discoveryHelper = discoveryHelperFactory.createDiscoveryHelper(deviceType);
    String[] requestParamsList = discoveryHelper.getRequestParams(discoveryTypes);

    Node rawDatNode = null;
    net.itransformers.idiscover.api.models.node_data.RawDeviceData rawData = null;
    try {
        rawDatNode = snmpManager.snmpWalk(requestParamsList);
        snmpManager.closeSnmp();

    } catch (IOException e) {
        e.printStackTrace();
    }
    if (rawDatNode != null) {
        SnmpXmlPrinter snmpXmlPrinter = new SnmpXmlPrinter(mibLoaderHolder.getLoader(), rawDatNode);
        rawData = new net.itransformers.idiscover.api.models.node_data.RawDeviceData(
                snmpXmlPrinter.printTreeAsXML().getBytes());

        logger.trace(new String(rawData.getData()));

    } else {

        return null;
    }
    SnmpForXslt.setMibLoaderHolder(mibLoaderHolder);
    snmpConnParams.put("neighbourIPDryRun", "true");
    discoveryHelper.parseDeviceRawData(rawData, discoveryTypes, snmpConnParams);

    SnmpForXslt.resolveIPAddresses(discoveryResource, "snmp");
    snmpConnParams.put("neighbourIPDryRun", "false");

    DiscoveredDeviceData discoveredDeviceData = discoveryHelper.parseDeviceRawData(rawData, discoveryTypes,
            snmpConnParams);

    Device device = discoveryHelper.createDevice(discoveredDeviceData);

    List<DeviceNeighbour> neighbours = device.getDeviceNeighbours();
    Set<Subnet> subnets = device.getDeviceSubnets();
    Set<ConnectionDetails> neighboursConnDetails = null;
    if (neighbours != null) {

        //TODO adapt for new algorthm and new DiscoveredDevice
        NeighbourConnectionDetails neighbourConnectionDetails = null;
        neighboursConnDetails = neighbourConnectionDetails.getConnectionDetailses();
    }

    Set<ConnectionDetails> subnetConnectionDetails = null;

    if (subnets != null) {
        SubnetConnectionDetails subnetConnectionDetailsCreator = new SubnetConnectionDetails();
        subnetConnectionDetailsCreator.load(subnets);
        neighboursConnDetails.addAll(subnetConnectionDetails);

    }

    //TODO add also own connectionDetails
    result = new NodeDiscoveryResult(deviceName, neighboursConnDetails, null);
    result.setDiscoveredData("deviceData", discoveredDeviceData);
    result.setDiscoveredData("rawData", rawData.getData());
    return result;
}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * loadClip loads the sound-file into a clip.
 * //from w w w. ja va 2 s .c om
 * @param soundFile
 *          file to be loaded and played.
 */
public static void loadClip(String soundFile) {
    AudioFormat audioFormat = null;
    AudioInputStream actionIS = null;
    try {
        // actionIS = AudioSystem.getAudioInputStream(input); // Does not work !
        actionIS = AudioSystem.getAudioInputStream(MToolKit.getFile(MToolKit.getSoundFile(soundFile)));
        AudioFormat.Encoding targetEncoding = AudioFormat.Encoding.PCM_SIGNED;
        actionIS = AudioSystem.getAudioInputStream(targetEncoding, actionIS);
        audioFormat = actionIS.getFormat();

    } catch (UnsupportedAudioFileException afex) {
        Log.error(afex);
    } catch (IOException ioe) {

        if (ioe.getMessage().equalsIgnoreCase("mark/reset not supported")) { // Ignore
            Log.error("IOException ignored.");
        }
        Log.error(ioe.getStackTrace());
    }

    // define the required attributes for our line,
    // and make sure a compatible line is supported.

    // get the source data line for play back.
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
    if (!AudioSystem.isLineSupported(info)) {
        Log.error("LineCtrl matching " + info + " not supported.");
        return;
    }

    // Open the source data line for play back.
    try {
        Clip clip = null;
        try {
            Clip.Info info2 = new Clip.Info(Clip.class, audioFormat);
            clip = (Clip) AudioSystem.getLine(info2);
            clip.open(actionIS);
            clip.start();
        } catch (IOException ioe) {
            Log.error(ioe);
        }
    } catch (LineUnavailableException ex) {
        Log.error("Unable to open the line: " + ex);
        return;
    }
}

From source file:business.services.RequestService.java

public HttpEntity<InputStreamResource> writeRequestListCsv(List<RequestRepresentation> requests) {
    try {/*  w ww .jav a2  s .  c o m*/
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Writer writer = new OutputStreamWriter(out, CSV_CHARACTER_ENCODING);
        CSVWriter csvwriter = new CSVWriter(writer, ';', '"');
        csvwriter.writeNext(CSV_COLUMN_NAMES);

        for (RequestRepresentation request : requests) {
            List<String> values = new ArrayList<>();
            values.add(request.getRequestNumber());
            values.add(DATE_FORMATTER.print(request.getDateCreated(), LOCALE));
            values.add(request.getTitle());
            values.add(request.getStatus().toString());
            values.add(booleanToString(request.isLinkageWithPersonalData()));
            values.add(request.getLinkageWithPersonalDataNotes());
            values.add(booleanToString(request.isStatisticsRequest()));
            values.add(booleanToString(request.isExcerptsRequest()));
            values.add(booleanToString(request.isPaReportRequest()));
            values.add(booleanToString(request.isMaterialsRequest()));
            values.add(booleanToString(request.isClinicalDataRequest()));
            values.add(request.getRequesterName());
            values.add(request.getLab() == null ? "" : request.getLab().getNumber().toString());
            values.add(request.getRequester() == null ? "" : request.getRequester().getSpecialism());
            values.add(labRequestService.countHubAssistanceLabRequestsForRequest(request.getProcessInstanceId())
                    .toString());
            values.add(request.getPathologistName());
            csvwriter.writeNext(values.toArray(new String[] {}));
        }
        csvwriter.flush();
        writer.flush();
        out.flush();
        InputStream in = new ByteArrayInputStream(out.toByteArray());
        csvwriter.close();
        writer.close();
        out.close();
        InputStreamResource resource = new InputStreamResource(in);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf("text/csv"));
        String filename = "requests_" + DATE_FORMATTER.print(new Date(), LOCALE) + ".csv";
        headers.set("Content-Disposition", "attachment; filename=" + filename);
        HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers);
        log.info("Returning reponse.");
        return response;
    } catch (IOException e) {
        log.error(e.getStackTrace());
        log.error(e.getMessage());
        throw new FileDownloadError();
    }

}

From source file:eu.smartenit.unada.sm.MonitorRunner.java

/**
 * Issues a request to vimeo and converts the result to a suitable JSONObject.
 *
 * @param contentID The content ID for which metadata is to be retrieved.
 * @return The JSONObject created from the response of the request.
 *///  w  ww . j a v  a  2  s.  c  om
private JSONObject vimeoRequest(long contentID) {
    String responseAsString = null;
    CloseableHttpResponse response = null;
    ByteArrayOutputStream out = null;
    try {
        CloseableHttpClient client = HttpClients.createDefault();
        String url = createURL(contentID);
        logger.debug("Sending request to " + url);
        HttpGet httpGet = new HttpGet(url);
        response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        out = new ByteArrayOutputStream();
        entity.writeTo(out);
        responseAsString = out.toString("UTF-8");
        out.close();

    } catch (IOException e) {
        logger.error(e.getMessage(), e.getStackTrace());
    } finally {
        if (response != null) {
            try {
                response.close();
            } catch (IOException e) {
                logger.error(e.getMessage(), e.getStackTrace());
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                logger.error(e.getMessage(), e.getStackTrace());
            }
        }

    }
    if (responseAsString == null) {
        return toJSON("{}");
    } else {
        responseAsString = responseAsString.substring(1, responseAsString.length() - 1);
        logger.debug("Converting response to JSON...");
        JSONObject JSONResponse = toJSON(responseAsString);
        logger.debug("Done.");
        return JSONResponse;
    }
}

From source file:com.oakesville.mythling.util.HttpHelper.java

private void rethrow(IOException ex, String msgPrefix) throws IOException {
    if (msgPrefix == null) {
        throw ex;
    } else {//from w w w .j av  a2  s  .c o  m
        IOException re = new IOException(msgPrefix + ": " + ex.getMessage());
        re.setStackTrace(ex.getStackTrace());
        throw re;
    }
}

From source file:org.sonar.plugins.delphi.project.DelphiProject.java

/**
 * C-tor, initializes project with data loaded from xml file
 *
 * @param xml XML file to parse/*from   ww  w  .jav  a2 s  . c  om*/
 */
public DelphiProject(File xml) {
    try {
        parseFile(xml);
    } catch (IOException e) {
        DelphiUtils.LOG.error("Could not find .dproj file: " + xml.getAbsolutePath());
    } catch (IllegalArgumentException e) {
        DelphiUtils.LOG.error("No .dproj file to parse. (null)");
    } catch (Exception e) {
        //TODO: Try to remove this Exception
        DelphiUtils.LOG.error("This Exception should not be thrown, specifie it if occures"
                + Arrays.toString(e.getStackTrace()));
    }
}

From source file:org.protocoder.network.ProtocoderHttpServer.java

private Response sendProjectFile(String uri, String method, Properties header, Properties parms,
        Properties files) {/*from   w w w .j  av  a 2s .c o m*/

    Response res = null;

    // Clean up uri
    uri = uri.trim().replace(File.separatorChar, '/');
    MLog.d(TAG, uri);

    // have the object build the directory structure, if needed.
    AssetManager am = ctx.get().getAssets();
    try {
        MLog.d(TAG, WEBAPP_DIR + uri);
        InputStream fi = am.open(WEBAPP_DIR + uri);

        // Get MIME type from file name extension, if possible
        String mime = null;
        int dot = uri.lastIndexOf('.');
        if (dot >= 0) {
            mime = MIME_TYPES.get(uri.substring(dot + 1).toLowerCase());
        }
        if (mime == null) {
            mime = NanoHTTPD.MIME_DEFAULT_BINARY;
        }

        res = new Response(HTTP_OK, mime, fi);
    } catch (IOException e) {
        e.printStackTrace();
        MLog.d(TAG, e.getStackTrace().toString());
        res = new Response(HTTP_INTERNALERROR, "text/html", "ERROR: " + e.getMessage());
    }

    return res;

}

From source file:org.protocoder.network.ProtocoderHttpServer.java

private Response sendWebAppFile(String uri, String method, Properties header, Properties parms,
        Properties files) {//from   w  ww.j av a 2s  . c o m
    Response res = null;

    MLog.d(TAG, "" + method + " '" + uri + " " + /* header + */" " + parms);

    String escapedCode = parms.getProperty("code");
    String unescapedCode = StringEscapeUtils.unescapeEcmaScript(escapedCode);
    MLog.d("HTTP Code", "" + escapedCode);
    MLog.d("HTTP Code", "" + unescapedCode);

    // Clean up uri
    uri = uri.trim().replace(File.separatorChar, '/');
    if (uri.indexOf('?') >= 0) {
        uri = uri.substring(0, uri.indexOf('?'));
    }

    // We never want to request just the '/'
    if (uri.length() == 1) {
        uri = "index.html";
    }

    // We're using assets, so we can't have a leading '/'
    if (uri.charAt(0) == '/') {
        uri = uri.substring(1, uri.length());
    }

    // have the object build the directory structure, if needed.
    AssetManager am = ctx.get().getAssets();
    try {
        MLog.d(TAG, WEBAPP_DIR + uri);
        InputStream fi = am.open(WEBAPP_DIR + uri);

        // Get MIME type from file name extension, if possible
        String mime = null;
        int dot = uri.lastIndexOf('.');
        if (dot >= 0) {
            mime = MIME_TYPES.get(uri.substring(dot + 1).toLowerCase());
        }
        if (mime == null) {
            mime = NanoHTTPD.MIME_DEFAULT_BINARY;
        }

        res = new Response(HTTP_OK, mime, fi);
    } catch (IOException e) {
        e.printStackTrace();
        MLog.d(TAG, e.getStackTrace().toString());
        res = new Response(HTTP_INTERNALERROR, "text/html", "ERROR: " + e.getMessage());
    }

    return res;

}