List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:com.linkbubble.util.YouTubeEmbedHelper.java
public boolean onEmbeds(String[] strings) { if (strings == null || strings.length == 0) { return false; }//from ww w .j a va2 s .c o m boolean listChanged = false; for (String string : strings) { int prefixStartIndex = string.indexOf(Config.YOUTUBE_EMBED_PREFIX); if (prefixStartIndex > -1) { URL url; try { url = new URL(string); } catch (MalformedURLException e) { e.printStackTrace(); break; } String path = url.getPath(); int pathStartIndex = path.indexOf(Config.YOUTUBE_EMBED_PATH_SUFFIX); if (pathStartIndex > -1) { String videoId = path.substring(pathStartIndex + Config.YOUTUBE_EMBED_PATH_SUFFIX.length()); if (videoId.length() > 0) { boolean onList = false; if (mEmbedIds.size() > 0) { for (String s : mEmbedIds) { if (s.equals(videoId)) { onList = true; break; } } } if (onList == false) { mEmbedIds.add(videoId); listChanged = true; } } } } } if (listChanged) { if (mCurrentDownloadTask != null) { synchronized (mCurrentDownloadTask) { if (mCurrentDownloadTask != null) { mCurrentDownloadTask.cancel(true); } mCurrentDownloadTask = new DownloadYouTubeEmbedInfoTask(false, null); mCurrentDownloadTask.execute(null, null, null); } } else { mCurrentDownloadTask = new DownloadYouTubeEmbedInfoTask(false, null); mCurrentDownloadTask.execute(null, null, null); } } return mEmbedIds.size() > 0; }
From source file:at.molindo.webtools.crawler.CrawlerTask.java
@Override public void run() { if (Thread.currentThread() instanceof CrawlerThread == false) { throw new Error("not a cralwer thread"); }/*from w ww . j a va 2 s . co m*/ final CrawlerResult sr = new CrawlerResult(); sr.setUrl(_urlString); sr.getReferrers().add(_referrer); final HttpGet get = new HttpGet(_urlString); // get.setFollowRedirects(false); try { final long start = System.currentTimeMillis(); final HttpResponse response = ((CrawlerThread) Thread.currentThread()).getClient().execute(get); sr.setStatus(response.getStatusLine().getStatusCode()); sr.setTime((int) (System.currentTimeMillis() - start)); final Header[] contentTypeHeader = response.getHeaders("Content-Type"); sr.setContentType(contentTypeHeader == null || contentTypeHeader.length == 0 ? null : contentTypeHeader[0].getValue()); final String encoding = response.getEntity().getContentEncoding() == null ? null : response.getEntity().getContentEncoding().getValue(); final Object content = consumeContent(response.getEntity().getContent(), sr.getContentType(), response.getEntity().getContentLength(), encoding); if (sr.getStatus() / 100 == 3) { String redirectLocation; final Header[] locationHeader = response.getHeaders("location"); if (locationHeader != null && locationHeader.length > 0) { redirectLocation = locationHeader[0].getValue(); if (redirectLocation.startsWith("/")) { redirectLocation = _crawler._host + redirectLocation.substring(1); } _crawler.queue(redirectLocation, new CrawlerReferrer(_urlString, response.getStatusLine().getReasonPhrase() + ": " + _referrer)); } else { System.err.println("redirect without location from " + _urlString); } } else if (sr.getStatus() == HttpStatus.SC_OK) { if (content instanceof String) { sr.setText((String) content); if (sr.getContentType().startsWith("text/html")) { parseResult(sr.getText()); } } } } catch (final MalformedURLException e) { sr.setErrorMessage(e.getMessage()); // e.printStackTrace(); } catch (final IOException e) { sr.setErrorMessage(e.getMessage()); e.printStackTrace(); } catch (final SAXException e) { sr.setErrorMessage(e.getMessage()); // e.printStackTrace(); } catch (final Throwable t) { t.printStackTrace(); } finally { _crawler.report(sr); // response.releaseConnection(); } }
From source file:com.clevertrail.mobile.findtrail.Activity_FindTrail_ByLocation.java
protected JSONArray fetchTrailListJSON(double dSearchLat, double dSearchLong, double dSearchDistance) { JSONArray returnJSON = null;/*from www .j a va2 s . com*/ HttpURLConnection urlConnection = null; try { //set up the api call String params = "lat=" + dSearchLat + "&lng=" + dSearchLong + "&dist=" + dSearchDistance; String requestURL = "http://clevertrail.com/ajax/handleGetArticles.php?" + params; URL url = new URL(requestURL); urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); BufferedReader r = new BufferedReader(new InputStreamReader(in)); String line; //did we get a response with trails in it? if ((line = r.readLine()) != null) { returnJSON = new JSONArray(line); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block // could not connect to clevertrail.com e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (urlConnection != null) urlConnection.disconnect(); } return returnJSON; }
From source file:eu.codeplumbers.cosi.services.CosiLoyaltyCardService.java
public void sendChangesToCozy() { List<LoyaltyCard> unSyncedLoyaltyCards = LoyaltyCard.getAllUnsynced(); int i = 0;//from ww w . j av a2s . c o m for (LoyaltyCard loyaltyCard : unSyncedLoyaltyCards) { URL urlO = null; try { JSONObject jsonObject = loyaltyCard.toJsonObject(); mBuilder.setProgress(unSyncedLoyaltyCards.size(), i + 1, false); mBuilder.setContentText("Syncing " + jsonObject.getString("docType") + ":"); mNotifyManager.notify(notification_id, mBuilder.build()); EventBus.getDefault().post( new LoyaltyCardSyncEvent(SYNC_MESSAGE, getString(R.string.lbl_sms_status_read_phone))); String remoteId = jsonObject.getString("remoteId"); String requestMethod = ""; if (remoteId.isEmpty()) { urlO = new URL(syncUrl); requestMethod = "POST"; } else { urlO = new URL(syncUrl + remoteId + "/"); requestMethod = "PUT"; } HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod(requestMethod); // set request body jsonObject.remove("remoteId"); long objectId = jsonObject.getLong("id"); jsonObject.remove("id"); OutputStream os = conn.getOutputStream(); os.write(jsonObject.toString().getBytes("UTF-8")); os.flush(); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONObject jsonObjectResult = new JSONObject(result); if (jsonObjectResult != null && jsonObjectResult.has("_id")) { result = jsonObjectResult.getString("_id"); loyaltyCard.setRemoteId(result); loyaltyCard.save(); } in.close(); conn.disconnect(); } catch (MalformedURLException e) { EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); e.printStackTrace(); stopSelf(); } catch (ProtocolException e) { EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); e.printStackTrace(); stopSelf(); } catch (IOException e) { EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); e.printStackTrace(); stopSelf(); } catch (JSONException e) { EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); e.printStackTrace(); stopSelf(); } i++; } }
From source file:com.android.datacloud.Entity.java
/** * Borra una fila/* w w w . j a va 2s . com*/ * * @return "true" si es borrada, "false" otra cosa */ public boolean delete() { try { URL url = new URL(DataCloud.getInstance().getURLLoadData(mTable, mId)); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpCon.setRequestMethod("DELETE"); httpCon.connect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:JMeter.plugins.functional.samplers.geoevent.HttpJsonToStreamServiceSampler.java
private void setupTarget() { try {// ww w. j a v a 2s . c om // Send the Message to Rest Endpoint String urlString = getRestInputURL(); //System.out.println(urlString); URL url = new URL(urlString); Client client; if (url.getProtocol().equalsIgnoreCase("https")) { TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } @Override public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } } }; SSLContext sc = null; sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); client = ClientBuilder.newBuilder().sslContext(sc).build(); } else { client = ClientBuilder.newClient(); } target = client.target(urlString); } catch (MalformedURLException ex) { java.util.logging.Logger.getLogger(HttpJsonToStreamServiceSampler.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } catch (NoSuchAlgorithmException ex) { java.util.logging.Logger.getLogger(HttpJsonToStreamServiceSampler.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } catch (KeyManagementException ex) { java.util.logging.Logger.getLogger(HttpJsonToStreamServiceSampler.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.EventServiceClient.java
public String queryContext(String codUser) { String strJSON = null;/*from ww w . jav a2s. co m*/ HttpURLConnection conn = null; StringBuffer strBOutput = new StringBuffer(); boolean boolOK = true; String input = null; StringBuffer stbInput = new StringBuffer(); try { log.debug("queryContext Start "); conn = getEventServiceSEConnection(methodQueryContext, endpointEventService, headerContentTypeJSON); stbInput.append("{\"entities\": [ {\"type\": \"" + typeContextValue + "\", \"isPattern\": \"false\", \"id\": \"" + codUser + "\"}]}"); input = stbInput.toString(); log.debug(input); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() == 200) { log.debug("queryContext Response code " + conn.getResponseCode()); } else { if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } } log.debug("queryContext OutputStream wrote"); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); log.debug("queryContext Waiting server response "); String output; log.debug("queryContext Output from Server .... \n"); while ((output = br.readLine()) != null) { strBOutput.append(output); log.debug(output); } conn.disconnect(); strJSON = strBOutput.toString(); boolOK = true; } catch (MalformedURLException e) { log.error("queryContext MalformedURLException " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("queryContext IOException " + e.getMessage()); e.printStackTrace(); } return strJSON; }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.EventServiceClient.java
public boolean getAccessToken() { HttpURLConnection conn = null; StringBuffer strBOutput = new StringBuffer(); boolean boolOK = true; String input = null;//from www . j a v a2 s. co m StringBuffer stbInput = new StringBuffer(); try { log.debug("getAccessToken Start "); conn = getEventServiceSEConnection(methodAccessToken, endpointOauth, headerContentTypeFormUrlencoded); stbInput.append( "client_id=522a3819dc268f33c983&client_secret=169d587f10e75316501483280d0c4843c3333144&grant_type=password&username=ktekQuser&password=F20st67R&scope=write"); input = stbInput.toString(); log.debug(input); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() == 200) { log.debug("getAccessToken Response code " + conn.getResponseCode()); } else { if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { throw new RuntimeException( "getAccessToken Failed : HTTP error code : " + conn.getResponseCode()); } } log.debug("getAccessToken OutputStream wrote"); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); log.debug("getAccessToken Waiting server response "); String output; log.debug("getAccessToken Output from Server .... \n"); while ((output = br.readLine()) != null) { strBOutput.append(output); log.debug(output); } conn.disconnect(); boolOK = true; } catch (MalformedURLException e) { log.error("getAccessToken MalformedURLException " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("getAccessToken IOException " + e.getMessage()); e.printStackTrace(); } return boolOK; }
From source file:eu.planets_project.tb.impl.model.exec.ServiceRecordImpl.java
/** */ private ServiceDescription serviceDescriptionFromRecord() { ServiceDescription.Builder sdb = new ServiceDescription.Builder(this.serviceName, this.serviceType); sdb.description("This old service is not longer available."); sdb.version(this.serviceVersion); // The endpoint: try {//w w w . java 2 s . c o m sdb.endpoint(new URL(this.endpoint)); } catch (MalformedURLException e) { e.printStackTrace(); } // Tool info: URI toolUri = null; try { if (this.toolIdentifier != null) { toolUri = new URI(this.toolIdentifier); } } catch (URISyntaxException e1) { e1.printStackTrace(); } sdb.tool(new Tool(toolUri, this.toolName, this.toolVersion, null, null)); return sdb.build(); }
From source file:com.nubits.nubot.notifications.jhipchat.HipChat.java
public User getUser(UserId id) { String query = String.format(HipChatConstants.USERS_SHOW_QUERY_FORMAT, id.getId(), HipChatConstants.JSON_FORMAT, authToken); InputStream input = null;// w w w . j av a 2 s.c om User result = null; HttpURLConnection connection = null; try { URL requestUrl = new URL(HipChatConstants.API_BASE + HipChatConstants.USERS_SHOW + query); connection = (HttpURLConnection) requestUrl.openConnection(); connection.setDoInput(true); input = connection.getInputStream(); result = UserParser.parseUser(this, input); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(input); connection.disconnect(); } return result; }