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:org.dlut.mycloudserver.service.performancemonitor.PerformanceListener.java

public static void main(String[] args) {
    long t1 = System.currentTimeMillis();

    String url = "http://127.0.0.1:8001";
    URLConnection conn;//w w  w .jav  a2 s. c o  m
    try {
        conn = new URL(url).openConnection();
        conn.setConnectTimeout(1000);
        conn.setReadTimeout(1000);
        InputStream is = conn.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String res = br.readLine();
        br.close();
        is.close();
        JSONObject jsonRes = JSON.parseObject(res);
        double loadAverage = jsonRes.getDoubleValue("loadAverage");
        System.out.println(loadAverage);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    long t2 = System.currentTimeMillis();

    System.out.println((t2 - t1) + "ms");
}

From source file:jp.mamesoft.mailsocketchat.Mailsocketchat.java

public static void main(String argv[]) {
    System.out.println("MailSocketChat Ver." + version);
    if (argv.length != 6) {
        System.out.println(//from   www  .  j a va  2s . c  o m
                "ERROR! ? <?URL> <???> <GMail??> <GMail> <(Simple???Normal???All)> <????(Subject???Text)> ???????");
        System.exit(0);
    }

    TimerTask newversion = new NewVersion();
    Timer timer = new Timer();
    timer.schedule(newversion, 0, 6 * 60 * 60 * 1000); //6??????

    chat_url = argv[0];
    chat_name = argv[1];
    mail_user = argv[2];
    mail_pass = argv[3];

    if (argv[4].equals("Simple")) {
        logformat = "simple";
    } else if (argv[4].equals("Normal")) {
        logformat = "normal";
    } else if (argv[4].equals("All")) {
        logformat = "all";
    } else {
        System.out.println(
                "ERROR! (5)???????Simple???Normal???All???????");
        System.exit(0);
    }

    if (argv[5].equals("Subject")) {
        subjectname = true;
    } else if (argv[5].equals("Text")) {
        subjectname = false;
    } else {
        System.out.println(
                "ERROR! ????(6)???????Subject???Text???????");
        System.exit(0);
    }

    try {
        Properties headers = new Properties();
        headers.setProperty("user-agent", "MailSocketChat/" + version + " (" + osName + " " + osVer + ") Java/"
                + javaver + " (Mamesoft Web)");
        socket = new SocketIO(chat_url, headers);
        socket.connect(new IOCallback() {
            @Override
            public void onMessage(JSONObject json, IOAcknowledge ack) {
                try {
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onMessage(String data, IOAcknowledge ack) {
            }

            @Override
            public void onError(SocketIOException socketIOException) {
                System.out.println("??????");
                System.err.println(socketIOException);
                System.exit(0);
            }

            @Override
            public void onDisconnect() {
                System.out.println("???????");
                System.exit(0);
            }

            @Override
            public void onConnect() {
                socket.emit("register", new JSONObject().put("mode", "client").put("lastid", 1));
                System.out.println("SocketChat?????");
                Thread mail = new Mail();
                mail.start();
            }

            @Override
            public void on(String event, IOAcknowledge ack, Object... args) {
                if (event.equals("log")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    Logperse(jsondata);
                }
                if (event.equals("init")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    JSONArray logs = jsondata.getJSONArray("logs");
                    for (int i = logs.length() - 1; i >= 0; i--) {
                        JSONObject log = logs.getJSONObject(i);
                        Logperse(log);
                    }
                    socket.emit("inout", new JSONObject().put("name", chat_name));
                }
                if (event.equals("result")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    System.out.println(jsondata);
                }
                if (event.equals("users")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    JSONArray users = jsondata.getJSONArray("users");
                    for (int i = 0; i < users.length(); i++) {
                        JSONObject user = users.getJSONObject(i);
                        userchange(user);
                    }
                }
                if (event.equals("newuser")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    userchange(jsondata);
                }
                if (event.equals("inout")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    userchange(jsondata);
                }
                if (event.equals("deluser")) {
                    Integer id = (Integer) args[0];
                    if (users.containsKey(id)) {
                        users.remove(id);
                    }
                    if (roms.containsKey(id)) {
                        roms.remove(id);
                    }

                }
                if (event.equals("userinfo")) {
                    JSONObject jsondata = (JSONObject) args[0];
                    if (jsondata.getBoolean("rom")) {
                        in = false;
                    } else {
                        in = true;
                    }
                }
            }
        });

    } catch (MalformedURLException e1) {
        e1.printStackTrace();
        System.out.println("URL????????");
        return;
    }
}

From source file:ImageBouncer.java

public static void main(String[] args) {
    String filename = "java2sLogo.png";
    if (args.length > 0)
        filename = args[0];//  w ww  .  j  a  v a  2  s .  c  o  m

    Image image = null;
    try {
        image = blockingLoad(new URL(filename));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    final ImageBouncer bouncer = new ImageBouncer(image);
    Frame f = new AnimationFrame(bouncer);
    f.setFont(new Font("Serif", Font.PLAIN, 12));
    Panel controls = new Panel();
    controls.add(bouncer.createCheckbox("Bilinear", ImageBouncer.BILINEAR));
    controls.add(bouncer.createCheckbox("Transform", ImageBouncer.TRANSFORM));
    final Choice typeChoice = new Choice();
    typeChoice.add("TYPE_INT_RGB");
    typeChoice.add("TYPE_INT_ARGB");
    typeChoice.add("TYPE_INT_ARGB_PRE");
    typeChoice.add("TYPE_3BYTE_BGR");
    typeChoice.add("TYPE_BYTE_GRAY");
    typeChoice.add("TYPE_USHORT_GRAY");
    typeChoice.add("TYPE_USHORT_555_RGB");
    typeChoice.add("TYPE_USHORT_565_RGB");
    controls.add(typeChoice);
    f.add(controls, BorderLayout.NORTH);

    typeChoice.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ie) {
            String type = typeChoice.getSelectedItem();
            bouncer.setImageType(type);
        }
    });
    f.setSize(200, 200);
    f.setVisible(true);
}

From source file:com.icloud.framework.http.URLUtil.java

/** For testing */
public static void main(String[] args) {

    if (args.length != 1) {
        System.err.println("Usage : URLUtil <url>");
        return;/*from w w  w . java  2 s .co  m*/
    }

    String url = args[0];
    try {
        System.out.println(URLUtil.getDomainName(new URL(url)));
    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    }
}

From source file:is.idega.idegaweb.egov.gumbo.bpm.violation.ViolationDataProviderRealWebservice.java

public static void main(String[] arguments) {
    try {/*from   ww  w  .  ja  va 2  s  .  co m*/
        FSWebserviceBROTAMAL_Service locator = new FSWebserviceBROTAMAL_ServiceLocator();
        FSWebserviceBROTAMAL_PortType port = locator.getFSWebserviceBROTAMALSoap12HttpPort(
                new URL(GumboConstants.WEB_SERVICE_URL + "FSWebserviceBROTAMALSoap12HttpPort"));

        StringBuilder ret = new StringBuilder();
        GetVigtunarleyfiByKtElement parameters = new GetVigtunarleyfiByKtElement("5411850389");
        VigtunarleyfiTypeUser res[] = port.getVigtunarleyfiByKt(parameters);
        int len = res.length;
        for (int i = 0; i < len; i++) {
            ret.append(res[i].getHeitiLeyfis());
            if (i < (len - 1)) {
                ret.append(", ");
            }
        }

    } catch (ServiceException se) {
        se.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.okta.tools.awscli.java

public static void main(String[] args) throws Exception {
    awsSetup();//from  w w w.  java2 s.  co m
    extractCredentials();

    // Step #1: Initiate the authentication and capture the SAML assertion.
    CloseableHttpClient httpClient = null;
    String resultSAML = "";
    try {

        String strOktaSessionToken = oktaAuthntication();
        if (!strOktaSessionToken.equalsIgnoreCase(""))
            //Step #2 get SAML assertion from Okta
            resultSAML = awsSamlHandler(strOktaSessionToken);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (UnknownHostException e) {
        logger.error(
                "\nUnable to establish a connection with AWS. \nPlease verify that your OKTA_AWS_APP_URL parameter is correct and try again");
        System.exit(0);
    } catch (ClientProtocolException e) {
        logger.error("\nNo Org found, please specify an OKTA_ORG parameter in your config.properties file");
        System.exit(0);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Step #3: Assume an AWS role using the SAML Assertion from Okta
    AssumeRoleWithSAMLResult assumeResult = assumeAWSRole(resultSAML);

    com.amazonaws.services.securitytoken.model.AssumedRoleUser aru = assumeResult.getAssumedRoleUser();
    String arn = aru.getArn();

    // Step #4: Get the final role to assume and update the config file to add it to the user's profile
    GetRoleToAssume(crossAccountRoleName);
    logger.trace("Role to assume ARN: " + roleToAssume);

    // Step #5: Write the credentials to ~/.aws/credentials
    String profileName = setAWSCredentials(assumeResult, arn);

    UpdateConfigFile(profileName, roleToAssume);
    UpdateConfigFile(DefaultProfileName, roleToAssume);

    // Print Final message
    resultMessage(profileName);
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

public static void main(final String[] args) {
    final String[][] test = new String[][] { new String[] { null, "file://y:/" },
            new String[] { null, "file://y:/yacy" }, new String[] { null, "file://y:/yacy/" },
            new String[] { null, "file://y:" }, new String[] { null, "file://Z:admin\\home" }, // thats wrong but may appear
            new String[] { null, "file://Z:\\admin\\home" },
            new String[] { null, "https://www.example.com/shoe/?p=2&ps=75#t={%22san_NaviPaging%22:2}" }, // ugly strange pagination link
            new String[] { null, "C:WINDOWS\\CMD0.EXE" }, new String[] { null, "file://C:WINDOWS\\CMD0.EXE" },
            new String[] { null, "file:///bin/yacy2" }, // file://<host>/<path> may have many '/' if the host is omitted and the path starts with '/'
            new String[] { null, "file:/bin/yacy1" }, // file://<host>/<path> may have many '/' if the host is omitted and the path starts with '/'
            new String[] { null, "file:C:WINDOWS\\CMD.EXE" },
            new String[] { null, "file:///C:WINDOWS\\CMD1.EXE" },
            new String[] { null, "file:///C|WINDOWS\\CMD2.EXE" },
            new String[] { null, "http://www.anomic.de/test/" }, new String[] { null, "http://www.anomic.de/" },
            new String[] { null, "http://www.anomic.de" },
            new String[] { null, "http://www.anomic.de/home/test?x=1#home" },
            new String[] { null, "http://www.anomic.de/home/test?x=1" },
            new String[] { null, "http://www.anomic.de/home/test#home" },
            new String[] { null, "ftp://ftp.anomic.de/home/test#home" },
            new String[] { null, "ftp://bob:builder@ftp.anomic.de/home/test.gif" },
            new String[] { null, "http://www.anomic.de/home/../abc/" },
            new String[] { null, "mailto:abcdefg@nomailnomail.com" },
            new String[] { "http://www.anomic.de/home", "test" },
            new String[] { "http://www.anomic.de/home", "test/" },
            new String[] { "http://www.anomic.de/home/", "test" },
            new String[] { "http://www.anomic.de/home/", "test/" },
            new String[] { "http://www.anomic.de/home/index.html", "test.htm" },
            new String[] { "http://www.anomic.de/home/index.html", "http://www.yacy.net/test" },
            new String[] { "http://www.anomic.de/home/index.html", "ftp://ftp.yacy.net/test" },
            new String[] { "http://www.anomic.de/home/index.html", "../test" },
            new String[] { "http://www.anomic.de/home/index.html", "mailto:abcdefg@nomailnomail.com" },
            new String[] { null, "news:de.test" }, new String[] { "http://www.anomic.de/home", "news:de.test" },
            new String[] { null, "mailto:bob@web.com" },
            new String[] { "http://www.anomic.de/home", "mailto:bob@web.com" },
            new String[] { "http://www.anomic.de/home", "ftp://ftp.anomic.de/src" },
            new String[] { null, "ftp://ftp.delegate.org/" },
            new String[] { "http://www.anomic.de/home", "ftp://ftp.delegate.org/" },
            new String[] { "http://www.anomic.de", "mailto:yacy@weltherrschaft.org" },
            new String[] { "http://www.anomic.de", "javascipt:temp" },
            new String[] { null,
                    "http://yacy-websuche.de/wiki/index.php?title=De:IntroInformationFreedom&action=history" },
            new String[] { null,
                    "http://diskusjion.no/index.php?s=5bad5f431a106d9a8355429b81bb0ca5&showuser=23585" },
            new String[] { null,
                    "http://diskusjion.no/index.php?s=5bad5f431a106d9a8355429b81bb0ca5&amp;showuser=23585" },
            new String[] { null,
                    "http://www.scc.kit.edu/publikationen/80.php?PHPSESSID=5f3624d3e1c33d4c086ab600d4d5f5a1" },
            new String[] { null, "smb://localhost/" }, new String[] { null, "smb://localhost/repository" }, // paths must end with '/'
            new String[] { null, "smb://localhost/repository/" }, new String[] { null, "\\\\localhost\\" }, // Windows-like notion of smb shares
            new String[] { null, "\\\\localhost\\repository" },
            new String[] { null, "\\\\localhost\\repository\\" },
            new String[] { null, "http://test.net/test1.htm?s=multiple&amp;a=amp&amp;b=in&amp;c=url" },
            new String[] { null, "http://test.net/test2.htm?s=multiple&amp;amp;amp;amp;a=amp" },
            new String[] { null, "http://validator.w3.org/check?uri=http://www.anomic.de/" } };
    //MultiProtocolURI.initSessionIDNames(FileUtils.loadList(new File("defaults/sessionid.names")));
    String environment, url;//from  www .j  av  a 2s  .com
    MultiProtocolURL aURL, aURL1;
    java.net.URL jURL;
    for (String[] element : test) {
        environment = element[0];
        url = element[1];
        try {
            aURL = MultiProtocolURL.newURL(environment, url);
        } catch (final MalformedURLException e) {
            e.printStackTrace();
            aURL = null;
        }
        if (environment == null) {
            try {
                jURL = new java.net.URL(url);
            } catch (final MalformedURLException e) {
                jURL = null;
            }
        } else {
            try {
                jURL = new java.net.URL(new java.net.URL(environment), url);
            } catch (final MalformedURLException e) {
                jURL = null;
            }
        }

        // check equality to java.net.URL
        if (((aURL == null) && (jURL != null)) || ((aURL != null) && (jURL == null)) || ((aURL != null)
                && (jURL != null) && (!(jURL.toString().equals(aURL.toNormalform(false)))))) {
            System.out.println("Difference for environment=" + environment + ", url=" + url + ":");
            System.out.println((jURL == null) ? "jURL rejected input" : "jURL=" + jURL.toString());
            System.out.println((aURL == null) ? "aURL rejected input"
                    : "aURL=" + aURL.toNormalform(false) + "; host=" + aURL.getHost() + "; path="
                            + aURL.getPath() + "; file=" + aURL.getFile());
        }

        if (aURL != null && jURL != null && jURL.toString().equals(aURL.toNormalform(false))) {
            System.out.println("jURL == aURL=" + aURL.toNormalform(false) + "; host=" + aURL.getHost()
                    + "; path=" + aURL.getPath() + "; file=" + aURL.getFile());
        }

        // check stability: the normalform of the normalform must be equal to the normalform
        if (aURL != null)
            try {
                aURL1 = new MultiProtocolURL(aURL.toNormalform(false));
                if (!(aURL1.toNormalform(false).equals(aURL.toNormalform(false)))) {
                    System.out.println("no stability for url:");
                    System.out.println("aURL0=" + aURL.toNormalform(false));
                    System.out.println("aURL1=" + aURL1.toNormalform(false));
                }
            } catch (final MalformedURLException e) {
                System.out.println("no stability for url:");
                System.out.println("aURL0=" + aURL.toNormalform(false));
                System.out.println("aURL1 cannot be computed:" + e.getMessage());
            }
    }
}

From source file:edu.toronto.cs.xcurator.cli.CLIRunner.java

public static void main(String[] args) {
    Options options = setupOptions();//from  w  w  w  . j a v a  2s. c o m
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption('t')) {
            fileType = line.getOptionValue('t');
        } else {
            fileType = XML;
        }
        if (line.hasOption('o')) {
            tdbDirectory = line.getOptionValue('o');
            File d = new File(tdbDirectory);
            if (!d.exists() || !d.isDirectory()) {
                throw new Exception("TDB directory does not exist, please create.");
            }
        }
        if (line.hasOption('h')) {
            domain = line.getOptionValue('h');
            try {
                URL url = new URL(domain);
            } catch (MalformedURLException ex) {
                throw new Exception("The domain name is ill-formed");
            }
        } else {
            printHelpAndExit(options);
        }
        if (line.hasOption('m')) {
            serializeMapping = true;
            mappingFilename = line.getOptionValue('m');
        }
        if (line.hasOption('d')) {
            dirLocation = line.getOptionValue('d');
            inputStreams = new ArrayList<>();
            final List<String> files = Util.getFiles(dirLocation);
            for (String inputfile : files) {
                File f = new File(inputfile);
                if (f.isFile() && f.exists()) {
                    System.out.println("Adding document to mapping discoverer: " + inputfile);
                    inputStreams.add(new FileInputStream(f));
                } // If it is a URL download link for the document from SEC
                else if (inputfile.startsWith("http") && inputfile.contains("://")) {
                    // Download
                    System.out.println("Adding remote document to mapping discoverer: " + inputfile);
                    try {
                        URL url = new URL(inputfile);
                        InputStream remoteDocumentStream = url.openStream();
                        inputStreams.add(remoteDocumentStream);
                    } catch (MalformedURLException ex) {
                        throw new Exception("The document URL is ill-formed: " + inputfile);
                    } catch (IOException ex) {
                        throw new Exception("Error in downloading remote document: " + inputfile);
                    }
                } else {
                    throw new Exception("Cannot open XBRL document: " + f.getName());
                }
            }
        }

        if (line.hasOption('f')) {
            fileLocation = line.getOptionValue('f');
            inputStreams = new ArrayList<>();
            File f = new File(fileLocation);
            if (f.isFile() && f.exists()) {
                System.out.println("Adding document to mapping discoverer: " + fileLocation);
                inputStreams.add(new FileInputStream(f));
            } // If it is a URL download link for the document from SEC
            else if (fileLocation.startsWith("http") && fileLocation.contains("://")) {
                // Download
                System.out.println("Adding remote document to mapping discoverer: " + fileLocation);
                try {
                    URL url = new URL(fileLocation);
                    InputStream remoteDocumentStream = url.openStream();
                    inputStreams.add(remoteDocumentStream);
                } catch (MalformedURLException ex) {
                    throw new Exception("The document URL is ill-formed: " + fileLocation);
                } catch (IOException ex) {
                    throw new Exception("Error in downloading remote document: " + fileLocation);
                }
            } else {

                throw new Exception("Cannot open XBRL document: " + f.getName());
            }

        }

        setupDocumentBuilder();
        RdfFactory rdfFactory = new RdfFactory(new RunConfig(domain));
        List<Document> documents = new ArrayList<>();
        for (InputStream inputStream : inputStreams) {
            Document dataDocument = null;
            if (fileType.equals(JSON)) {
                String json = IOUtils.toString(inputStream);
                final String xml = Util.json2xml(json);
                final InputStream xmlInputStream = IOUtils.toInputStream(xml);
                dataDocument = createDocument(xmlInputStream);
            } else {
                dataDocument = createDocument(inputStream);
            }
            documents.add(dataDocument);
        }
        if (serializeMapping) {
            System.out.println("Mapping file will be saved to: " + new File(mappingFilename).getAbsolutePath());
            rdfFactory.createRdfs(documents, tdbDirectory, mappingFilename);
        } else {
            rdfFactory.createRdfs(documents, tdbDirectory);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("Unexpected exception: " + ex.getMessage());
        System.exit(1);
    }
}

From source file:Main.java

public static String getNoQueryUrl(String source) {
    String dest = null;//from  w w  w .j  av a  2  s. c o  m
    try {
        URL sUrl = new URL(source);
        URL dUrl = new URL(sUrl.getProtocol(), sUrl.getHost(), sUrl.getPort(), sUrl.getPath());
        dest = dUrl.toString();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return dest;
}

From source file:Main.java

/**
 * Return the base URL from the given URL.  Example:
 * http://foo.org/abc.html -> http://foo.org/
 * @param surl/* ww w . j  av  a2  s  . c  om*/
 * @return The base URL.
 */
public static String getBaseUrl(String surl) {
    URL url;
    try {
        url = new URL(surl);
        System.out.println("getHost: " + url.getHost());
        return "http://" + url.getHost() + "/";
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return null;
}