List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:org.rhq.modules.plugins.wildfly10.ASUploadConnection.java
private URI buildUploadUri() { try {/*from w ww. j a va 2s.c o m*/ return new URIBuilder() // .setScheme(asConnectionParams.isSecure() ? ASConnection.HTTPS_SCHEME : ASConnection.HTTP_SCHEME) // .setHost(asConnectionParams.getHost()) // .setPort(asConnectionParams.getPort()) // .setPath(UPLOAD_URI) // .build(); } catch (URISyntaxException e) { throw new RuntimeException("Could not build upload URI: " + e.getMessage(), e); } }
From source file:org.apache.hadoop.metrics2.sink.WindowsAzureTableSink.java
@Override public void putMetrics(MetricsRecord record) { SimpleDateFormat formatter = new SimpleDateFormat(partitionKeyTimeFormat); String partitionKeySuffix = formatter.format(new java.util.Date()); if (StringUtils.isEmpty(tableName)) { // Note: Azure Tables can only contain alpha-numeric values // assume table name is context + record if it is not specified in the property tableName = record.context().toUpperCase() + record.name(); }/*from ww w . j av a 2s. c o m*/ String partitionKey; HashMap<String, String> metrics2KeyValuePairs = new HashMap<String, String>(); metrics2KeyValuePairs.put("MetricTimestamp", String.valueOf(record.timestamp())); metrics2KeyValuePairs.put("Context", record.context()); metrics2KeyValuePairs.put("Name", record.name()); metrics2KeyValuePairs.put("IPAddress", getLocalNodeIPAddress()); if (logDeploymentIdWithMetrics) { metrics2KeyValuePairs.put("DeploymentId", deploymentId); metrics2KeyValuePairs.put("Role", roleName); metrics2KeyValuePairs.put("RoleInstance", roleInstanceName); partitionKey = deploymentId + "-" + roleName + "-" + partitionKeySuffix; } else { partitionKey = getLocalNodeName(); } for (MetricsTag tag : record.tags()) { metrics2KeyValuePairs.put(tag.name(), String.valueOf(tag.value())); } for (AbstractMetric metric : record.metrics()) { metrics2KeyValuePairs.put(metric.name(), metric.value().toString()); } // Using a guid as the rowkey to guarantee uniqueness AzureTableMetrics2Entity metrics2Entity = new AzureTableMetrics2Entity(partitionKey, UUID.randomUUID().toString()); metrics2Entity.setMetrics2KeyValuePairs(metrics2KeyValuePairs); CloudTableClient tableClient; try { tableClient = getTableClient(tableName); } catch (StorageException storageException) { logger.error(String.format("getTableClient failed. Details: %s, %s", storageException.getMessage(), storageException)); return; } catch (URISyntaxException syntaxException) { logger.error(String.format("getTableClient failed. Details: %s, %s", syntaxException.getMessage(), syntaxException)); return; } TableOperation insertMetricOperation = TableOperation.insert(metrics2Entity, true); try { TableRequestOptions requestOptions = new TableRequestOptions(); requestOptions.setTablePayloadFormat(TablePayloadFormat.AtomPub); tableClient.execute(tableName, insertMetricOperation, requestOptions, null); } catch (StorageException storageException) { logger.error(String.format("tableClient.execute failed. Details: %s, %s", storageException.getMessage(), storageException)); return; } }
From source file:com.cloud.storage.template.HttpTemplateDownloader.java
private Pair<String, Integer> validateUrl(String url) throws IllegalArgumentException { try {/*from w w w .j a v a2s . c om*/ URI uri = new URI(url); if (!uri.getScheme().equalsIgnoreCase("http") && !uri.getScheme().equalsIgnoreCase("https")) { throw new IllegalArgumentException("Unsupported scheme for url"); } int port = uri.getPort(); if (!(port == 80 || port == 443 || port == -1)) { throw new IllegalArgumentException("Only ports 80 and 443 are allowed"); } if (port == -1 && uri.getScheme().equalsIgnoreCase("https")) { port = 443; } else if (port == -1 && uri.getScheme().equalsIgnoreCase("http")) { port = 80; } String host = uri.getHost(); try { InetAddress hostAddr = InetAddress.getByName(host); if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) { throw new IllegalArgumentException("Illegal host specified in url"); } if (hostAddr instanceof Inet6Address) { throw new IllegalArgumentException( "IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")"); } return new Pair<String, Integer>(host, port); } catch (UnknownHostException uhe) { throw new IllegalArgumentException("Unable to resolve " + host); } } catch (IllegalArgumentException iae) { s_logger.warn("Failed uri validation check: " + iae.getMessage()); throw iae; } catch (URISyntaxException use) { s_logger.warn("Failed uri syntax check: " + use.getMessage()); throw new IllegalArgumentException(use.getMessage()); } }
From source file:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java
/** * Test method for {@link info.rmapproject.core.model.impl.openrdf.ORMapDiSCO#ORMapDiSCO(RMapIri, java.util.List)}. * @throws RMapDefectiveArgumentException * @throws RMapException /*ww w .j a va2 s . c o m*/ */ @Test public void testORMapDiSCORMapResourceListOfURI() throws RMapException, RMapDefectiveArgumentException { List<java.net.URI> resourceList = new ArrayList<java.net.URI>(); try { resourceList.add(new java.net.URI("http://rmap-info.org")); resourceList.add(new java.net.URI("https://rmap-project.atlassian.net/wiki/display/RMAPPS/RMap+Wiki")); RMapIri author = ORAdapter.openRdfIri2RMapIri(creatorIRI); ORMapDiSCO disco = new ORMapDiSCO(author, resourceList); assertEquals(author.toString(), disco.getCreator().getStringValue()); List<Statement> resources = disco.getAggregatedResourceStatements(); assertEquals(2, resources.size()); Model model = new LinkedHashModel(); model.addAll(resources); Set<IRI> predicates = model.predicates(); assertEquals(1, predicates.size()); assertTrue(predicates.contains(ORE.AGGREGATES)); Set<Value> objects = model.objects(); assertTrue(objects.contains(r)); assertTrue(objects.contains(r2)); Statement cstmt = disco.getCreatorStmt(); assertEquals(DCTERMS.CREATOR, cstmt.getPredicate()); } catch (URISyntaxException e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:sit.web.client.HttpHelper.java
/** * * * @param method//from ww w .jav a 2s . co m * @param host * @param port * @param path * @param payload * @param mimeType mimetype as string e.g. "application/json" will be added * to the content type of the http call * @param charSet set charSet to null to omit sending a char flag (e.g. for * binary files) * @param isHTTPS * @param unamePword64 * @return * @throws MalformedURLException * @throws ProtocolException * @throws IOException */ public HTTPResponse doHTTPRequest(String method, String host, int port, String path, String payload, String mimeType, Charset charSet, boolean isHTTPS, String unamePword64) throws MalformedURLException, ProtocolException, IOException { if (mimeType == null || mimeType.length() == 0) { mimeType = MimeTypes.getMimeType(""); //get unknown mime type if mimetype not set } String contentType = mimeType; if (charSet != null) { contentType += HttpConstants.SUB_FIELD_SEPARATOR + HttpConstants.CHARSET_CONTENT_TYPE_TAG + charSet.name(); //text/html; charset=utf-8 //##CHARSET_MARKER## } else { charSet = Charset.defaultCharset(); } try { return doHTTPRequest(method, host, port, path, payload.getBytes(charSet), contentType, isHTTPS, unamePword64); } catch (URISyntaxException ex) { throw new MalformedURLException(ex.getMessage()); } }
From source file:org.rhq.modules.plugins.wildfly10.ASUploadConnection.java
private URI buildTriggerAuthUri() { try {/* www . j ava 2 s . c o m*/ return new URIBuilder() // .setScheme(asConnectionParams.isSecure() ? ASConnection.HTTPS_SCHEME : ASConnection.HTTP_SCHEME) // .setHost(asConnectionParams.getHost()) // .setPort(asConnectionParams.getPort()) // .setPath(TRIGGER_AUTH_URI) // .build(); } catch (URISyntaxException e) { throw new RuntimeException("Could not build auth trigger URI: " + e.getMessage(), e); } }
From source file:com.jkoolcloud.jesl.tnt4j.sink.JKCloudEventSink.java
@Override public synchronized void open() throws IOException { try {/*from w w w. j a va2 s .c o m*/ close(); logger.log(OpLevel.DEBUG, "Open name={3}, url={0}, proxy.host={1}, proxy.port={2}", url, proxyHost, proxyPort, this.getName()); jkHandle = new JKClient(url, proxyHost, proxyPort, logger); if (!StringUtils.isEmpty(accessToken)) { jkHandle.connect(accessToken); } else { jkHandle.connect(); } if (logSink != null && !logSink.isOpen()) { logSink.open(); } } catch (URISyntaxException e) { logger.log(OpLevel.ERROR, "Failed to open name={3}, url={0}, proxy.host={1}, proxy.port={2}", url, proxyHost, proxyPort, this.getName(), e); close(); throw new IOException(e.getMessage(), e); } }
From source file:com.dtolabs.client.utils.HttpClientChannel.java
/** * Process the URL based on the query params, and create the HttpURLConnection with appropriate headers for username * and password./* w ww.j av a 2 s . co m*/ */ protected void init(String uriSpec, Map query) throws CoreException { requestUrl = uriSpec; if (query != null && query.size() > 0) { requestUrl = constructURLQuery(uriSpec, query); } URI uri; try { uri = new URI(requestUrl); } catch (URISyntaxException e) { throw new CoreException(e.getMessage()); } requestURL = null; try { requestURL = uri.toURL(); } catch (MalformedURLException e) { throw new CoreException(e.getMessage()); } logger.debug("creating connection object to URL: " + requestUrl); httpc = new HttpClient(); }
From source file:org.apache.fop.apps.FOURIResolver.java
/** * Checks if the given base URL is acceptable. It also normalizes the URL. * @param base the base URL to check/*from w ww .j a v a2 s . com*/ * @return the normalized URL * @throws MalformedURLException if there's a problem with a file URL */ public String checkBaseURL(String base) throws MalformedURLException { // replace back slash with forward slash to ensure windows file:/// URLS are supported base = base.replace('\\', '/'); if (!base.endsWith("/")) { // The behavior described by RFC 3986 regarding resolution of relative // references may be misleading for normal users: // file://path/to/resources + myResource.res -> file://path/to/myResource.res // file://path/to/resources/ + myResource.res -> file://path/to/resources/myResource.res // We assume that even when the ending slash is missing, users have the second // example in mind base += "/"; } File dir = new File(base); if (dir.isDirectory()) { return dir.toURI().toASCIIString(); } else { URI baseURI; try { baseURI = new URI(base); String scheme = baseURI.getScheme(); boolean directoryExists = true; if ("file".equals(scheme)) { dir = FileUtils.toFile(baseURI.toURL()); directoryExists = dir.isDirectory(); } if (scheme == null || !directoryExists) { String message = "base " + base + " is not a valid directory"; if (throwExceptions) { throw new MalformedURLException(message); } log.error(message); } return baseURI.toASCIIString(); } catch (URISyntaxException e) { //TODO not ideal: our base URLs are actually base URIs. throw new MalformedURLException(e.getMessage()); } } }