Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.app.server.util.ClassLoaderUtil.java

public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) {
    CopyOnWriteArrayList jars = new CopyOnWriteArrayList();
    boolean res = false;
    Class classURLClassLoader = null;
    if (cl instanceof URLClassLoader) {
        classURLClassLoader = URLClassLoader.class;
        if (cl instanceof WebClassLoader) {
            String url = "";
            CopyOnWriteArrayList webCLUrl = ((WebClassLoader) cl).geturlS();
            for (int index = 0; index < webCLUrl.size(); index++) {

                try {
                    url = ((URL) webCLUrl.get(index)).toURI().toString();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }//from ww  w .ja  va 2  s.  c om
                jars.add(url.replace("file:", "").replace("/", "\\").toUpperCase());
            }
        }
    } else if (cl instanceof VFSClassLoader) {
        classURLClassLoader = VFSClassLoader.class;
    }
    Field f = null;
    try {
        f = classURLClassLoader.getDeclaredField("ucp");
        //log.info(f);
    } catch (NoSuchFieldException e1) {
        // e1.printStackTrace();
        // log.info(e1.getMessage(), e1);

    }
    if (f != null) {
        f.setAccessible(true);
        Object obj = null;
        try {
            obj = f.get(cl);
        } catch (IllegalAccessException e1) {
            // e1.printStackTrace();
            // log.info(e1.getMessage(), e1);
        }
        if (obj != null) {
            final Object ucp = obj;
            f = null;
            try {
                f = ucp.getClass().getDeclaredField("loaders");
                //log.info(f);
            } catch (NoSuchFieldException e1) {
                // e1.printStackTrace();
                // log.info(e1.getMessage(), e1);
            }
            if (f != null) {
                f.setAccessible(true);
                ArrayList loaders = null;
                try {
                    loaders = (ArrayList) f.get(ucp);
                    res = true;
                } catch (IllegalAccessException e1) {
                    // e1.printStackTrace();
                }
                for (int i = 0; loaders != null && i < loaders.size(); i++) {
                    obj = loaders.get(i);
                    f = null;
                    try {
                        f = obj.getClass().getDeclaredField("jar");
                        // log.info(f);
                    } catch (NoSuchFieldException e) {
                        // e.printStackTrace();
                        // log.info(e.getMessage(), e);
                    }
                    if (f != null) {
                        f.setAccessible(true);
                        try {
                            obj = f.get(obj);
                        } catch (IllegalAccessException e1) {
                            // e1.printStackTrace();
                            // log.info(e1.getMessage(), e1);
                        }
                        if (obj instanceof JarFile) {
                            final JarFile jarFile = (JarFile) obj;
                            //log.info(jarFile.getName());
                            jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase());
                            // try {
                            // jarFile.getManifest().clear();
                            // } catch (IOException e) {
                            // // ignore
                            // }
                            try {
                                jarFile.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                                // ignore
                                // log.info(e.getMessage(), e);
                            }
                        }
                    }
                }
            }
        }
    }
    return jars;
}

From source file:com.askfast.askfastapi.util.HttpUtil.java

/**
 * Returns the url without query parameters
 * //from  ww  w .  ja v a2s .  co m
 * @param url
 *            Url containing query parameters
 * @return url Url without query parameters
 * @throws IOException
 *             Errors in connecting to the given URL
 */
static public String removeQueryParams(String url) throws IOException {

    try {
        url = url.replace(" ", "%20");
        URIBuilder uriBuilder = new URIBuilder(new URI(url));
        return uriBuilder.removeQuery().toString();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.android.W3T.app.network.NetworkUtil.java

public static boolean attemptLogin(String uname, String pwd, int op) {
    // Here we may want to check the network status.
    checkNetwork();//  ww w .  j  a v  a  2s  .c  o m

    HttpClient Client = new DefaultHttpClient();
    HttpPost request;

    try {
        request = new HttpPost();
        if (op == LOGIN) {
            request.setURI(new URI(LOGIN_URL));
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
            nameValuePairs.add(new BasicNameValuePair("acc", uname));
            nameValuePairs.add(new BasicNameValuePair("pwd", pwd));
            nameValuePairs.add(new BasicNameValuePair("type", "user"));
            request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        } else if (op == LOGOUT) {
            request.setURI(new URI(LOGOUT_URL));
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
            nameValuePairs.add(new BasicNameValuePair("acc", uname));
            request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        }
        // Execute HTTP Post Request
        HttpResponse response = Client.execute(request);
        System.out.println(response.getStatusLine().getStatusCode());
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            if (op == LOGOUT) {
                return true;
            }
            String s = EntityUtils.toString(response.getEntity());

            if (s.equals("1")) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    } catch (URISyntaxException e) {
        e.printStackTrace();

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

From source file:com.cloud.consoleproxy.ConsoleProxy.java

private static void configLog4j() {
    URL configUrl = System.class.getResource("/conf/log4j-cloud.xml");
    if (configUrl == null)
        configUrl = ClassLoader.getSystemResource("log4j-cloud.xml");

    if (configUrl == null)
        configUrl = ClassLoader.getSystemResource("conf/log4j-cloud.xml");

    if (configUrl != null) {
        try {/* w w w . j av  a  2  s.  c o m*/
            System.out.println("Configure log4j using " + configUrl.toURI().toString());
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        }

        try {
            File file = new File(configUrl.toURI());

            System.out.println("Log4j configuration from : " + file.getAbsolutePath());
            DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000);
        } catch (URISyntaxException e) {
            System.out.println("Unable to convert log4j configuration Url to URI");
        }
        // DOMConfigurator.configure(configUrl);
    } else {
        System.out.println("Configure log4j with default properties");
    }
}

From source file:org.dvbviewer.controller.io.ServerRequest.java

/**
 * Gets the client auth scope.// w ww  . jav  a2 s  . c  om
 * 
 * @return the client auth scope
 * @author RayBa
 * @date 13.04.2012
 */
private static AuthScope getClientAuthScope() {
    if (clientAuthScope == null) {
        if (urlValidator.isValid(ServerConsts.DVBVIEWER_URL)) {
            URI uri;
            try {
                uri = new URI(ServerConsts.DVBVIEWER_URL);
                clientAuthScope = new AuthScope(uri.getHost(), uri.getPort());
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    return clientAuthScope;
}

From source file:org.dvbviewer.controller.io.ServerRequest.java

/**
 * Gets the Recording service auth scope.
 * /*from   w w  w.j a  va  2 s.c o m*/
 * @return the rs auth scope
 * @author RayBa
 * @date 13.04.2012
 */
private static AuthScope getRsAuthScope() {
    if (rsAuthScope == null) {
        if (urlValidator.isValid(ServerConsts.REC_SERVICE_URL)) {
            URI uri;
            try {
                uri = new URI(ServerConsts.REC_SERVICE_URL);
                rsAuthScope = new AuthScope(uri.getHost(), uri.getPort());
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    return rsAuthScope;
}

From source file:com.breadwallet.tools.security.RequestHandler.java

public static boolean tryBitIdUri(final Activity app, String uri, JSONObject jsonBody) {
    if (uri == null)
        return false;
    boolean isBitUri = false;

    URI bitIdUri = null;/*from w w  w  .  jav  a  2  s  . c o  m*/
    try {
        bitIdUri = new URI(uri);
        if ("bitid".equals(bitIdUri.getScheme()))
            isBitUri = true;
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    _bitUri = uri;

    if (jsonBody != null) {
        try {
            _authString = jsonBody.getString("prompt_string");
            _bitCallback = jsonBody.getString("bitid_url");
            _index = jsonBody.getInt("bitid_index");
            _strToSign = jsonBody.getString("string_to_sign");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else if (bitIdUri != null && "bitid".equals(bitIdUri.getScheme())) {
        if (app == null) {
            Log.e(TAG, "tryBitIdUri: app is null, returning true still");
            return isBitUri;
        }

        //ask for phrase, will system auth if needed

        _authString = "BitID Authentication Request";
    }

    //        Log.e(TAG, "tryBitIdUri: _bitUri: " + _bitUri);
    //        Log.e(TAG, "tryBitIdUri: _strToSign: " + _strToSign);
    //        Log.e(TAG, "tryBitIdUri: _index: " + _index);

    new Thread(new Runnable() {
        @Override
        public void run() {
            byte[] phrase = null;
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Uri tmpUri = Uri.parse(_bitUri);
            try {
                phrase = KeyStoreManager.getKeyStorePhrase(app, REQUEST_PHRASE_BITID);
                ((BreadWalletApp) app.getApplicationContext()).promptForAuthentication(app, AUTH_FOR_BIT_ID,
                        null, tmpUri.getHost(), _authString, null, false);
            } catch (BRKeystoreErrorException e) {
                //asked the system, no need for local auth
                e.printStackTrace();
            } finally {
                //free the phrase
                if (phrase != null)
                    Arrays.fill(phrase, (byte) 0);
            }
        }
    }).start();
    return isBitUri;

}

From source file:org.darkware.wpman.wpcli.WPCLI.java

/**
 * Update the local WP-CLI tool to the most recent version.
 *//*from  w  w  w  . j a v a2  s . c om*/
public static void update() {
    try {
        WPManager.log.info("Downloading new version of WP-CLI.");

        CloseableHttpClient httpclient = HttpClients.createDefault();

        URI pharURI = new URIBuilder().setScheme("http").setHost("raw.githubusercontent.com")
                .setPath("/wp-cli/builds/gh-pages/phar/wp-cli.phar").build();

        WPManager.log.info("Downloading from: {}", pharURI);
        HttpGet downloadRequest = new HttpGet(pharURI);

        CloseableHttpResponse response = httpclient.execute(downloadRequest);

        WPManager.log.info("Download response: {}", response.getStatusLine());
        WPManager.log.info("Download content type: {}", response.getFirstHeader("Content-Type").getValue());

        FileChannel wpcliFile = FileChannel.open(WPCLI.toolPath, StandardOpenOption.CREATE,
                StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);

        response.getEntity().writeTo(Channels.newOutputStream(wpcliFile));
        wpcliFile.close();

        Set<PosixFilePermission> wpcliPerms = new HashSet<>();
        wpcliPerms.add(PosixFilePermission.OWNER_READ);
        wpcliPerms.add(PosixFilePermission.OWNER_WRITE);
        wpcliPerms.add(PosixFilePermission.OWNER_EXECUTE);
        wpcliPerms.add(PosixFilePermission.GROUP_READ);
        wpcliPerms.add(PosixFilePermission.GROUP_EXECUTE);

        Files.setPosixFilePermissions(WPCLI.toolPath, wpcliPerms);
    } catch (URISyntaxException e) {
        WPManager.log.error("Failure building URL for WPCLI download.", e);
        System.exit(1);
    } catch (IOException e) {
        WPManager.log.error("Error while downloading WPCLI client.", e);
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:eu.planets_project.tb.gui.backing.data.DigitalObjectCompare.java

/**
 * @param dobUri//ww  w .j  a v  a 2  s . c om
 * @return
 */
static public DigitalObjectTreeNode lookupDob(String dobUri) {
    if (dobUri == null)
        return null;
    // Create as a URI:
    URI item;
    try {
        item = new URI(dobUri);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }
    // Lookup and return:
    DigitalObjectTreeNode itemNode = new DigitalObjectTreeNode(item, DataRegistryFactory.getDataRegistry());
    return itemNode;
}

From source file:cn.tiup.httpproxy.ProxyServlet.java

private static String getHost(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    try {//from ww  w  . ja va 2  s. c o m
        URI uri = new URI(requestURL.toString());
        int port = uri.getPort();
        if (port > 0 && port != 80 && port != 443) {
            return uri.getHost() + ":" + Integer.toString(port);
        } else {
            return uri.getHost();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return request.getServerName();
}