List of usage examples for java.net URISyntaxException URISyntaxException
public URISyntaxException(String input, String reason)
From source file:org.apache.any23.servlet.Servlet.java
private DocumentSource createHTTPDocumentSource(WebResponder responder, String uri, boolean report) throws IOException { try {//from www . j a va 2s . com if (!isValidIRI(uri)) { throw new URISyntaxException(uri, "@@@"); } return createHTTPDocumentSource(responder.getRunner().getHTTPClient(), uri); } catch (URISyntaxException ex) { LOG.error("Invalid IRI detected", ex); responder.sendError(400, "Invalid input IRI " + uri, report); return null; } }
From source file:com.falcon.orca.actors.Generator.java
private HttpUriRequest prepareRequest() throws URISyntaxException, JsonProcessingException { HttpUriRequest request;// www.j a va2 s . c o m switch (method) { case POST: { String postUrl = isUrlDynamic ? dataStore.fillURLWithData() : url; AbstractHttpEntity postData; try { postData = isBodyDynamic ? new StringEntity(dataStore.fillTemplateWithData(), StandardCharsets.UTF_8) : new ByteArrayEntity(staticRequestData == null ? new byte[0] : staticRequestData); } catch (IllegalArgumentException ile) { postData = new ByteArrayEntity(new byte[0]); log.error("Post body is null, sending blank."); } request = new HttpPost(postUrl); ((HttpPost) request).setEntity(postData); break; } case GET: { String getUrl = isUrlDynamic ? dataStore.fillURLWithData() : url; request = new HttpGet(getUrl); break; } case PUT: { String putUrl = isUrlDynamic ? dataStore.fillURLWithData() : url; AbstractHttpEntity putData; try { putData = isBodyDynamic ? new StringEntity(dataStore.fillTemplateWithData(), StandardCharsets.UTF_8) : new ByteArrayEntity(staticRequestData == null ? new byte[0] : staticRequestData); } catch (IllegalArgumentException ile) { putData = new ByteArrayEntity(new byte[0]); log.error("Post body is null, sending blank."); } request = new HttpPut(putUrl); ((HttpPut) request).setEntity(putData); break; } case DELETE: { String deleteUrl = isUrlDynamic ? dataStore.fillURLWithData() : url; request = new HttpDelete(deleteUrl); break; } case OPTIONS: { String optionsUrl = isUrlDynamic ? dataStore.fillURLWithData() : url; request = new HttpOptions(optionsUrl); break; } case HEAD: { String headUrl = isUrlDynamic ? dataStore.fillURLWithData() : url; request = new HttpHead(headUrl); break; } default: throw new URISyntaxException(url + ":" + method, "Wrong method supplied, available methods are POST, " + "GET, PUT, DELETE, HEAD, OPTIONS"); } if (headers != null) { headers.forEach(request::addHeader); } return request; }
From source file:edu.harvard.hul.ois.drs.pdfaconvert.PdfaConvert.java
private static void loadApplicationPropertiesFile() { // Set the projects properties. // First look for a system property pointing to a project properties file. // This value can be either a file path, file protocol (e.g. - file:/path/to/file), // or a URL (http://some/server/file). // If this value either does not exist or is not valid, the default // file that comes with this application will be used for initialization. String environmentProjectPropsFile = System.getProperty(ApplicationConstants.ENV_PROJECT_PROPS); logger.info("Have {} from environment: {}", ApplicationConstants.PROJECT_PROPS, environmentProjectPropsFile); URI projectPropsUri = null;// w w w . j a va 2 s . c o m if (environmentProjectPropsFile != null) { try { projectPropsUri = new URI(environmentProjectPropsFile); // properties file needs a scheme in the URI so convert to file if necessary. if (null == projectPropsUri.getScheme()) { File projectProperties = new File(environmentProjectPropsFile); if (projectProperties.exists() && projectProperties.isFile()) { projectPropsUri = projectProperties.toURI(); } else { // No scheme and not a file - yikes!!! Let's bail and // use fall-back file. projectPropsUri = null; throw new URISyntaxException(environmentProjectPropsFile, "Not a valid file"); } } } catch (URISyntaxException e) { // fall back to default file logger.error("Unable to load properties file: {} -- reason: {}", environmentProjectPropsFile, e.getReason()); logger.error("Falling back to default {} file: {}", ApplicationConstants.PROJECT_PROPS, ApplicationConstants.PROJECT_PROPS); } } applicationProps = new Properties(); // load properties if environment value set if (projectPropsUri != null) { File envPropFile = new File(projectPropsUri); if (envPropFile.exists() && envPropFile.isFile() && envPropFile.canRead()) { Reader reader; try { reader = new FileReader(envPropFile); logger.info("About to load {} from environment: {}", ApplicationConstants.PROJECT_PROPS, envPropFile.getAbsolutePath()); applicationProps.load(reader); logger.info("Success -- loaded properties file."); } catch (IOException e) { logger.error("Could not load environment properties file: {}", projectPropsUri, e); // set URI back to null so default prop file loaded projectPropsUri = null; } } } if (projectPropsUri == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { InputStream resourceStream = loader.getResourceAsStream(ApplicationConstants.PROJECT_PROPS); applicationProps.load(resourceStream); logger.info("loaded default applicationProps: "); } catch (IOException e) { logger.error("Could not load properties file: {}", ApplicationConstants.PROJECT_PROPS, e); // couldn't load default properties so bail... throw new RuntimeException("Couldn't load an applications properties file.", e); } } }
From source file:org.gbif.ipt.service.registry.impl.RegistryManagerImplTest.java
@Test public void testGetExtensionsBadURLThrowsRegistryException() throws IOException, URISyntaxException, SAXException, ParserConfigurationException { // mock response HttpUtil as URISyntaxException when(mockHttpUtil.get(anyString())).thenThrow(new URISyntaxException("httpgoog.c", "Wrong syntax!")); // create instance of RegistryManager RegistryManager manager = new RegistryManagerImpl(mockAppConfig, mockDataDir, mockHttpUtil, mockSAXParserFactory, mockConfigWarnings, mockSimpleTextProvider, mockRegistrationManager); // getExtensions() throws a RegistryException of type BAD_REQUEST try {/*ww w.j a v a 2 s .co m*/ manager.getExtensions(); } catch (RegistryException e) { LOG.info(e.getMessage()); assertEquals(RegistryException.TYPE.BAD_REQUEST, e.getType()); } }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Checks whether the given URL string begins with a protocol (http://, * ftp://, etc.) If it does, the string is returned unchanged. If it does * not, full URL is returned and is constructed as parentUrl "/" url. * * @param url input URL string in absolute or relative form * @param parentUrl base URL to use if the given URL is in relative form * @return an absolute URL/*from w ww.j a v a 2s . co m*/ */ public static URI relToAbs(String url, URI parentUrl) throws URISyntaxException { if (!StringUtils.hasLength(url)) { throw new URISyntaxException(url, "The input url was empty!"); } URI parent2 = new URI(parentUrl.getScheme(), parentUrl.getUserInfo(), parentUrl.getAuthority(), parentUrl.getPort(), parentUrl.getPath() + "/", // Parent URL path must end with "/" for // this to work. resolve() removes any // duplicates. parentUrl.getQuery(), parentUrl.getFragment()); return parent2.resolve(url.trim()); }
From source file:com.snaker.DownloadManager.java
public void start(final Downloader d) throws IOException { String host = null;/*w w w . j a va 2 s. com*/ try { URI uri = new URI(d.getUrl()); host = uri.getHost(); if (host != null) { host = host.toLowerCase(); } else { throw new URISyntaxException(d.getUrl(), "Bad url"); } } catch (URISyntaxException e) { throw new IOException(e); } d.setHost(host); downloadings.add(d); if (d.getHandler() == null) { createRunnable(d).run(); } else { queue.put(d); } }
From source file:org.rssowl.core.util.URIUtils.java
/** * Returns a new <code>URI</code> from the given one, that potentially points * to the favicon.ico./*from ww w .j a v a 2s . c om*/ * * @param link The Link to look for a favicon. * @param rewriteHost If <code>TRUE</code>, change the host for a better * result. * @return Returns the <code>URI</code> from the given one, that potentially * points to the favicon.ico. * @throws URISyntaxException In case of a malformed URI. */ public static URI toFaviconUrl(URI link, boolean rewriteHost) throws URISyntaxException { String host = safeGetHost(link); if (!StringUtils.isSet(host)) return null; /* Strip all but the last two segments from the Host */ if (rewriteHost) { String[] hostSegments = host.split("\\."); //$NON-NLS-1$ int len = hostSegments.length; /* Rewrite if conditions match */ if (len > 2 && !"www".equals(hostSegments[0])) //$NON-NLS-1$ host = hostSegments[len - 2] + "." + hostSegments[len - 1]; //$NON-NLS-1$ /* Rewrite failed, avoid reloading by throwing an exception */ else throw new URISyntaxException("", ""); //$NON-NLS-1$ //$NON-NLS-2$ } StringBuilder buf = new StringBuilder(); buf.append(HTTP); buf.append(host); buf.append("/favicon.ico"); //$NON-NLS-1$ return new URI(fastEncode(buf.toString())); }
From source file:com.provenance.cloudprovenance.storagecontroller.presistence.xmldb.XmlDbService.java
public String constructTraceabilityURI(String serviceId, String traceabilityType) throws URISyntaxException { if (serviceId == null || traceabilityType == null) throw new URISyntaxException("serviceId, provenanceId and provenanceType", "Missing information"); String URI = this.getStore() + "/" + serviceId + "/" + traceabilityType; logger.debug("Provenance relative URI ==> " + URI); return URI; }
From source file:org.cloudfoundry.maven.AbstractCloudFoundryMojo.java
/** * If the target property was provided via the command line, use that property. * Otherwise use the property that was injected via Maven. If that is Null * as well, Null is returned.// w w w .ja va 2 s . co m * * @return Returns the Cloud Foundry Target Url - Can return Null. * */ public URI getTarget() { final String targetProperty = getCommandlineProperty(SystemProperties.TARGET); if (targetProperty != null) { try { URI uri = new URI(targetProperty); if (uri.isAbsolute()) { return uri; } else { throw new URISyntaxException(targetProperty, "URI is not opaque."); } } catch (URISyntaxException e) { throw new IllegalStateException(String.format( "The Url parameter '%s' " + "which was passed in as system property is not valid.", targetProperty)); } } if (this.target == null) { return null; } try { return new URI(this.target); } catch (URISyntaxException e) { throw new IllegalStateException(String.format( "The Url parameter '%s' " + "which was passed in as pom.xml configiuration parameter is not valid.", this.target)); } }
From source file:org.codice.alliance.video.stream.mpegts.UdpStreamMonitor.java
/** * @param monitoredAddress must be non-null and resolvable *///from ww w. j ava2s . c o m public void setMonitoredAddress(String monitoredAddress) { notNull(monitoredAddress, "monitoredAddress must be non-null"); URI uri; try { uri = new URI(monitoredAddress); InetAddress.getByName(uri.getHost()); if (uri.getScheme() == null || !uri.getScheme().equals("udp")) { throw new URISyntaxException(uri.toString(), "Monitored Address is not UDP protocol"); } } catch (UnknownHostException | URISyntaxException e) { throw new IllegalArgumentException(String .format("the monitored address could not be resolved: monitoredAddress=%s", monitoredAddress)); } inclusiveBetween(MONITORED_PORT_MIN, MONITORED_PORT_MAX, uri.getPort()); this.streamUri = uri; this.monitoredPort = uri.getPort(); this.monitoredAddress = uri.getHost(); }