List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:name.yumao.douyu.http.PlaylistDownloader.java
public static void go(/**final String name,*/ final String num) { // PlaylistDownloader loader = new PlaylistDownloader("http://"); ExecutorService service = Executors.newCachedThreadPool(); // GetList producer = new GetList(); roomnum = num;//from ww w .j a v a 2 s. co m // Down consumer = new Down(); // final String id = ""; service.execute(new Runnable() { public void run() { while (true) { // // ZhanqiApiVo vo = HttpClientFromZhanqi.QueryZhanqiDownloadUrl(inNum.getText() ); try { String url = HttpClientFromDouyu.getHTML5DownUrl(num); if (!url.equals("")) { // fetchsubPlaylist(new URL(url)); } else { logger.info("error"); outFile = getPath(); } } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // // } // try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); service.execute(new Runnable() { public void run() { while (true) { logger.info("down ......................"); URL down = null; while (true) { try { down = basket.poll(); logger.debug("down:" + down); if (down != null) downloadInternal(down); Thread.sleep(500); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } //download("outtest"); } } }); }
From source file:de.betterform.agent.web.WebUtil.java
/** * this method is responsible for passing all context information needed by the Adapter and Processor from * ServletRequest to Context. Will be called only once when the form-session is inited (GET). * <p/>//w ww. ja va 2 s .c o m * <p/> * todo: better logging of context params * * @param request the Servlet request to fetch params from * @param httpSession the Http Session context * @param processor the XFormsProcessor which receives the context params * @param sessionkey the key to identify the XFormsSession */ public static void setContextParams(HttpServletRequest request, HttpSession httpSession, XFormsProcessor processor, String sessionkey) throws XFormsConfigException { Map servletMap = new HashMap(); servletMap.put(WebProcessor.SESSION_ID, sessionkey); processor.setContextParam(XFormsProcessor.SUBMISSION_RESPONSE, servletMap); //adding requestURI to context processor.setContextParam(WebProcessor.REQUEST_URI, WebUtil.getRequestURI(request)); //adding request URL to context String requestURL = request.getRequestURL().toString(); processor.setContextParam(WebProcessor.REQUEST_URL, requestURL); // the web app name with an '/' prepended e.g. '/betterform' by default String contextRoot = WebUtil.getContextRoot(request); processor.setContextParam(WebProcessor.CONTEXTROOT, contextRoot); if (LOGGER.isDebugEnabled()) { LOGGER.debug("context root of webapp: " + processor.getContextParam(WebProcessor.CONTEXTROOT)); } String requestPath = ""; URL url = null; String plainPath = ""; try { url = new URL(requestURL); requestPath = url.getPath(); } catch (MalformedURLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } if (requestPath.length() != 0) { //adding request path e.g. '/betterform/forms/demo/registration.xhtml' processor.setContextParam(WebProcessor.REQUEST_PATH, requestPath); //adding filename of requested doc to context String fileName = requestPath.substring(requestPath.lastIndexOf('/') + 1, requestPath.length());//FILENAME xforms processor.setContextParam(FILENAME, fileName); if (requestURL.contains(contextRoot)) { //case1: contextRoot is a part of the URL //adding plainPath which is the part between contextroot and filename e.g. '/forms' for a requestPath of '/betterform/forms/Status.xhtml' plainPath = requestPath.substring(contextRoot.length() + 1, requestPath.length() - fileName.length()); processor.setContextParam(PLAIN_PATH, plainPath); } else {//case2: contextRoot is not a part of the URL take the part previous the filename. String[] urlParts = requestURL.split("/"); plainPath = urlParts[urlParts.length - 2]; } //adding contextPath - requestPath without the filename processor.setContextParam(CONTEXT_PATH, contextRoot + "/" + plainPath); } //adding session id to context processor.setContextParam(HTTP_SESSION_ID, httpSession.getId()); //adding context absolute path to context //EXIST-WORKAROUND: TODO triple check ... //TODO: triple check where this is used. if (request.isRequestedSessionIdValid()) { processor.setContextParam(EXISTDB_USER, httpSession.getAttribute(EXISTDB_USER)); } //adding pathInfo to context - attention: this is only available when a servlet is requested String s1 = request.getPathInfo(); if (s1 != null) { processor.setContextParam(WebProcessor.PATH_INFO, s1); } processor.setContextParam(WebProcessor.QUERY_STRING, (request.getQueryString() != null ? request.getQueryString() : "")); //storing the realpath for webapp String realPath = WebFactory.getRealPath(".", httpSession.getServletContext()); File f = new File(realPath); URI fileURI = f.toURI(); processor.setContextParam(WebProcessor.REALPATH, fileURI.toString()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("real path of webapp: " + realPath); } //storing the TransformerService processor.setContextParam(TransformerService.TRANSFORMER_SERVICE, httpSession.getServletContext().getAttribute(TransformerService.TRANSFORMER_SERVICE)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("TransformerService: " + httpSession.getServletContext().getAttribute(TransformerService.TRANSFORMER_SERVICE)); } //[2] read any request params that are *not* betterForm params and pass them into the context map Enumeration params = request.getParameterNames(); String s; while (params.hasMoreElements()) { s = (String) params.nextElement(); //store all request-params we don't use in the context map of XFormsProcessorImpl String value = request.getParameter(s); processor.setContextParam(s, value); if (LOGGER.isDebugEnabled()) { LOGGER.debug("added request param '" + s + "' added to context"); LOGGER.debug("param value'" + value); } } }
From source file:edu.jhu.cvrg.waveform.utility.WebServiceUtility.java
public static Map<String, String> annotationJSONLookup(String restURL, String... key) { Map<String, String> ret = null; URL url;/*from www .j a v a2 s . co m*/ HttpURLConnection conn = null; try { if (System.currentTimeMillis() > waitUntil) { url = new URL(restURL); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); BufferedReader in = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String jsonSrc = in.readLine(); in.close(); JSONObject jsonObject = new JSONObject(jsonSrc); ret = new HashMap<String, String>(); for (int i = 0; i < key.length; i++) { Object atr = jsonObject.get(key[i]); String value = ""; if (atr instanceof JSONArray) { JSONArray array = ((JSONArray) atr); for (int j = 0; j < array.length(); j++) { value += array.getString(j); } } else { value = atr.toString(); } if (value.isEmpty()) { value = "No " + key[i] + " found"; } ret.put(key[i], value); } } else { log.warn("Waiting the bioportal server"); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { //wait for 1 minute waitUntil = System.currentTimeMillis() + (1000 * 60); log.error(ioe.getMessage()); } catch (JSONException e) { e.printStackTrace(); } return ret; }
From source file:edu.jhu.cvrg.waveform.utility.WebServiceUtility.java
/** Looks up the long definition text from the/ECGOntology at Bioportal for the specfied tree node ID. * //from ww w . j a v a2 s .com * @param treeNodeID - the id to look up, as supplied by the OntologyTree popup. * @return - long definition text */ public static String annotationXMLLookup(String restURL) { String definition = "WARNING TEST FILLER From BrokerServiceImpl.java"; String label = "TEST LABEL"; String sReturn = ""; URL url; try { url = new URL(restURL); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; boolean isDescriptionFollowing = false; StringBuffer buff = null; while ((inputLine = in.readLine()) != null) { String regex = "^\\s+<label>\\w+</label>$"; boolean bLabel = inputLine.matches(regex); if (bLabel) { label = inputLine.trim(); } if (isDescriptionFollowing) { // <label> if (inputLine.length() != 0) { if (inputLine.indexOf("</definitions>") > -1) { isDescriptionFollowing = false; break; } else { buff.append(inputLine); } } } else { if (inputLine.indexOf("<definitions>") > -1) { isDescriptionFollowing = true; buff = new StringBuffer(); } } } in.close(); if (buff.length() > 0) { definition = buff.substring(0); definition = definition.replace("/n", ""); definition = definition.replace("<string>", ""); definition = definition.replace("</string>", ""); definition = definition.trim(); } else { definition = "Detailed definition not available."; } sReturn = label + definition; } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } return sReturn; }
From source file:eu.planets_project.services.utils.DigitalObjectUtils.java
/** * Convenience method that creates a URL from a file in a proper (i.e. not deprecated) way, using the toURI().toURL() way. * Hiding the Exception, so you don't have to put it in a try-catch block. * @param file/*from w w w . jav a 2 s . c o m*/ * @return The URL for the given file */ private static URL getUrlFromFile(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:no.ntnu.idi.socialhitchhiking.facebook.FBConnectionActivity.java
/** * Static method that retrieves a users Facebook profile picture. * // ww w .j a v a2 s . c o m * @param id - String, containing a Facebook users id. * @return {@link Bitmap} of the users profile picture. */ public static Bitmap getPicture(String id) { URL img_value = null; Bitmap mIcon1 = null; try { img_value = new URL("http://graph.facebook.com/" + id + "/picture?type=normal"); mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return mIcon1; }
From source file:edu.usc.pgroup.floe.utils.Utils.java
/** * Creates and returns a class loader with the given jar file. * @param path path to the jar file./*ww w. jav a 2 s .c o m*/ * @param parent parent class loader. * @return a new child class loader */ public static ClassLoader getClassLoader(final String path, final ClassLoader parent) { ClassLoader loader = null; try { File relativeJarLoc = new File(path); URL jarLoc = new URL("file://" + relativeJarLoc.getAbsolutePath()); LOGGER.info("Loading jar: {} into class loader.", jarLoc); loader = URLClassLoader.newInstance(new URL[] { jarLoc }, parent); } catch (MalformedURLException e) { e.printStackTrace(); LOGGER.error("Invalid Jar URL Exception: {}", e); } return loader; }
From source file:it.intecs.pisa.toolbox.util.URLReader.java
public static Object getFullURLContent(String urlString) throws Exception { String returnString = ""; URL url = null;//from w w w . ja v a2 s .c o m URLConnection connection = null; // Open Connection try { url = new URL(urlString); } catch (MalformedURLException ex) { ex.printStackTrace(); } try { connection = url.openConnection(); } catch (IOException ex) { ex.printStackTrace(); } HttpURLConnection httpConn = (HttpURLConnection) connection; try { StreamSource source = new StreamSource(httpConn.getInputStream()); TransformerFactory fac = TransformerFactory.newInstance(); Transformer trans = null; StreamResult res = new StreamResult(new StringWriter()); try { trans = fac.newTransformer(); } catch (TransformerConfigurationException ex) { ex.printStackTrace(); } try { trans.transform(source, res); } catch (TransformerException ex) { ex.printStackTrace(); } StringWriter w = (StringWriter) res.getWriter(); returnString = w.toString(); } catch (IOException ex) { ex.printStackTrace(); } return returnString; }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
public static void validateFile(URI fileLocation, String token, boolean validateLevel) throws Exception { BufferedReader reader = null; int lineNo = 1; if (token == null) { token = token_;/*from ww w . j a va2 s . co m*/ } // test MRCUI.RRF URI mrCUIFile = fileLocation.resolve("MRCUI.RRF"); if (mrCUIFile == null) { throw new ConnectionFailure("Did not find the expected MRCUI.RRF file in the location provided."); } if (mrCUIFile.getScheme().equals("file")) { new FileReader(new File(mrCUIFile)).close(); } else { new InputStreamReader(mrCUIFile.toURL().openConnection().getInputStream()).close(); } try { reader = getReader(mrCUIFile); String line = reader.readLine(); lineNo = 1; boolean notAMonth = false; while (line != null) { if (line.startsWith("#") || line.length() == 0) { line = reader.readLine(); continue; } if (validateLevel && lineNo > 10) { break; } List<String> elements = deTokenizeString(line, token_); if (elements.size() != 7) { throw new Exception( "MRCUI.RRF " + "(" + "Line:" + lineNo + ")" + " is not in the required format."); } if (!elements.get(0).toLowerCase().startsWith("c")) { throw new Exception("MRCUI.RRF " + "(" + "Line:" + lineNo + "): " + "The concept(" + elements.get(0) + ") is not in the required format."); } try { String month = elements.get(1).substring(4); int i = Integer.parseInt(month); if (i < 0 || i > 12) { throw new Exception(); } else { notAMonth = false; } } catch (Exception e) { notAMonth = true; } if (!elements.get(1).endsWith("AA") && !elements.get(1).endsWith("AB") && !elements.get(1).endsWith("AC") && !elements.get(1).endsWith("AD") && notAMonth) { throw new Exception("MRCUI.RRF " + "(" + "Line:" + lineNo + "): " + "The Release id (" + elements.get(1) + ") is not in the required format."); } lineNo++; line = reader.readLine(); } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { reader.close(); } // test MRCONSO.RRF URI mrCONSOFile = fileLocation.resolve("MRCONSO.RRF"); if (mrCONSOFile == null) { throw new ConnectionFailure("Did not find the expected MRCONSO.RRF file in the location provided."); } if (mrCONSOFile.getScheme().equals("file")) { new FileReader(new File(mrCONSOFile)).close(); } else { new InputStreamReader(mrCONSOFile.toURL().openConnection().getInputStream()).close(); } try { reader = getReader(mrCONSOFile); String line = reader.readLine(); lineNo = 1; while (line != null) { if (line.startsWith("#") || line.length() == 0) { line = reader.readLine(); continue; } if (validateLevel && lineNo > 10) { break; } List<String> elements = deTokenizeString(line, token_); if (elements.size() != 18) { throw new Exception( "MRCONSO.RRF " + "(" + "Line:" + lineNo + ")" + " is not in the required format."); } lineNo++; line = reader.readLine(); } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { reader.close(); } }
From source file:edu.samplu.common.WebDriverUtil.java
/** * remote.public.driver set to chrome or firefox (null assumes firefox) * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid) * if proxy.host is set, the web driver is setup to use a proxy * @return WebDriver or null if unable to create *//* w ww .j av a 2 s .c o m*/ public static WebDriver getWebDriver() { String driverParam = System.getProperty(ITUtil.HUB_DRIVER_PROPERTY); String hubParam = System.getProperty(ITUtil.HUB_PROPERTY); String proxyParam = System.getProperty(PROXY_HOST_PROPERTY); // setup proxy if specified as VM Arg DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver webDriver = null; if (StringUtils.isNotEmpty(proxyParam)) { capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam)); } if (hubParam == null) { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); return new FirefoxDriver(capabilities); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new ChromeDriver(capabilities); } else if ("safari".equals(driverParam)) { System.out.println("SafariDriver probably won't work, if it does please contact Erik M."); return new SafariDriver(capabilities); } } else { try { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.firefox()); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.chrome()); } } catch (MalformedURLException mue) { System.out.println(ITUtil.getHubUrlString() + " " + mue.getMessage()); mue.printStackTrace(); } } return null; }