List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:com.denimgroup.threadfix.service.defects.utils.RestUtilsImpl.java
@Override public boolean hasXSeraphLoginReason(String urlString, String username, String password) { URL url;// w w w .j av a 2 s. c o m try { url = new URL(urlString); } catch (MalformedURLException e) { e.printStackTrace(); return false; } try { HttpURLConnection httpConnection; if (proxyService == null) { httpConnection = (HttpURLConnection) url.openConnection(); } else { httpConnection = proxyService.getConnectionWithProxyConfig(url, classToProxy); } setupAuthorization(httpConnection, username, password); httpConnection.addRequestProperty("Content-Type", "application/json"); httpConnection.addRequestProperty("Accept", "application/json"); String headerResult = httpConnection.getHeaderField("X-Seraph-LoginReason"); return headerResult != null && headerResult.equals("AUTHENTICATION_DENIED"); } catch (IOException e) { LOG.warn("IOException encountered while trying to find the response code.", e); } return false; }
From source file:com.esri.geoevent.processor.geonames.GeoNamesOSMPOIProcessor.java
private String getReverseGeocode(URL url) { String output = ""; try {// w w w. java2 s .c o m HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); if (conn.getResponseCode() != 200) { String errorString = "Failed : HTTP error code : " + conn.getResponseCode(); throw new RuntimeException(errorString); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String line; //System.out.println("Output from Server .... \n"); while ((line = br.readLine()) != null) { output += line; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return output; }
From source file:com.pursuer.reader.easyrss.WebpageItemViewCtrl.java
@SuppressLint("SimpleDateFormat") private void showMobilizedPage() { showMobilized = true;/* w w w . j ava 2 s . c om*/ view.findViewById(R.id.Mobilized).setVisibility(View.VISIBLE); view.findViewById(R.id.OriginalContent).setVisibility(View.GONE); view.findViewById(R.id.BtnMobilzedPage).setEnabled(false); view.findViewById(R.id.BtnOriginalPage).setEnabled(true); view.findViewById(R.id.OriginalProgress).setVisibility(View.GONE); view.findViewById(R.id.MobilizedProgress).setVisibility(View.VISIBLE); view.findViewById(R.id.MobilizedContent).setVisibility(View.GONE); final TextView title = (TextView) view.findViewById(R.id.ItemTitle); title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3); title.setText(item.getTitle()); final TextView info = (TextView) view.findViewById(R.id.ItemInfo); info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5); final StringBuilder infoText = new StringBuilder(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); sdf.setTimeZone(TimeZone.getDefault()); infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp()))); if (item.getAuthor() != null && item.getAuthor().length() > 0) { infoText.append(" | By "); infoText.append(item.getAuthor()); } if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) { infoText.append(" ("); infoText.append(item.getSourceTitle()); infoText.append(")"); } info.setText(infoText); if (thread == null) { thread = new Thread(new Runnable() { @SuppressWarnings("deprecation") @Override public void run() { try { final StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append("http://easyrss.pursuer.me/parser?url="); urlBuilder.append(URLEncoder.encode(item.getHref())); urlBuilder.append("&email="); urlBuilder.append(URLEncoder.encode(dataMgr.getSettingByName(Setting.SETTING_USERNAME))); urlBuilder.append("&version="); urlBuilder.append(context.getString(R.string.Version)); final URLConnection connection = new URL(urlBuilder.toString()).openConnection(); connection.setConnectTimeout(30 * 1000); connection.setReadTimeout(20 * 1000); final InputStreamReader input = new InputStreamReader(connection.getInputStream()); final StringBuilder builder = new StringBuilder(); final char buff[] = new char[8192]; int len; while ((len = input.read(buff)) != -1) { builder.append(new String(buff, 0, len)); } builder.append(theme == SettingTheme.THEME_NORMAL ? DataUtils.DEFAULT_NORMAL_CSS : DataUtils.DEFAULT_DARK_CSS); pageContent = builder.toString(); handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } catch (final MalformedURLException exception) { exception.printStackTrace(); pageContent = genFailedToLoadContentPage(context, theme); handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } catch (final IOException exception) { exception.printStackTrace(); pageContent = genFailedToLoadContentPage(context, theme); handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } } }); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } else if (!thread.isAlive()) { handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } }
From source file:fi.elfcloud.sci.Connection.java
/** * Does a fetch operation to elfcloud.fi server. * @param headers request headers to be applied * @return connection to elfcloud.fi server * @throws ECException//from w w w . j a v a 2s . co m * @see {@link HttpURLConnection} */ public HttpURLConnection getData(Map<String, String> headers) throws ECException { Object[] keys = headers.keySet().toArray(); URL url; try { url = new URL(Connection.url + Connection.apiVersion + "/fetch"); conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Content-type", "application/octet-stream; charset=utf-8"); for (int i = 0; i < keys.length; i++) { conn.setRequestProperty((String) keys[i], headers.get(keys[i])); } String result = conn.getHeaderField("X-ELFCLOUD-RESULT"); if (!result.equals("OK")) { String[] exceptionData = result.split(" ", 4); int exceptionID = Integer.parseInt(exceptionData[1]); String message = exceptionData[3]; if (exceptionID == 101) { while (authTries < 3) { if (auth()) { return getData(headers); } } authTries = 0; } ECDataItemException exception = new ECDataItemException(); exception.setId(exceptionID); exception.setMessage(message); throw exception; } authTries = 0; return conn; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { ECClientException exception = new ECClientException(); exception.setId(408); exception.setMessage("Error connecting to elfcloud.fi server"); throw exception; } return null; }
From source file:net.blogracy.services.SeedService.java
@Override public void onMessage(Message request) { try {//www. j a va2 s . c o m String text = ((TextMessage) request).getText(); Logger.info("seed service:" + text + ";"); JSONObject entry = new JSONObject(text); try { File file = new File(entry.getString("file")); Torrent torrent = plugin.getTorrentManager().createFromDataFile(file, new URL("udp://tracker.openbittorrent.com:80")); torrent.setComplete(file.getParentFile()); String name = Base32.encode(torrent.getHash()); int index = file.getName().lastIndexOf('.'); if (0 < index && index <= file.getName().length() - 2) { name = name + file.getName().substring(index); } Download download = plugin.getDownloadManager().addDownload(torrent, null, // torrentFile, file.getParentFile()); if (download != null) download.renameDownload(name); entry.put("uri", torrent.getMagnetURI().toExternalForm()); if (request.getJMSReplyTo() != null) { TextMessage response = session.createTextMessage(); response.setText(entry.toString()); response.setJMSCorrelationID(request.getJMSCorrelationID()); producer.send(request.getJMSReplyTo(), response); } } catch (MalformedURLException e) { Logger.error("Malformed URL error: seed service " + text); } catch (TorrentException e) { Logger.error("Torrent error: seed service: " + text); e.printStackTrace(); } catch (DownloadException e) { Logger.error("Download error: seed service: " + text); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } catch (JMSException e) { Logger.error("JMS error: seed service"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:crawl.SphinxWrapper.java
protected void addStartLink(String root) { try {// w w w. j av a 2s. c o m URL url = new URL(root); Link link = new Link(url); System.out.println("Adding seed URL " + url.toString()); super.addRoot(link); } catch (MalformedURLException me) { System.err.println("Malformed url " + root); me.printStackTrace(); } }
From source file:de.codecentric.jira.jenkins.plugin.servlet.RecentBuildsServlet.java
/** * This function takes get data and renders the template *///from w ww . j a va 2 s. co m protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Map<String, Object> velocityValues = new HashMap<String, Object>(); List<JenkinsBuild> builds = new ArrayList<JenkinsBuild>(); I18nHelper i18nHelper; if (old) { i18nHelper = OldUser.getI18nHelper(authenticationContext); } else { i18nHelper = NewUser.getI18nHelper(authenticationContext); } try { String urlJenkinsServer = req.getParameter("jenkinsUrl"); String view = req.getParameter("view"); String job = req.getParameter("job"); int maxBuilds = Integer.parseInt(req.getParameter("maxBuilds")); String userName = req.getParameter("userName"); String password = req.getParameter("password"); //check if urlJenkinsServer equals Server.name JenkinsServer server = serverList.find(urlJenkinsServer); if (server != null) { urlJenkinsServer = server.getUrl(); } if (urlJenkinsServer.lastIndexOf('/') < urlJenkinsServer.length() - 1) { urlJenkinsServer += "/"; } Document buildRss; //Test if authorization is available if (userName == "" && password == "" && !urlJenkinsServer.startsWith("https")) { buildRss = getBuildRss(urlJenkinsServer, view, job); velocityValues.put("user", "anonymous"); } else if (userName == "") { defaultcreds = new UsernamePasswordCredentials(userName, password); client.getState().setCredentials(new AuthScope(null, -1, AuthScope.ANY_REALM), defaultcreds); buildRss = getBuildRssAuth(urlJenkinsServer, view, job); velocityValues.put("user", "anonymous"); } else { defaultcreds = new UsernamePasswordCredentials(userName, password); client.getState().setCredentials(new AuthScope(null, -1, AuthScope.ANY_REALM), defaultcreds); buildRss = getBuildRssAuth(urlJenkinsServer, view, job); velocityValues.put("user", userName); } builds = readBuilds(buildRss, maxBuilds, i18nHelper); velocityValues.put("serverList", serverList.getServerList()); velocityValues.put("view", view); velocityValues.put("job", job); velocityValues.put("jenkinsUrl", urlJenkinsServer); velocityValues.put("builds", builds); velocityValues.put("context", this.getServletContext()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } resp.setContentType("text/html;charset=utf-8"); templateRenderer.render(TEMPLATE_PATH, velocityValues, resp.getWriter()); }
From source file:com.vishnuvalleru.travelweatheralertsystem.MainActivity.java
private void fetchData() { StringBuilder urlString = new StringBuilder(); urlString.append("http://maps.google.com/maps/api/directions/xml?origin="); urlString.append(src_lat);// w ww . j a va2s .c o m urlString.append(","); urlString.append(src_long); urlString.append("&destination=");// to urlString.append(dest_lat); urlString.append(","); urlString.append(dest_long); urlString.append("&sensor=true&mode=driving"); HttpURLConnection urlConnection = null; URL url = null; try { url = new URL(urlString.toString()); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.connect(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = (Document) db.parse(urlConnection.getInputStream());// Util.XMLfromString(response); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } }
From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java
/** * Runs the XCDLComparator on two given xcdls and returns the comparison result. * @param xcdl1/* www . j av a 2 s . c o m*/ * @param xcdl2 * @return * @throws Exception */ private String runXCDLComparator(String xcdl1, String xcdl2) throws Exception { URL url = null; try { url = new URL(URL_XCDLCOMPARATOR); Service service = Service.create(url, new QName(PlanetsServices.NS, Compare.NAME)); Compare comparator = service.getPort(Compare.class); //the service call and it's result DigitalObject x1 = new DigitalObject.Builder(Content.byValue(xcdl1.getBytes())).build(); DigitalObject x2 = new DigitalObject.Builder(Content.byValue(xcdl2.getBytes())).build(); List<Property> result = comparator.compare(x1, x2, null).getProperties(); if (result == null) { throw new Exception("XCDL comparison failed - please check service logs for details"); } return result.toString(); } catch (MalformedURLException e) { e.printStackTrace(); throw e; } }
From source file:fi.elfcloud.sci.Connection.java
/** * Does a store operation to elfcloud.fi server. * @param headers request headers to be applied * @param dataChunk data to be sent//from w w w.j a v a2s .c om * @param len length of the data * @throws ECException */ public void sendData(Map<String, String> headers, byte[] dataChunk, int len) throws ECException { Object[] keys = headers.keySet().toArray(); URL url; try { url = new URL(Connection.url + Connection.apiVersion + "/store"); conn = (HttpURLConnection) url.openConnection(); for (int i = 0; i < keys.length; i++) { conn.setRequestProperty((String) keys[i], headers.get(keys[i])); } conn.setDoOutput(true); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.write(dataChunk, 0, len); String result = conn.getHeaderField("X-ELFCLOUD-RESULT"); wr.close(); if (conn.getResponseCode() != 200 || !result.equals("OK")) { ECDataItemException exception; if (conn.getResponseCode() == 200) { String[] exceptionData = result.split(" ", 4); int exceptionID = Integer.parseInt(exceptionData[1]); String message = exceptionData[3]; if (exceptionID == 101) { cookieJar.removeAll(); while (authTries < 3) { if (auth()) { sendData(headers, dataChunk, len); return; } } authTries = 0; } exception = new ECDataItemException(); exception.setId(exceptionID); exception.setMessage(message); } else { exception = new ECDataItemException(); exception.setId(conn.getResponseCode()); exception.setMessage(conn.getResponseMessage()); } throw exception; } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { ECClientException exception = new ECClientException(); exception.setId(408); exception.setMessage("Error connecting to elfcloud.fi server"); authTries = 0; throw exception; } }