List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:net.sourceforge.dita4publishers.tools.dxp.DitaDxpHelper.java
/** * Given a DITA map bounded object set, zips it up into a DXP Zip package. * @param mapBos/*from w ww .j a va2 s . c o m*/ * @param outputZipFile * @throws Exception */ public static void zipMapBos(DitaBoundedObjectSet mapBos, File outputZipFile, MapBosProcessorOptions options) throws Exception { /* * Some potential complexities: * * - DXP package spec requires either a map manifest or that * there be exactly one map at the root of the zip package. This * means that the file structure of the BOS needs to be checked to * see if the files already conform to this structure and, if not, * they need to be reorganized and have pointers rewritten if a * map manifest has not been requested. * * - If the file structure of the original data includes files not * below the root map, the file organization must be reworked whether * or not a map manifest has been requested. * * - Need to generate DXP map manifest if a manifest is requested. * * - If user has requested that the original file structure be * remembered, a manifest must be generated. */ log.debug("Determining zip file organization..."); BosVisitor visitor = new DxpFileOrganizingBosVisitor(); visitor.visit(mapBos); if (!options.isQuiet()) log.info("Creating DXP package \"" + outputZipFile.getAbsolutePath() + "\"..."); OutputStream outStream = new FileOutputStream(outputZipFile); ZipOutputStream zipOutStream = new ZipOutputStream(outStream); ZipEntry entry = null; // At this point, URIs of all members should reflect their // storage location within the resulting DXP package. There // must also be a root map, either the original map // we started with or a DXP manifest map. URI rootMapUri = mapBos.getRoot().getEffectiveUri(); URI baseUri = null; try { baseUri = AddressingUtil.getParent(rootMapUri); } catch (URISyntaxException e) { throw new BosException("URI syntax exception getting parent URI: " + e.getMessage()); } Set<String> dirs = new HashSet<String>(); if (!options.isQuiet()) log.info("Constructing DXP package..."); for (BosMember member : mapBos.getMembers()) { if (!options.isQuiet()) log.info("Adding member " + member + " to zip..."); URI relativeUri = baseUri.relativize(member.getEffectiveUri()); File temp = new File(relativeUri.getPath()); String parentPath = temp.getParent(); if (parentPath != null && !"".equals(parentPath) && !parentPath.endsWith("/")) { parentPath += "/"; } log.debug("parentPath=\"" + parentPath + "\""); if (!"".equals(parentPath) && parentPath != null && !dirs.contains(parentPath)) { entry = new ZipEntry(parentPath); zipOutStream.putNextEntry(entry); zipOutStream.closeEntry(); dirs.add(parentPath); } entry = new ZipEntry(relativeUri.getPath()); zipOutStream.putNextEntry(entry); IOUtils.copy(member.getInputStream(), zipOutStream); zipOutStream.closeEntry(); } zipOutStream.close(); if (!options.isQuiet()) log.info("DXP package \"" + outputZipFile.getAbsolutePath() + "\" created."); }
From source file:io.druid.server.AsyncQueryForwardingServlet.java
protected static URI makeURI(String scheme, String host, String requestURI, String rawQueryString) { try {//from w ww.j a v a 2 s . c o m return new URIBuilder().setScheme(scheme).setHost(host).setPath(requestURI) // No need to encode-decode queryString, it is already encoded .setQuery(rawQueryString).build(); } catch (URISyntaxException e) { log.error(e, "Unable to rewrite URI [%s]", e.getMessage()); throw Throwables.propagate(e); } }
From source file:com.cloud.utils.UriUtils.java
public static String getUpdateUri(String url, boolean encrypt) { String updatedPath = null;//www . j a v a2 s .c om try { String query = URIUtil.getQuery(url); URIBuilder builder = new URIBuilder(url); builder.removeQuery(); StringBuilder updatedQuery = new StringBuilder(); List<NameValuePair> queryParams = getUserDetails(query); ListIterator<NameValuePair> iterator = queryParams.listIterator(); while (iterator.hasNext()) { NameValuePair param = iterator.next(); String value = null; if ("password".equalsIgnoreCase(param.getName()) && param.getValue() != null) { value = encrypt ? DBEncryptionUtil.encrypt(param.getValue()) : DBEncryptionUtil.decrypt(param.getValue()); } else { value = param.getValue(); } if (updatedQuery.length() == 0) { updatedQuery.append(param.getName()).append('=').append(value); } else { updatedQuery.append('&').append(param.getName()).append('=').append(value); } } String schemeAndHost = ""; URI newUri = builder.build(); if (newUri.getScheme() != null) { schemeAndHost = newUri.getScheme() + "://" + newUri.getHost(); } updatedPath = schemeAndHost + newUri.getPath() + "?" + updatedQuery; } catch (URISyntaxException e) { throw new CloudRuntimeException("Couldn't generate an updated uri. " + e.getMessage()); } return updatedPath; }
From source file:com.taobao.datax.plugins.common.DFSUtils.java
/** * Get {@link Configuration}.//from www.j a v a2 s . c o m * * @param dir * directory path in hdfs * * @param ugi * hadoop ugi * * @param conf * hadoop-site.xml path * * @return {@link Configuration} * * @throws java.io.IOException*/ public static Configuration getConf(String dir, String ugi, String conf) throws IOException { URI uri = null; Configuration cfg = null; String scheme = null; try { uri = new URI(dir); scheme = uri.getScheme(); if (null == scheme) { throw new IOException("HDFS Path missing scheme, check path begin with hdfs://ip:port/ ."); } cfg = confs.get(scheme); } catch (URISyntaxException e) { throw new IOException(e.getMessage(), e.getCause()); } if (cfg == null) { cfg = new Configuration(); cfg.setClassLoader(DFSUtils.class.getClassLoader()); List<String> configs = new ArrayList<String>(); if (!StringUtils.isBlank(conf) && new File(conf).exists()) { configs.add(conf); } else { /* * For taobao internal use e.g. if bazhen.csy start a new datax * job, datax will use /home/bazhen.csy/config/hadoop-site.xml * as configuration xml */ String confDir = System.getenv("HADOOP_CONF_DIR"); if (null == confDir) { //for taobao internal use, it is ugly configs.add(System.getProperty("user.home") + "/config/hadoop-site.xml"); } else { //run in hadoop-0.19 if (new File(confDir + "/hadoop-site.xml").exists()) { configs.add(confDir + "/hadoop-site.xml"); } else { configs.add(confDir + "/core-default.xml"); configs.add(confDir + "/core-site.xml"); } } } for (String config : configs) { log.info(String.format("HdfsReader use %s for hadoop configuration .", config)); cfg.addResource(new Path(config)); } /* commented by bazhen.csy */ // log.info("HdfsReader use default ugi " + // cfg.get(ParamsKey.HdfsReader.ugi)); if (uri.getScheme() != null) { String fsname = String.format("%s://%s:%s", uri.getScheme(), uri.getHost(), uri.getPort()); log.info("fs.default.name=" + fsname); cfg.set("fs.default.name", fsname); } if (ugi != null) { cfg.set("hadoop.job.ugi", ugi); /* * commented by bazhen.csy log.info("use specification ugi:" + * cfg.get(ParamsKey.HdfsReader.ugi)); */ } confs.put(scheme, cfg); } return cfg; }
From source file:controllers.Common.java
@Util public static String toSafeRedirectURL(String url) { String cleanUrl = ""; try {/*from w w w . j av a 2s. c o m*/ // Remove Host and port from referrer URI uriObject = new URI(url); cleanUrl += uriObject.getPath(); String query = uriObject.getQuery(); if (!StringUtils.isBlank(query)) { cleanUrl += "?" + query; } } catch (URISyntaxException ignore) { Logger.error(ignore.getMessage()); } return cleanUrl; }
From source file:com.ibm.stocator.fs.common.Utils.java
public static boolean validSchema(String path) throws IOException { try {// w w w .j a v a2 s .c o m return validSchema(new URI(path)); } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } }
From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.tools.R2RMLToolkit.java
/** * The URL-safe version of a string is obtained by an URL encoding to a * string value./*from w w w . jav a 2s . co m*/ * * @throws R2RMLDataError * @throws MalformedURLException */ public static String getURLSafeVersion(String value) throws R2RMLDataError { if (value == null) return null; URL url = null; try { url = new URL(value); } catch (MalformedURLException mue) { // This template should be not a url : no encoding return value; } // No exception raised, this template is a valid url : perform // percent-encoding try { java.net.URI uri = new java.net.URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef()); String result = uri.toURL().toString(); // Percent encoding : complete with no supported char in this // treatment result = result.replaceAll("\\,", "%2C"); return result; } catch (URISyntaxException e) { throw new R2RMLDataError("[R2RMLToolkit:getIRISafeVersion] This value " + value + " can not be percent-encoded because " + e.getMessage()); } catch (MalformedURLException e) { throw new R2RMLDataError("[R2RMLToolkit:getIRISafeVersion] This value " + value + " can not be percent-encoded because " + e.getMessage()); } }
From source file:password.pwm.http.servlet.oauth.OAuthMachine.java
public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) { final String debugSource; final String redirect_uri; {/*from w w w . ja va2 s . c o m*/ final String returnUrlOverride = pwmRequest.getConfig() .readAppProperty(AppProperty.OAUTH_RETURN_URL_OVERRIDE); final String siteURL = pwmRequest.getConfig().readSettingAsString(PwmSetting.PWM_SITE_URL); if (returnUrlOverride != null && !returnUrlOverride.trim().isEmpty()) { debugSource = "AppProperty(\"" + AppProperty.OAUTH_RETURN_URL_OVERRIDE.getKey() + "\")"; redirect_uri = returnUrlOverride + PwmServletDefinition.OAuthConsumer.servletUrl(); } else if (siteURL != null && !siteURL.trim().isEmpty()) { debugSource = "SiteURL Setting"; redirect_uri = siteURL + PwmServletDefinition.OAuthConsumer.servletUrl(); } else { debugSource = "Input Request URL"; final String inputURI = pwmRequest.getHttpServletRequest().getRequestURL().toString(); try { final URI requestUri = new URI(inputURI); final int port = requestUri.getPort(); redirect_uri = requestUri.getScheme() + "://" + requestUri.getHost() + (port > 0 && port != 80 && port != 443 ? ":" + requestUri.getPort() : "") + pwmRequest.getContextPath() + PwmServletDefinition.OAuthConsumer.servletUrl(); } catch (URISyntaxException e) { throw new IllegalStateException( "unable to parse inbound request uri while generating oauth redirect: " + e.getMessage()); } } } LOGGER.trace("calculated oauth self end point URI as '" + redirect_uri + "' using method " + debugSource); return redirect_uri; }
From source file:org.apache.hadoop.hive.ql.parse.EximUtil.java
/** * Initialize the URI where the exported data collection is * to created for export, or is present for import */// www . j a va 2 s .co m public static URI getValidatedURI(HiveConf conf, String dcPath) throws SemanticException { try { boolean testMode = conf.getBoolVar(HiveConf.ConfVars.HIVETESTMODE); URI uri = new Path(dcPath).toUri(); FileSystem fs = FileSystem.get(uri, conf); // Get scheme from FileSystem String scheme = fs.getScheme(); String authority = uri.getAuthority(); String path = uri.getPath(); LOG.info("Path before norm :" + path); // generate absolute path relative to home directory if (!path.startsWith("/")) { if (testMode) { path = (new Path(System.getProperty("test.tmp.dir"), path)).toUri().getPath(); } else { path = (new Path(new Path("/user/" + System.getProperty("user.name")), path)).toUri().getPath(); } } // if scheme is specified but not authority then use the default authority if (StringUtils.isEmpty(authority)) { URI defaultURI = FileSystem.get(conf).getUri(); authority = defaultURI.getAuthority(); } LOG.info("Scheme:" + scheme + ", authority:" + authority + ", path:" + path); Collection<String> eximSchemes = conf .getStringCollection(HiveConf.ConfVars.HIVE_EXIM_URI_SCHEME_WL.varname); if (!eximSchemes.contains(scheme)) { throw new SemanticException( ErrorMsg.INVALID_PATH.getMsg("only the following file systems accepted for export/import : " + conf.get(HiveConf.ConfVars.HIVE_EXIM_URI_SCHEME_WL.varname))); } try { return new URI(scheme, authority, path, null, null); } catch (URISyntaxException e) { throw new SemanticException(ErrorMsg.INVALID_PATH.getMsg(), e); } } catch (IOException e) { throw new SemanticException(ErrorMsg.IO_ERROR.getMsg() + ": " + e.getMessage(), e); } }
From source file:org.unitedinternet.cosmo.dav.caldav.report.MultigetReport.java
private static URL normalizeHref(URL context, String href) throws CosmoDavException { URL url = null;//w ww. ja v a 2 s . com try { url = new URL(context, href); // check that the URL is escaped. it's questionable whether or // not we should all unescaped URLs, but at least as of // 10/02/2007, iCal 3.0 generates them url.toURI(); return url; } catch (URISyntaxException e) { try { URI escaped = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef()); return new URL(escaped.toString()); } catch (URISyntaxException | MalformedURLException e2) { throw new BadRequestException("Malformed unescaped href " + href + ": " + e.getMessage()); } } catch (MalformedURLException e) { throw new BadRequestException("Malformed href " + href + ": " + e.getMessage()); } }