Example usage for java.net MalformedURLException printStackTrace

List of usage examples for java.net MalformedURLException printStackTrace

Introduction

In this page you can find the example usage for java.net MalformedURLException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.denimgroup.threadfix.service.defects.RestUtils.java

public static InputStream getUrl(String urlString, String username, String password) {
    URL url = null;//from ww  w.  ja  v  a2 s  .co m
    try {
        url = new URL(urlString);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    }
    InputStream is = null;
    HttpURLConnection httpConnection;
    try {
        httpConnection = (HttpURLConnection) url.openConnection();

        setupAuthorization(httpConnection, username, password);

        httpConnection.addRequestProperty("Content-Type", "application/json");
        httpConnection.addRequestProperty("Accept", "application/json");

        is = httpConnection.getInputStream();

        return is;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return is;
}

From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java

/**
 * ?post??/* w w w .j  a  v a2s .co m*/
 * 
 * @param url
 * @return
 */
public static HttpPost getPostMethod(String url) {

    URI uri = null;
    try {
        URL _url = new URL(url);
        uri = new URI(_url.getProtocol(), _url.getHost(), _url.getPath(), _url.getQuery(), null);

    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    HttpPost pmethod = new HttpPost(uri); // ??
    pmethod.addHeader("Connection", "keep-alive");
    pmethod.addHeader("Accept", "*/*");
    pmethod.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    pmethod.addHeader("Host", "mp.weixin.qq.com");
    pmethod.addHeader("X-Requested-With", "XMLHttpRequest");
    pmethod.addHeader("Cache-Control", "max-age=0");
    pmethod.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
    return pmethod;
}

From source file:com.bjorsond.android.timeline.sync.ServerUploader.java

private static boolean fileExistsOnServer(String URLName) {
    URL url;/*from   w w w.  j  av a 2s.com*/
    try {
        url = new URL(URLName);
        URLConnection connection = url.openConnection();

        connection.connect();

        // Cast to a HttpURLConnection
        if (connection instanceof HttpURLConnection) {
            HttpURLConnection httpConnection = (HttpURLConnection) connection;

            int code = httpConnection.getResponseCode();

            if (code == 200)
                return true;
        } else {
            System.err.println("error - not a http request!");
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return false;
}

From source file:com.surenpi.autotest.suite.SuiteRunnerLauncher.java

/**
 * ??/* w ww. ja  v  a 2  s  .co  m*/
 * @param param
 */
private static void compile(RunnerParam param) {
    URL itemUrl = SuiteRunnerLauncher.class.getResource("/");
    if (itemUrl == null) {
        logger.warn("Can not get base url from root. Try use current dir.");

        try {
            itemUrl = new File(".").toURI().toURL();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    logger.debug("Base url : {}", itemUrl);

    String protocol = itemUrl.getProtocol();
    if ("file".equals(protocol)) {
        String file = itemUrl.getFile();
        File[] subFiles = new File(file).listFiles(new PageXmlFilter());

        Generator generator = new DefaultXmlCodeGenerator() {
            @Override
            protected void done() {
                super.done();
            }
        };

        for (File pageFile : subFiles) {
            generator.generate(pageFile.getName(), param.compileDstDir);
        }

        JDTUtils utils = new JDTUtils(param.compileDstDir);
        utils.compileAllFile();

        try {
            logger.info("Compile dest dir: {}.", new File(param.compileDstDir).getAbsolutePath());

            ClassLoader loader = new URLClassLoader(
                    new URL[] { new File(param.compileDstDir).toURI().toURL() }) {
                @Override
                protected Class<?> findClass(String s) throws ClassNotFoundException {
                    return super.findClass(s);
                }
            };

            Thread.currentThread().setContextClassLoader(loader);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.android.feedmeandroid.HTTPClient.java

public static Bitmap downloadFile(final String fileUrl) {
    final Bitmap[] bitmap = new Bitmap[1];
    Thread t = new Thread(new Runnable() {
        public void run() {
            URL myFileUrl = null;
            try {
                myFileUrl = new URL(fileUrl);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }// w w w.  j av a  2 s .  co  m
            try {
                HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                InputStream is = conn.getInputStream();

                Bitmap bmImg = BitmapFactory.decodeStream(is);
                bitmap[0] = bmImg;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    t.start();
    try {
        t.join();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return bitmap[0];
}

From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java

private static void initLogging() {
    System.setProperty("appDir", SystemUtils.getPropertyDir().getAbsolutePath());

    URL logConfigUrl = null;//w w  w . j a  v  a  2  s .c o  m
    File logConfigFile = new File(SystemUtils.getPropertyDir(), "/logging.properties");

    if (logConfigFile.exists()) {
        try {
            logConfigUrl = logConfigFile.toURI().toURL();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else {
        logConfigUrl = EzDL.class.getResource("/log/logging.properties");
    }

    if (logConfigUrl != null) {
        PropertyConfigurator.configure(logConfigUrl);
    } else {
        System.err.println("no logger config found!");
    }

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            logger.error("Uncaught exception in Thread " + t.getName(), e);
        }
    });
    System.err.close();
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java

public static boolean connect(int i) {
    JMXConnector jmxc = null;/*  ww  w . ja va2  s .c om*/
    JMXServiceURL url = null;

    try {
        url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i);
        jmxc = JMXConnectorFactory.connect(url, null);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        return false;
        // System.out.println("Could not connect to address: " + url);
        // e.printStackTrace();
    }
    if (jmxc != null) {
        try {
            MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
            ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME);
            Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations");
            Object currentTest = mbsc.getAttribute(objectName, "CurrentTest");
            Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation");
            Object allMutations = mbsc.getAttribute(objectName, "Mutations");
            Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration");
            Object testDuration = mbsc.getAttribute(objectName, "TestDuration");
            //            Object mutationSummary = mbsc.getAttribute(objectName,
            //                  "MutationSummary");

            final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc,
                    ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);

            final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc,
                    ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
            System.out.print("Connection: " + i + "  ");
            System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor()
                    + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion());
            System.out.println(
                    "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime()));
            System.out
                    .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed())
                            + "  Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed()));

            String mutationDurationFormatted = DurationFormatUtils
                    .formatDurationHMS(Long.parseLong(mutationsDuration.toString()));
            String testDurationFormatted = DurationFormatUtils
                    .formatDurationHMS(Long.parseLong(testDuration.toString()));
            if (DEBUG_ADD) {
                System.out.println("Classpath: " + remoteRuntime.getClassPath());
                System.out.println("Args: " + remoteRuntime.getInputArguments());
                System.out.println("All Mutations: " + allMutations);
            }
            //            System.out.println(mutationSummary);
            System.out.println(
                    "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation);
            System.out.println("Mutations tested: " + numberOfMutations);
            System.out.println("Current test:   (Running for: " + testDurationFormatted + "): " + currentTest);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (MalformedObjectNameException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        } finally {
            try {
                jmxc.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return true;
}

From source file:marytts.tools.install.LicenseRegistry.java

/**
 * For the license identified by the given URL, return the URL of a local file providing the same content as the given URL. If
 * the license has not been downloaded yet, it will be now.
 * //from   w  ww  .  j av a  2 s.  c  om
 * @param licenseURL
 *            the remote URL of the license, serving as the license's identifier.
 * @return the URL of a local file from which the license text can be read even if there is no internet connection.
 */
public static URL getLicense(URL licenseURL) {
    long startT = System.currentTimeMillis();
    if (remote2local == null) {
        loadLocalLicenses();
    }
    assert remote2local != null;
    if (!remote2local.containsKey(licenseURL)) {
        downloadLicense(licenseURL);
    }
    String localFilename = remote2local.get(licenseURL);
    File downloadDir = new File(System.getProperty("mary.downloadDir", "."));
    File localFile = new File(downloadDir, localFilename);
    try {
        URL localURL = localFile.toURI().toURL();
        System.out.println("Lookup took " + (System.currentTimeMillis() - startT) + " ms");
        return localURL;
    } catch (MalformedURLException e) {
        System.err.println("Cannot create URL from local file " + localFile.getAbsolutePath());
        e.printStackTrace();
    }
    return null;
}

From source file:mdretrieval.FileFetcher.java

public static InputStream fetchFileFromUrl(String urlString) {

    InputStream inputStream = null;

    Proxy proxy = ServerConstants.isProxyEnabled
            ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ServerConstants.hostname, ServerConstants.port))
            : Proxy.NO_PROXY;/* w ww.  java 2 s.co m*/

    URL url;
    try {
        url = new URL(urlString);
        url.openConnection();

        if (proxy != Proxy.NO_PROXY && proxy.type() != Proxy.Type.DIRECT) {
            inputStream = url.openConnection(proxy).getInputStream();
        } else {
            inputStream = url.openConnection().getInputStream();
        }
    } catch (MalformedURLException e) {
        GUIrefs.displayAlert("Invalid URL " + urlString + "- \\n malformed expression");
        e.printStackTrace();
        inputStream = null;
    } catch (IOException ioe) {
        GUIrefs.displayAlert("Cannot read from " + StringUtilities.escapeQuotes(urlString) + "- IOException");
        ioe.printStackTrace();
        inputStream = null;
    }

    return inputStream;
}

From source file:com.mycompany.craftdemo.utility.java

public static JSONObject getAPIData(String apiURL) {
    try {//from w  ww.ja  v a  2 s .com
        URL url = new URL(apiURL);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
        StringBuilder sb = new StringBuilder();
        String output;
        while ((output = br.readLine()) != null)
            sb.append(output);

        String res = sb.toString();
        JSONParser parser = new JSONParser();
        JSONObject json = null;
        try {
            json = (JSONObject) parser.parse(res);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        //resturn api data in json format
        return json;

    } catch (MalformedURLException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    }
    return null;
}