List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:Activities.java
private String addData(String endpoint) { String data = null;/*w w w. ja va2 s. c om*/ try { // Construct request payload JSONObject attrObj = new JSONObject(); attrObj.put("name", "URL"); attrObj.put("value", "http://www.nvidia.com/game-giveaway"); JSONArray attrArray = new JSONArray(); attrArray.add(attrObj); TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); String dateAsISO = df.format(new Date()); // Required attributes JSONObject obj = new JSONObject(); obj.put("leadId", "1001"); obj.put("activityDate", dateAsISO); obj.put("activityTypeId", "1001"); obj.put("primaryAttributeValue", "Game Giveaway"); obj.put("attributes", attrArray); System.out.println(obj); // Make request URL url = new URL(endpoint); HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection(); urlConn.setRequestMethod("POST"); urlConn.setAllowUserInteraction(false); urlConn.setDoOutput(true); urlConn.setRequestProperty("Content-type", "application/json"); urlConn.setRequestProperty("accept", "application/json"); urlConn.connect(); OutputStream os = urlConn.getOutputStream(); os.write(obj.toJSONString().getBytes()); os.close(); // Inspect response int responseCode = urlConn.getResponseCode(); if (responseCode == 200) { System.out.println("Status: 200"); InputStream inStream = urlConn.getInputStream(); data = convertStreamToString(inStream); System.out.println(data); } else { System.out.println(responseCode); data = "Status:" + responseCode; } } catch (MalformedURLException e) { System.out.println("URL not valid."); } catch (IOException e) { System.out.println("IOException: " + e.getMessage()); e.printStackTrace(); } return data; }
From source file:mayo.edu.server.JsonServiceImpl.java
/** * Make a REST call to retrieve XML response * @param endpoint/*from w ww . j a v a 2 s . c om*/ * @return */ private String makeRestCall(String endpoint) { HttpURLConnection request = null; BufferedReader rd = null; StringBuilder response = null; try { java.net.URL endpointUrl = new java.net.URL(endpoint); request = (java.net.HttpURLConnection) endpointUrl.openConnection(); request.setRequestMethod("GET"); rd = new java.io.BufferedReader(new java.io.InputStreamReader(request.getInputStream())); request.connect(); // read the response response = new StringBuilder(); String line = null; while ((line = rd.readLine()) != null) { response.append(line + '\n'); } // Finally, the connection is released and the response is processed request.disconnect(); rd.close(); System.out.println((response != null) ? response.toString() : "No Response"); } catch (MalformedURLException e) { System.out.println("Exception: " + e.getMessage()); // e.printStackTrace(); } catch (ProtocolException e) { System.out.println("Exception: " + e.getMessage()); // e.printStackTrace(); } catch (IOException e) { System.out.println("Exception: " + e.getMessage()); // e.printStackTrace(); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); // e.printStackTrace(); } finally { try { request.disconnect(); } catch (Exception e) { } if (rd != null) { try { rd.close(); } catch (IOException ex) { } rd = null; } } return response.toString(); }
From source file:com.seleniumtests.browserfactory.SauceLabsDriverFactory.java
@Override protected WebDriver createNativeDriver() { MutableCapabilities capabilities = createCapabilities(); capabilities.merge(driverOptions);/*from w w w.ja v a2 s . com*/ try { if ("android".equalsIgnoreCase(webDriverConfig.getPlatform())) { return new AndroidDriver<WebElement>(new URL(webDriverConfig.getHubUrl().get(0)), capabilities); } else if ("ios".equalsIgnoreCase(webDriverConfig.getPlatform())) { return new IOSDriver<WebElement>(new URL(webDriverConfig.getHubUrl().get(0)), capabilities); } else { return new RemoteWebDriver(new URL(webDriverConfig.getHubUrl().get(0)), capabilities); } } catch (MalformedURLException e) { throw new DriverExceptions("Error creating driver: " + e.getMessage()); } }
From source file:com.exxatools.monitoring.jmx.JmxStatsCli.java
@CliCommand(value = "stats", help = "Collect statistics information from a JMX source") public void stats( @CliOption(key = { LONG_OPT_SERVICE_URL, OPT_SERVICE_URL }, mandatory = true, help = HELP_SERVICE_URL) String serviceUrl, @CliOption(key = { LONG_OPT_OBJECT_NAME, OPT_OBJECT_NAME }, mandatory = true, help = HELP_OBJECT_NAME) String objectName, @CliOption(key = { LONG_OPT_ATTRIBUTE_NAME, OPT_ATTRIBUTE_NAME }, mandatory = true, help = HELP_ATTRIBUTE_NAME) String attributeName, @CliOption(key = { LONG_OPT_USERNAME, OPT_USERNAME }, mandatory = false, help = HELP_USERNAME, specifiedDefaultValue = "", unspecifiedDefaultValue = "") String username, @CliOption(key = { LONG_OPT_PASSWORD, OPT_PASSWORD }, mandatory = false, help = HELP_PASSWORD, specifiedDefaultValue = "", unspecifiedDefaultValue = "") String password, @CliOption(key = { LONG_OPT_INTERVAL, OPT_INTERVAL }, mandatory = false, help = HELP_INTERVAL, specifiedDefaultValue = "250", unspecifiedDefaultValue = "250") long interval, @CliOption(key = { LONG_OPT_LINES, OPT_LINES }, mandatory = false, help = HELP_LINES, specifiedDefaultValue = "0", unspecifiedDefaultValue = "0") int linesHeading, @CliOption(key = { LONG_OPT_TIMESTAMP, OPT_TIMESTAMP }, mandatory = false, help = HELP_TIMESTAMP, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean showTimestamp, @CliOption(key = { LONG_OPT_UNIXTIME, OPT_UNIXTIME }, mandatory = false, help = HELP_UNIXTIME, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean showUnixTime) { try {// w w w . ja v a2 s. c o m // a few more sanity checks if (interval < 250) { Output.OUT.println("Warning: interval value too small, setting to 250"); interval = 250; } if (linesHeading < 0) { Output.OUT.println("Warning: lines value too small, setting to 0"); interval = 0; } // finally, find and start the tool JmxStats jmxStats = (JmxStats) applicationContext.getBean(MAIN_BEAN_NAME); jmxStats.setServiceUrl(serviceUrl); jmxStats.setObjectName(objectName); jmxStats.setAttributeName(attributeName); jmxStats.setUsername(username); jmxStats.setPassword(password); jmxStats.setIntervalMilliseconds(interval); jmxStats.setLinesHeading(linesHeading); jmxStats.setShowTimestamp(showTimestamp); jmxStats.setShowUnixTime(showUnixTime); jmxStats.run(); } catch (MalformedURLException e) { Output.OUT.println("Service URL incorrect: " + e.getMessage()); LOGGER.error("Service URL malformed: " + serviceUrl, e); } catch (MalformedObjectNameException e) { Output.OUT.println("Object name incorrect: " + e.getMessage()); LOGGER.error("Object name malformed: " + objectName, e); } catch (Exception e) { Output.OUT.println("Unexpected error occurred: " + e.getMessage()); LOGGER.error("Unexpected error occurred", e); } }
From source file:com.acrutiapps.browser.tasks.SearchUrlTask.java
@Override protected String doInBackground(Void... params) { publishProgress(0);/*from w w w. ja va2 s . co m*/ String message = null; HttpURLConnection c = null; try { URL url = new URL("http://anasthase.github.com/TintBrowser/search-engines.json"); c = (HttpURLConnection) url.openConnection(); c.connect(); int responseCode = c.getResponseCode(); if (responseCode == 200) { StringBuilder sb = new StringBuilder(); InputStream is = c.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { sb.append(line); } publishProgress(1); JSONArray jsonArray = new JSONArray(sb.toString()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String groupName = jsonObject.getString("group"); SearchUrlGroup group = mResults.get(groupName); if (group == null) { group = new SearchUrlGroup(groupName); mResults.put(groupName, group); } JSONArray items = jsonObject.getJSONArray("items"); for (int j = 0; j < items.length(); j++) { JSONObject item = items.getJSONObject(j); group.addItem(item.getString("name"), item.getString("url")); } } } else { message = String.format(mContext.getString(R.string.SearchUrlBadResponseCodeMessage), Integer.toString(responseCode)); } } catch (MalformedURLException e) { message = e.getMessage(); } catch (IOException e) { message = e.getMessage(); } catch (JSONException e) { message = e.getMessage(); } finally { if (c != null) { c.disconnect(); } } return message; }
From source file:com.gisgraphy.domain.geoloc.service.fulltextsearch.SolrClient.java
/** * @param solrUrl/*from w w w . j a va 2 s . com*/ * The solr URL of the server to connect */ @Autowired public SolrClient(@Qualifier("fulltextSearchUrl") String solrUrl, @Qualifier("multiThreadedHttpConnectionManager") MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager) { try { Assert.notNull(solrUrl, "solrClient does not accept null solrUrl"); Assert.notNull(multiThreadedHttpConnectionManager, "solrClient does not accept null multiThreadedHttpConnectionManager"); this.multiThreadedHttpConnectionManager = multiThreadedHttpConnectionManager; this.server = new CommonsHttpSolrServer(new URL(solrUrl), new HttpClient(multiThreadedHttpConnectionManager)); this.URL = !solrUrl.endsWith("/") ? solrUrl + "/" : solrUrl; logger.info("connecting to solr on " + this.URL + "..."); } catch (MalformedURLException e) { throw new RuntimeException("Error connecting to Solr! : " + e.getMessage()); } }
From source file:be.fedict.trust.service.bean.TrustServiceTrustLinker.java
private String getCrlUrl(X509Certificate childCertificate) { URI crlUri = CrlTrustLinker.getCrlUri(childCertificate); if (null == crlUri) { LOG.warn("No CRL uri for: " + childCertificate.getIssuerX500Principal().toString()); return null; }/*ww w . ja va2 s.c o m*/ try { return crlUri.toURL().toString(); } catch (MalformedURLException e) { LOG.warn("malformed URL: " + e.getMessage(), e); return null; } }
From source file:BackgroundGeometry.java
public void init() { if (bgImage == null) { // the path to the image for an applet try {/* ww w .j a v a 2 s . c o m*/ bgImage = new java.net.URL(getCodeBase().toString() + "/bg.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform(); // Create the rotate behavior node MouseRotate behavior1 = new MouseRotate(viewTrans); scene.addChild(behavior1); behavior1.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(viewTrans); scene.addChild(behavior2); behavior2.setSchedulingBounds(bounds); // Create the translate behavior node MouseTranslate behavior3 = new MouseTranslate(viewTrans); scene.addChild(behavior3); behavior3.setSchedulingBounds(bounds); // Let Java 3D perform optimizations on this scene graph. scene.compile(); u.addBranchGraph(scene); }
From source file:com.longwei.project.sso.client.util.HttpClient.java
public boolean isValidEndPoint(final String url) { try {//from w w w . ja v a 2s . co m final URL u = new URL(url); return isValidEndPoint(u); } catch (final MalformedURLException e) { log.error(e.getMessage(), e); return false; } }
From source file:com.netspective.sparx.fileupload.FileUploadFilter.java
/** * This method is called by the server before the filter goes into service, * and here it determines the file upload directory. * * @param <b>config</b> The filter config passed by the servlet engine *//*w ww. j a v a 2s . co m*/ public void init(FilterConfig config) throws ServletException { String tryDirectoryNames = config.getInitParameter(FILTERPARAM_UPLOAD_DIRS); // comma-separated list of directories to try if (tryDirectoryNames != null) { // find the first available directory either as a resource or a physical directory String[] tryDirectories = TextUtils.getInstance().split(tryDirectoryNames, ",", true); for (int i = 0; i < tryDirectories.length; i++) { String tryDirectory = tryDirectories[i]; try { // first try the directory as a servlet resource java.net.URL uploadDirURL = config.getServletContext().getResource(tryDirectory); if (uploadDirURL != null && uploadDirURL.getFile() != null) { uploadDir = uploadDirURL.getFile(); break; } File f = new File(tryDirectory); if (f.exists()) { uploadDir = f.getAbsolutePath(); break; } } catch (java.net.MalformedURLException ex) { throw new ServletException(ex.getMessage()); } } } // If upload directory parameter is null, assign a temp directory if (uploadDir == null) { File tempdir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"); if (tempdir != null) { uploadDir = tempdir.toString(); } else { throw new ServletException("Error in FileUploadFilter : No upload " + "directory found: set an uploadDir init " + "parameter or ensure the " + "javax.servlet.context.tempdir directory " + "is valid"); } } uploadPrefix = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_PREFIX); if (uploadPrefix == null) uploadPrefix = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_PREFIX; log.info("uploadPrefix is: " + uploadPrefix); uploadFileArg = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_REQUEST_ATTR_NAME); if (uploadFileArg == null) uploadFileArg = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_REQUEST_ATTR_NAME; log.info("uploadFileArg is: " + uploadFileArg); }