List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:io.selendroid.server.grid.SelfRegisteringRemote.java
/** * Extracts the configuration.//from w w w .j a va2 s.com * * @return The configuration * @throws JSONException On JSON errors. */ private JSONObject getConfiguration() throws JSONException { JSONObject configuration = new JSONObject(); configuration.put("port", config.getPort()); configuration.put("register", true); if (config.getProxy() != null) { configuration.put("proxy", config.getProxy()); } else { configuration.put("proxy", "org.openqa.grid.selenium.proxy.DefaultRemoteProxy"); } configuration.put("role", "node"); configuration.put("registerCycle", 5000); configuration.put("maxInstances", 5); // adding hub details URL registrationUrl; try { registrationUrl = new URL(config.getRegistrationUrl()); } catch (MalformedURLException e) { e.printStackTrace(); throw new SelendroidException("Grid hub url cannot be parsed: " + e.getMessage()); } configuration.put("hubHost", registrationUrl.getHost()); configuration.put("hubPort", registrationUrl.getPort()); // adding driver details configuration.put("remoteHost", "http://" + config.getServerHost() + ":" + config.getPort()); return configuration; }
From source file:org.sonatype.nexus.proxy.maven.routing.internal.RemoteScrapeStrategy.java
@Override public StrategyResult doDiscover(final MavenProxyRepository mavenProxyRepository) throws StrategyFailedException, IOException { log.debug("Remote scrape on {} tried", mavenProxyRepository); // check does a proxy have a valid URL at all final String remoteRepositoryRootUrl; try {/*from www .j av a 2s. c om*/ remoteRepositoryRootUrl = getRemoteUrlOf(mavenProxyRepository); } catch (MalformedURLException e) { throw new StrategyFailedException( "Proxy repository " + mavenProxyRepository + " remote URL malformed:" + e.getMessage(), e); } // get client configured in same way as proxy is using it final HttpClient httpClient = createHttpClientFor(mavenProxyRepository); final ScrapeContext context = new ScrapeContext(mavenProxyRepository, httpClient, config.getRemoteScrapeDepth()); final Page rootPage = Page.getPageFor(context, remoteRepositoryRootUrl); final ArrayList<Scraper> appliedScrapers = new ArrayList<Scraper>(scrapers); Collections.sort(appliedScrapers, new PriorityOrderingComparator<Scraper>()); for (Scraper scraper : appliedScrapers) { log.debug("Remote scraping {} with Scraper {}", mavenProxyRepository, scraper.getId()); scraper.scrape(context, rootPage); if (context.isStopped()) { if (context.isSuccessful()) { log.debug("Remote scraping {} with Scraper {} succeeded.", mavenProxyRepository, scraper.getId()); return new StrategyResult(context.getMessage(), context.getPrefixSource(), true); } else { log.debug("Remote scraping {} with Scraper {} stopped execution.", mavenProxyRepository, scraper.getId()); throw new StrategyFailedException(context.getMessage()); } } log.debug("Remote scraping {} with Scraper {} skipped.", mavenProxyRepository, scraper.getId()); } log.info("Not possible remote scrape of {}, no scraper succeeded.", mavenProxyRepository); throw new StrategyFailedException("No scraper was able to scrape remote (or remote prevents scraping)."); }
From source file:com.rjuarez.webapp.tools.ApiUrl.java
public URL buildUrl(final TheMovieDatabaseParameters params) { final StringBuilder urlString = new StringBuilder(TMDB_API_BASE); LOG.trace("Method: '{}', Sub-method: '{}', Params: {}", method.getValue(), submethod.getValue(), ToStringBuilder.reflectionToString(params, ToStringStyle.SHORT_PREFIX_STYLE)); // Get the start of the URL, substituting TV for the season or episode // methods/*w ww.j a v a 2 s .c om*/ if (method == TheMovieDatabaseMethod.SEASON || method == TheMovieDatabaseMethod.EPISODE) { urlString.append(TheMovieDatabaseMethod.TV.getValue()); } else { urlString.append(method.getValue()); } // We have either a queury, or a ID request if (params.has(TheMovieDatabaseQueries.QUERY)) { urlString.append(queryProcessing(params)); } else { urlString.append(idProcessing(params)); } urlString.append(otherProcessing(params)); try { LOG.trace("URL: {}", urlString.toString()); return new URL(urlString.toString()); } catch (final MalformedURLException ex) { LOG.warn("Failed to create URL {} - {}", urlString.toString(), ex.getMessage()); return null; } }
From source file:org.cloudbyexample.dc.agent.command.ImageClientImpl.java
private DockerImageResponse buildFromArchive(DockerImageArchive request) { String id = null;/* w w w . j a v a 2 s . co m*/ String tag = null; if (request.getRepoTags().size() > 0) { tag = request.getRepoTags().get(0); } logger.debug("Build image. tag='{}' archiveUrl='{}', ", tag, request.getArchiveUrl()); InputStream imageInput = null; InputStream responseInput = null; String log = ""; try { Resource resource = new UrlResource(request.getArchiveUrl()); imageInput = new BufferedInputStream(resource.getInputStream()); // FIXME: need to add no cache option if (tag == null) { responseInput = client.buildImageCmd(imageInput).withRemove(true).exec(); } else { responseInput = client.buildImageCmd(imageInput).withTag(tag).withRemove(true).exec(); } // responseInput = client.buildImageCmd(in).withNoCache().withTag(id).exec(); log = convertInputStreamToString(responseInput); id = matcher.findId(log); } catch (MalformedURLException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } finally { IOUtils.closeQuietly(imageInput); IOUtils.closeQuietly(responseInput); } DockerImageResponse reponse = new DockerImageResponse() .withMessageList(new Message().withMessageType(MessageType.INFO).withMessage(log)) .withResults(request.withId(id).withRepoTags(tag)); return reponse; }
From source file:io.cloudslang.content.utilities.services.osdetector.NmapOsDetectorService.java
@NotNull public String appendProxyArgument(String nmapArguments, String proxyHost, String proxyPort) { try {//from w ww . j ava 2 s . com URL proxyUrl = new URL(proxyHost); if (!isValidIpPort(proxyPort)) { throw new IllegalArgumentException( format("The '%s' input does not contain a valid port.", PROXY_PORT)); } nmapArguments += " --proxies " + proxyUrl.getProtocol() + "://" + proxyUrl.getHost() + ":" + proxyPort; } catch (MalformedURLException e) { throw new IllegalArgumentException( format("The '%s' input does not contain a valid URL: %s.", PROXY_HOST, e.getMessage())); } return nmapArguments; }
From source file:com.networkmanagerapp.JSONBackgroundDownloaderService.java
/** * Delegate method to run the specified intent in another thread. * @param arg0 The intent to run in the background *//*from www.ja v a 2 s .co m*/ @Override protected void onHandleIntent(Intent arg0) { mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); showNotification(); String filename = arg0.getStringExtra("FILENAME"); String jsonFile = arg0.getStringExtra("JSONFILE"); try { String password = PreferenceManager.getDefaultSharedPreferences(this).getString("password_preference", ""); Log.d("password", password); String ip = PreferenceManager.getDefaultSharedPreferences(this).getString("ip_preference", "192.168.1.1"); String enc = URLEncoder.encode(ip, "UTF-8"); String scriptUrl = "http://" + enc + ":1080" + filename; HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(params, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 20000; HttpConnectionParams.setSoTimeout(params, timeoutSocket); HttpHost targetHost = new HttpHost(enc, 1080, "http"); DefaultHttpClient client = new DefaultHttpClient(params); client.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("root", password)); HttpGet request = new HttpGet(scriptUrl); HttpResponse response = client.execute(targetHost, request); Log.d("JBDS", response.getStatusLine().toString()); InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { str.append(line + "\n"); } in.close(); if (str.toString().equals("Success\n")) { String xmlUrl = "http://" + enc + ":1080/json" + jsonFile; request = new HttpGet(xmlUrl); HttpResponse jsonData = client.execute(targetHost, request); in = jsonData.getEntity().getContent(); reader = new BufferedReader(new InputStreamReader(in)); str = new StringBuilder(); line = null; while ((line = reader.readLine()) != null) { str.append(line + "\n"); } in.close(); FileOutputStream fos = openFileOutput(jsonFile.substring(1), Context.MODE_PRIVATE); fos.write(str.toString().getBytes()); fos.close(); } } catch (MalformedURLException ex) { Log.e("NETWORKMANAGER_XBD_MUE", ex.getMessage()); } catch (IOException e) { try { Log.e("NETWORK_MANAGER_XBD_IOE", e.getMessage()); StackTraceElement[] st = e.getStackTrace(); for (int i = 0; i < st.length; i++) { Log.e("NETWORK_MANAGER_XBD_IOE", st[i].toString()); } } catch (NullPointerException ex) { Log.e("Network_manager_xbd_npe", ex.getLocalizedMessage()); } } finally { mNM.cancel(R.string.download_service_started); Intent bci = new Intent(NEW_DATA_AVAILABLE); sendBroadcast(bci); stopSelf(); } }
From source file:gsn.wrappers.HttpGetAndroidWrapper.java
/** * From XML file it needs the followings : * <ul>/*from w ww . ja v a 2 s . c o m*/ * <li>url</li> The full url for retriving the binary data. * <li>rate</li> The interval in msec for updating/asking for new information. * <li>mime</li> Type of the binary data. * </ul> */ public boolean initialize() { this.addressBean = getActiveAddressBean(); urlPath = this.addressBean.getPredicateValue("url"); try { url = new URL(urlPath); } catch (MalformedURLException e) { logger.error("Loading the http android wrapper failed : " + e.getMessage(), e); return false; } inputRate = this.addressBean.getPredicateValue("rate"); if (inputRate == null || inputRate.trim().length() == 0) rate = DEFAULT_RATE; else rate = Integer.parseInt(inputRate); logger.debug("AndroidWrapper is now running @" + rate + " Rate."); return true; }
From source file:com.ibm.mobilefirstplatform.clientsdk.cordovaplugins.core.CDVBMSClient.java
/** * Use the native SDK API to set the base URL for the authorization server. * * @param args JSONArray that contains the backendRoute and backendGUID * @param callbackContext//from w w w. ja v a 2s. co m */ public void initialize(JSONArray args, CallbackContext callbackContext) throws JSONException { String backendRoute = args.getString(0); String backendGUID = args.getString(1); if (backendRoute != null && backendRoute.length() > 0 && backendGUID != null && backendGUID.length() > 0) { try { BMSClient.getInstance().initialize(this.cordova.getActivity().getApplicationContext(), backendRoute, backendGUID); } catch (MalformedURLException e) { callbackContext.error(e.getMessage()); } bmsLogger.debug("Successfully initialized BMSClient"); callbackContext.success(); } else { bmsLogger.error("Trouble initializing BMSClient"); callbackContext.error(errorEmptyArg); } }
From source file:edu.du.penrose.systems.fedoraProxy.util.FedoraProxyServletContextListener.java
public URL getVersionsFileURL() { URL resourceURL;//from w ww . j a va 2 s . co m try { resourceURL = new URL("file:///" + getAppRealPath() + RESOURCES_RELATIVE_URI_PATH + VERSIONS_FILE_NAME); } catch (MalformedURLException e) { throw new RuntimeException(e.getMessage()); } return resourceURL; }
From source file:de.micmun.android.workdaystarget.DayCalculator.java
/** * Returns the list with holydays between now and target. * * @return the list with holydays between now and target. * @throws JSONException if parsing the holidays fails. *//*from w ww . j a va 2s . c om*/ private ArrayList<Date> getHolidays() throws JSONException { ArrayList<Date> holidays = new ArrayList<Date>(); String basisUrl = "http://kayaposoft.com/enrico/json/v1.0/" + "?action=getPublicHolidaysForDateRange&fromDate=%s&toDate=%s" + "&country=ger®ion=Bavaria"; SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); String url = String.format(basisUrl, sdf.format(today.getTime()), sdf.format(target.getTime())); BufferedReader br = null; String text = null; try { URL httpUrl = new URL(url); HttpURLConnection con = (HttpURLConnection) httpUrl.openConnection(); con.setRequestMethod("GET"); con.connect(); InputStream is = con.getInputStream(); br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } br.close(); text = sb.toString(); } catch (MalformedURLException e) { System.err.println("FEHLER: " + e.getMessage()); holidays = null; } catch (IOException e) { System.err.println("FEHLER: " + e.getMessage()); holidays = null; } finally { if (br != null) { try { br.close(); } catch (IOException ignored) { } } } if (text != null) { JSONArray array = new JSONArray(text); for (int i = 0; i < array.length(); ++i) { JSONObject h = array.getJSONObject(i); JSONObject o = h.getJSONObject("date"); int day = o.getInt("day"); int month = o.getInt("month"); int year = o.getInt("year"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.YEAR, year); setMidnight(cal); holidays.add(cal.getTime()); } } return holidays; }