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.utils.bugzilla.BugzillaClientImpl.java

/**
 * Set up the configuration/*from ww  w. j  a  v a 2 s. com*/
 */
private XmlRpcClient initializeClient() {

    assert this.url != null : "This would cause a NullPointerException below.";

    // Get the RPC client set up and ready to go
    // The alternate TransportFactory stuff is required so that cookies
    // work and the logins behave persistently
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    try {
        config.setServerURL(new URL(this.url));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    // config.setEnabledForExtensions(true);
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);
    XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(client);

    HttpClient httpClient = proxyService == null ? new HttpClient()
            : proxyService.getClientWithProxyConfig(BugzillaDefectTracker.class);
    factory.setHttpClient(httpClient);

    client.setTransportFactory(factory);

    return client;
}

From source file:com.risevision.ui.server.utils.MakeRequestServlet.java

public RequestResponse makeRequest(HttpServletRequest request) throws Exception {
    RequestResponse response = new RequestResponse();

    String requestUrl = request.getParameter("url");
    if ((requestUrl != null) && (!requestUrl.isEmpty())) {
        try {/*from   w  w w  .j a  v a 2  s.co m*/
            URL payload_url = new URL(requestUrl.replace(" ", "+"));

            HttpURLConnection urlConnection = (HttpURLConnection) payload_url.openConnection();

            urlConnection.setReadTimeout(20000);
            urlConnection.setRequestMethod("GET");

            //            if ("oauth".equals(request.getParameter("authz")) && requestUrl.contains("api.twitter.com/1.1")) {
            //               signTwitterRequest(request, urlConnection);
            //            }

            response.responseBody = getResponseAsJson(urlConnection);
            response.responseCode = urlConnection.getResponseCode();

        } catch (MalformedURLException e) {
            e.printStackTrace();
            throw new Exception("Malformed URL, " + e.getMessage());
        } catch (Exception e) {
            //            e.printStackTrace();
            log.log(Level.SEVERE, e.getMessage(), e);
            //              log.severe("Exception - " + e.getMessage(), e);
        }
    }
    return response;
}

From source file:com.teozcommunity.teozfrank.duelme.util.UpdateChecker.java

/**
 * Query the API to find the latest approved file's details.
 *//*from w  ww  . j  av  a 2s. c  om*/
public void query() {
    URL url = null;

    try {
        // Create the URL to query using the project's ID
        url = new URL(API_HOST + API_QUERY + projectID);
    } catch (MalformedURLException e) {
        // There was an error creating the URL

        e.printStackTrace();
        return;
    }

    try {
        // Open a connection and query the project
        URLConnection conn = url.openConnection();

        // Add the user-agent to identify the program
        conn.addRequestProperty("User-Agent", "ServerModsAPI-Example (by Gravity)");

        // Read the response of the query
        // The response will be in a JSON format, so only reading one line is necessary.
        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String response = reader.readLine();

        // Parse the array of files from the query's response
        JSONArray array = (JSONArray) JSONValue.parse(response);

        if (array.size() > 0) {
            // Get the newest file's details
            JSONObject latest = (JSONObject) array.get(array.size() - 1);

            // Get the version's title
            String versionName = (String) latest.get(API_NAME_VALUE);

            // Get the version's link
            String versionLink = (String) latest.get(API_LINK_VALUE);

            // Get the version's release type
            String versionType = (String) latest.get(API_RELEASE_TYPE_VALUE);

            // Get the version's file name
            String versionFileName = (String) latest.get(API_FILE_NAME_VALUE);

            // Get the version's game version
            String versionGameVersion = (String) latest.get(API_GAME_VERSION_VALUE);

            versionName = versionName.replaceAll("[a-zA-Z]", "");
            versionName = versionName.replaceAll(" ", "");

            String pluginVersion = plugin.getDescription().getVersion();

            pluginVersion = pluginVersion.replaceAll("Alpha", "");
            pluginVersion = pluginVersion.replaceAll("Beta", "");
            pluginVersion = pluginVersion.replaceAll("Release", "");
            pluginVersion = pluginVersion.replaceAll(" ", "");

            if (!versionName.equals(pluginVersion)) {
                this.updateAvailable = true;
                SendConsoleMessage.info("There is a new update available!");
                SendConsoleMessage.info("download it on bukkit dev " + ChatColor.YELLOW
                        + "http://dev.bukkit.org/bukkit-plugins/duelme/");
            } else {
                this.updateAvailable = false;
                SendConsoleMessage.info("plugin is up to date!");
            }

        } else {
            System.out.println("There are no files for this project");
        }
    } catch (IOException e) {
        // There was an error reading the query
        SendConsoleMessage.severe("There was an error checking for updates!");
        return;
    }
}

From source file:com.brightcove.zartan.encode.TencodeAPI.java

@Override
public Verifiable submitTranscode(TranscodeInfo transcode, TranscodeEnvironment env, Account acc) {
    VerifiableTranscode toVerify = new VerifiableTranscode(transcode, env, acc,
            TranscodeEntryPointEnum.TENCODE_API);
    toVerify.setTranscodeTime(System.currentTimeMillis());

    // TODO:throw if env has a bad url
    URI targetURL = null;/*w  ww  .  j a  v a2 s.co m*/
    try {
        targetURL = new URL(env.getTranscodeApiUrl()).toURI();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    JsonNode response = encodeFile(transcode, targetURL, toVerify);

    return toVerify;
}

From source file:fr.seeks.SuggestionProvider.java

public void setCursorOfQuery(Uri uri, String query, MatrixCursor matrix) {
    try {/*from w w w .  ja  va 2  s.co  m*/
        setCursorOfQueryThrow(uri, query, matrix);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:eu.udig.catalog.jgrass.core.JGTtmsGeoResource.java

public URL getIdentifier() {
    String urlString = URLUtils.urlToString(url, false);
    try {/*from  w  ww . ja va  2 s.c o  m*/
        return new URL(urlString + "#/" + getTitle());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.web.server.XMLDeploymentScanner.java

public XMLDeploymentScanner(String scanDirectory, String userLibDir) {
    super(scanDirectory);
    this.userLibDir = userLibDir;
    File userLibJars = new File(userLibDir);
    CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList();
    getUsersJars(userLibJars, jarList);/*ww w .j a  va  2 s. c om*/
    URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    userLibJarLoader = new WebClassLoader(loader.getURLs());
    for (String jarFilePath : jarList) {
        try {
            userLibJarLoader.addURL(new URL("file:/" + jarFilePath.replace("\\", "/")));
        } catch (MalformedURLException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
    }

    DigesterLoader xmlDigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {
            // TODO Auto-generated method stub
            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/datasource-rules.xml")));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    xmlDigester = xmlDigesterLoader.newDigester();
    try {
        ic = new InitialContext();
        ic.createSubcontext("java:");
    } catch (NamingException e1) {
        // TODO Auto-generated catch block
    }

    File[] xmlFiles = new File(scanDirectory).listFiles();

    if (xmlFiles != null && xmlFiles.length > 0) {
        for (File xmlFile : xmlFiles) {
            if (xmlFile.getName().toLowerCase().endsWith("datasource.xml")) {
                installDataSource(xmlFile);
            }
        }
    }

    // TODO Auto-generated constructor stub
}

From source file:net.sourceforge.ganttproject.client.RssFeedChecker.java

private Runnable createRssReadCommand() {
    return new Runnable() {
        @Override// www .j  av a  2s. c om
        public void run() {
            GPLogger.log("Starting RSS check...");
            HttpClient httpClient = new DefaultHttpClient();
            String url = RSS_URL;
            try {
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
                    HttpGet getRssUrl = new HttpGet(url);
                    getRssUrl.addHeader("User-Agent", "GanttProject " + GPVersion.CURRENT);
                    HttpResponse result = httpClient.execute(getRssUrl);

                    switch (result.getStatusLine().getStatusCode()) {
                    case HttpStatus.SC_OK:
                        processResponse(result.getEntity().getContent());
                        return;
                    }
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                httpClient.getConnectionManager().shutdown();
                GPLogger.log("RSS check finished");
            }
        }

        private void processResponse(InputStream responseStream) {
            RssFeed feed = parser.parse(responseStream, myLastCheckOption.getValue());
            List<NotificationItem> items = new ArrayList<NotificationItem>();
            for (RssFeed.Item item : feed.getItems()) {
                items.add(new NotificationItem(item.title, item.body,
                        NotificationManager.DEFAULT_HYPERLINK_LISTENER));
            }
            Collections.reverse(items);
            if (!items.isEmpty()) {
                getNotificationManager().addNotifications(NotificationChannel.RSS, items);
            }
            markLastCheck();
        }
    };
}

From source file:de.matzefratze123.heavyspleef.util.Updater.java

public void query() {
    URL url;/*from www . j ava 2 s  .  com*/

    try {
        url = new URL(API_HOST + API_QUERY + PROJECT_ID);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return;
    }

    try {
        URLConnection conn = url.openConnection();

        conn.setConnectTimeout(6000);
        conn.addRequestProperty("User-Agent", "HeavySpleef-Updater (by matzefratze123)");

        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String query = reader.readLine();

        JSONArray array = (JSONArray) JSONValue.parse(query);

        String version = null;

        if (array.size() > 0) {

            // Get the newest file's details
            JSONObject latest = (JSONObject) array.get(array.size() - 1);

            fileTitle = (String) latest.get(API_TITLE_VALUE);
            fileName = (String) latest.get(API_NAME_VALUE);
            downloadUrl = (String) latest.get(API_LINK_VALUE);

            String[] parts = fileTitle.split(" v");
            if (parts.length >= 2) {
                version = parts[1];
            }

            checkVersions(version);
            done = true;
        }
    } catch (IOException e) {
        Logger.severe("Failed querying the curseforge api: " + e.getMessage());
        e.printStackTrace();
    }

}

From source file:FormatTest.java

public FormatTestFrame() {
    setTitle("FormatTest");
    setSize(WIDTH, HEIGHT);//from   w  ww .j  ava  2 s.co  m

    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JFormattedTextField intField = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField.setValue(new Integer(100));
    addRow("Number:", intField);

    JFormattedTextField intField2 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField2.setValue(new Integer(100));
    intField2.setFocusLostBehavior(JFormattedTextField.COMMIT);
    addRow("Number (Commit behavior):", intField2);

    JFormattedTextField intField3 = new JFormattedTextField(
            new InternationalFormatter(NumberFormat.getIntegerInstance()) {
                protected DocumentFilter getDocumentFilter() {
                    return filter;
                }

                private DocumentFilter filter = new IntFilter();
            });
    intField3.setValue(new Integer(100));
    addRow("Filtered Number", intField3);

    JFormattedTextField intField4 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField4.setValue(new Integer(100));
    intField4.setInputVerifier(new FormattedTextFieldVerifier());
    addRow("Verified Number:", intField4);

    JFormattedTextField currencyField = new JFormattedTextField(NumberFormat.getCurrencyInstance());
    currencyField.setValue(new Double(10));
    addRow("Currency:", currencyField);

    JFormattedTextField dateField = new JFormattedTextField(DateFormat.getDateInstance());
    dateField.setValue(new Date());
    addRow("Date (default):", dateField);

    DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
    format.setLenient(false);
    JFormattedTextField dateField2 = new JFormattedTextField(format);
    dateField2.setValue(new Date());
    addRow("Date (short, not lenient):", dateField2);

    try {
        DefaultFormatter formatter = new DefaultFormatter();
        formatter.setOverwriteMode(false);
        JFormattedTextField urlField = new JFormattedTextField(formatter);
        urlField.setValue(new URL("http://java.sun.com"));
        addRow("URL:", urlField);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    try {
        MaskFormatter formatter = new MaskFormatter("###-##-####");
        formatter.setPlaceholderCharacter('0');
        JFormattedTextField ssnField = new JFormattedTextField(formatter);
        ssnField.setValue("078-05-1120");
        addRow("SSN Mask:", ssnField);
    } catch (ParseException exception) {
        exception.printStackTrace();
    }

    JFormattedTextField ipField = new JFormattedTextField(new IPAddressFormatter());
    ipField.setValue(new byte[] { (byte) 130, 65, 86, 66 });
    addRow("IP Address:", ipField);
}