Java Code Examples for java.net.URISyntaxException#getMessage()

The following examples show how to use java.net.URISyntaxException#getMessage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void load(File aliasSpecificationFile) throws IOException {

        log.info("Loading aliases from file {}", aliasSpecificationFile);
        Properties properties = new Properties();
        try (InputStream stream = new FileInputStream(aliasSpecificationFile)) {
            properties.load(stream);
        }
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            String key = entry.getKey().toString();
            String value = entry.getValue().toString();
            if (key.startsWith(ALIAS_CONFIG_PREFIX) && !value.isEmpty()) {
                key = key.substring(ALIAS_CONFIG_PREFIX.length());

                try {
                    // validate URI
                    URI uri = new URI(value);
                    // log only part
                    log.info("Registering datasource alias '{}' for {}://{}****", key, uri.getScheme(), uri.getHost());

                    aliasMap.put(key, value);
                } catch (URISyntaxException err) {
                    throw new IllegalArgumentException("Failed to validate DSN for alias '" + key + "' - " + value + ", error: " + err.getMessage());
                }
            }
        }
    }
 
Example 2
/**
 * @param requestHeaders the client's supplied request headers. This class
 * creates a private copy that it can mutate.
 * @param connection the connection used for an intermediate response
 * immediately prior to this request/response pair, such as a same-host
 * redirect. This engine assumes ownership of the connection and must
 * release it when it is unneeded.
 */
public HttpEngine(HttpURLConnectionImpl policy, String method, RawHeaders requestHeaders,
    Connection connection, RetryableOutputStream requestBodyOut) throws IOException {
  this.policy = policy;
  this.method = method;
  this.connection = connection;
  this.requestBodyOut = requestBodyOut;

  try {
    uri = Platform.get().toUriLenient(policy.getURL());
  } catch (URISyntaxException e) {
    throw new IOException(e.getMessage());
  }

  this.requestHeaders = new RequestHeaders(uri, new RawHeaders(requestHeaders));
}
 
Example 3
private void authorizeCreateTable(PreCreateTableEvent context)
    throws InvalidOperationException, MetaException {
  HierarcyBuilder inputBuilder = new HierarcyBuilder();
  inputBuilder.addDbToOutput(getAuthServer(), context.getTable().getDbName());
  HierarcyBuilder outputBuilder = new HierarcyBuilder();
  outputBuilder.addDbToOutput(getAuthServer(), context.getTable().getDbName());

  if (!StringUtils.isEmpty(context.getTable().getSd().getLocation())) {
    String uriPath;
    try {
      uriPath = PathUtils.parseDFSURI(warehouseDir,
          getSdLocation(context.getTable().getSd()));
    } catch(URISyntaxException e) {
      throw new MetaException(e.getMessage());
    }
    inputBuilder.addUriToOutput(getAuthServer(), uriPath, warehouseDir);
  }
  authorizeMetastoreAccess(HiveOperation.CREATETABLE, inputBuilder.build(),
      outputBuilder.build());
}
 
Example 4
String fromAuthDomain(String authUri) {
    URI uri = URI.create(authUri);

    String host = uri.getHost();

    if (host == null) {
        throw new IllegalArgumentException("Unable to parse URI host from VCAP_SERVICES with label: \"" + PIVOTAL_SSO_LABEL + "\" and auth_domain: \"" + authUri + "\"");
    }

    String issuerHost = uri.getHost().replaceFirst("login\\.", "uaa.");

    try {
        return new URI(
                uri.getScheme(),
                uri.getUserInfo(),
                issuerHost,
                uri.getPort(),
                uri.getPath(),
                uri.getQuery(),
                uri.getFragment()
        ).toString();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 5
Source Project: woodstox   File: ValidatingStreamReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Method called to resolve path to external DTD subset, given
 * system identifier.
 */
private URI resolveExtSubsetPath(String systemId) throws IOException
{
    // Do we have a context to use for resolving?
    URL ctxt = (mInput == null) ? null : mInput.getSource();

    /* Ok, either got a context or not; let's create the URL based on
     * the id, and optional context:
     */
    if (ctxt == null) {
        /* Call will try to figure out if system id has the protocol
         * in it; if not, create a relative file, if it does, try to
         * resolve it.
         */
        return URLUtil.uriFromSystemId(systemId);
    }
    URL url = URLUtil.urlFromSystemId(systemId, ctxt);
    try {
        return new URI(url.toExternalForm());
    } catch (URISyntaxException e) { // should never occur...
        throw new IOException("Failed to construct URI for external subset, URL = "+url.toExternalForm()+": "+e.getMessage());
    }
}
 
Example 6
Source Project: microprofile-lra   File: LRAClientOps.java    License: Apache License 2.0 5 votes vote down vote up
private URI toURI(String lra) throws GenericLRAException {
    try {
        return new URI(lra);
    } catch (URISyntaxException e) {
        throw new GenericLRAException(null, e.getMessage(), e);
    }
}
 
Example 7
public static WsAddressingHeader createHeader(String mutualityToSendTo, String action, String messageId) throws TechnicalConnectorException {
   try {
      WsAddressingHeader getHeader = null;
      if (action == null) {
         getHeader = new WsAddressingHeader(new URI(""));
      } else {
         getHeader = new WsAddressingHeader(new URI(action));
      }

      getHeader.setFaultTo("http://www.w3.org/2005/08/addressing/anonymous");
      getHeader.setReplyTo("http://www.w3.org/2005/08/addressing/anonymous");
      if (messageId == null) {
         getHeader.setMessageID(new URI(IdGeneratorFactory.getIdGenerator("uuid").generateId()));
      } else {
         getHeader.setMessageID(new URI(messageId));
      }

      if (mutualityToSendTo == null) {
         getHeader.setTo(new URI(""));
      } else {
         getHeader.setTo(new URI("urn:nip:destination:io:" + mutualityToSendTo));
      }

      return getHeader;
   } catch (URISyntaxException var4) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var4, new Object[]{var4.getMessage()});
   }
}
 
Example 8
@Override
public URI getURI() {
	try {
		return this.connection.getURL().toURI();
	}
	catch (URISyntaxException ex) {
		throw new IllegalStateException("Could not get HttpURLConnection URI: " + ex.getMessage(), ex);
	}
}
 
Example 9
/**
 * sometimes permanenturis inside items are wrong after an Exchange version migration
 * need to restore base uri to actual public Exchange uri
 *
 * @param url input uri
 * @return fixed uri
 * @throws IOException on error
 */
protected String encodeAndFixUrl(String url) throws IOException {
    String fixedurl = URIUtil.encodePath(url);
    // sometimes permanenturis inside items are wrong after an Exchange version migration
    // need to restore base uri to actual public Exchange uri
    if (restoreHostName && fixedurl.startsWith("http")) {
        try {
            return URIUtils.rewriteURI(new java.net.URI(fixedurl), URIUtils.extractHost(httpClientAdapter.getUri())).toString();
        } catch (URISyntaxException e) {
            throw new IOException(e.getMessage(), e);
        }
    }
    return fixedurl;
}
 
Example 10
Source Project: nano-framework   File: URIBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public URIBuilder(final String string) {
    super();
    try {
        digestURI(new URI(string));
    } catch (final URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
Example 11
Source Project: DataSphereStudio   File: Props.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the uri representation of the value. If the value is null, then the default value is
 * returned. If the value isn't a uri, then a IllegalArgumentException will be thrown.
 */
public URI getUri(final String name) {
  if (containsKey(name)) {
    try {
      return new URI(get(name));
    } catch (final URISyntaxException e) {
      throw new IllegalArgumentException(e.getMessage());
    }
  } else {
    throw new UndefinedPropertyException("Missing required property '" + name
        + "'");
  }
}
 
Example 12
@Override
public URI getURI() {
	try {
		return this.connection.getURL().toURI();
	}
	catch (URISyntaxException ex) {
		throw new IllegalStateException("Could not get HttpURLConnection URI: " + ex.getMessage(), ex);
	}
}
 
Example 13
Source Project: SI   File: Request.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This is a convenience method to set the reques's options for host, port
 * and path with a string of the form
 * <code>[scheme]://[host]:[port]{/resource}*?{&amp;query}*</code>
 * 
 * @param uri the URI defining the target resource
 * @return this request
 */
public Request setURI(String uri) {
	try {
		if (!uri.startsWith("coap://") && !uri.startsWith("coaps://"))
			uri = "coap://" + uri;
		return setURI(new URI(uri));
	} catch (URISyntaxException e) {
		throw new IllegalArgumentException("Failed to set uri "+uri + ": " + e.getMessage());
	}
}
 
Example 14
/**
 * Convenient method to simulate a parent/child composition
 *
 * @param parent the URI to parent directory
 * @param child  the child name
 * @return the resulting URI
 */
public static URI toURI (URI parent,
                         String child)
{
    try {
        // Make sure parent ends with a '/'
        if (parent == null) {
            throw new IllegalArgumentException("Parent is null");
        }

        StringBuilder dirName = new StringBuilder(parent.toString());

        if (dirName.charAt(dirName.length() - 1) != '/') {
            dirName.append('/');
        }

        // Make sure child does not start with a '/'
        if ((child == null) || child.isEmpty()) {
            throw new IllegalArgumentException("Child is null or empty");
        }

        if (child.startsWith("/")) {
            throw new IllegalArgumentException("Child is absolute: " + child);
        }

        return new URI(dirName.append(child).toString());
    } catch (URISyntaxException ex) {
        throw new IllegalArgumentException(ex.getMessage(), ex);
    }
}
 
Example 15
int runStartService(PrintWriter pw, boolean asForeground) throws RemoteException {
    final PrintWriter err = getErrPrintWriter();
    Intent intent;
    try {
        intent = makeIntent(UserHandle.USER_CURRENT);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (mUserId == UserHandle.USER_ALL) {
        err.println("Error: Can't start activity with user 'all'");
        return -1;
    }
    pw.println("Starting service: " + intent);
    pw.flush();
    ComponentName cn = mInterface.startService(null, intent, intent.getType(),
            asForeground, SHELL_PACKAGE_NAME, mUserId);
    if (cn == null) {
        err.println("Error: Not found; no service started.");
        return -1;
    } else if (cn.getPackageName().equals("!")) {
        err.println("Error: Requires permission " + cn.getClassName());
        return -1;
    } else if (cn.getPackageName().equals("!!")) {
        err.println("Error: " + cn.getClassName());
        return -1;
    } else if (cn.getPackageName().equals("?")) {
        err.println("Error: " + cn.getClassName());
        return -1;
    }
    return 0;
}
 
Example 16
int runStopService(PrintWriter pw) throws RemoteException {
    final PrintWriter err = getErrPrintWriter();
    Intent intent;
    try {
        intent = makeIntent(UserHandle.USER_CURRENT);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (mUserId == UserHandle.USER_ALL) {
        err.println("Error: Can't stop activity with user 'all'");
        return -1;
    }
    pw.println("Stopping service: " + intent);
    pw.flush();
    int result = mInterface.stopService(null, intent, intent.getType(), mUserId);
    if (result == 0) {
        err.println("Service not stopped: was not running.");
        return -1;
    } else if (result == 1) {
        err.println("Service stopped");
        return -1;
    } else if (result == -1) {
        err.println("Error stopping service");
        return -1;
    }
    return 0;
}
 
Example 17
@Override
public URI toUri() {
	try {
		return new URI(getScheme(), this.ssp, getFragment());
	}
	catch (URISyntaxException ex) {
		throw new IllegalStateException("Could not create URI object: " + ex.getMessage(), ex);
	}
}
 
Example 18
static URI setQuery(URI u, String newQuery, boolean add) throws MalformedURLException {
    String query = u.getQuery();
    query = (query == null || !add) ? newQuery : query + '&' + newQuery;
    try {
        return  new URI(u.getScheme(), u.getUserInfo(), u.getHost(),
                u.getPort(), u.getPath(), query, u.getFragment());
    } catch (URISyntaxException ex) {
        MalformedURLException mex = new MalformedURLException(ex.getMessage());
        mex.initCause(ex);
        throw mex;
    }
}
 
Example 19
public DOMReference(String uri, String type, DigestMethod dm,
                    List<? extends Transform> appliedTransforms,
                    Data result, List<? extends Transform> transforms,
                    String id, byte[] digestValue, Provider provider)
{
    if (dm == null) {
        throw new NullPointerException("DigestMethod must be non-null");
    }
    List<Transform> tempList =
        Collections.checkedList(new ArrayList<Transform>(),
                                Transform.class);
    if (appliedTransforms != null) {
        tempList.addAll(appliedTransforms);
    }
    List<Transform> tempList2 =
        Collections.checkedList(new ArrayList<Transform>(),
                                Transform.class);
    if (transforms != null) {
        tempList.addAll(transforms);
        tempList2.addAll(transforms);
    }
    this.allTransforms = Collections.unmodifiableList(tempList);
    this.transforms = tempList2;
    this.digestMethod = dm;
    this.uri = uri;
    if ((uri != null) && (!uri.equals(""))) {
        try {
            new URI(uri);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }
    this.type = type;
    this.id = id;
    if (digestValue != null) {
        this.digestValue = digestValue.clone();
        this.digested = true;
    }
    this.appliedTransformData = result;
    this.provider = provider;
}
 
Example 20
public DOMReference(String uri, String type, DigestMethod dm,
                    List<? extends Transform> appliedTransforms,
                    Data result, List<? extends Transform> transforms,
                    String id, byte[] digestValue, Provider provider)
{
    if (dm == null) {
        throw new NullPointerException("DigestMethod must be non-null");
    }
    if (appliedTransforms == null) {
        this.allTransforms = new ArrayList<Transform>();
    } else {
        this.allTransforms = new ArrayList<Transform>(appliedTransforms);
        for (int i = 0, size = this.allTransforms.size(); i < size; i++) {
            if (!(this.allTransforms.get(i) instanceof Transform)) {
                throw new ClassCastException
                    ("appliedTransforms["+i+"] is not a valid type");
            }
        }
    }
    if (transforms == null) {
        this.transforms = Collections.emptyList();
    } else {
        this.transforms = new ArrayList<Transform>(transforms);
        for (int i = 0, size = this.transforms.size(); i < size; i++) {
            if (!(this.transforms.get(i) instanceof Transform)) {
                throw new ClassCastException
                    ("transforms["+i+"] is not a valid type");
            }
        }
        this.allTransforms.addAll(this.transforms);
    }
    this.digestMethod = dm;
    this.uri = uri;
    if ((uri != null) && (!uri.equals(""))) {
        try {
            new URI(uri);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }
    this.type = type;
    this.id = id;
    if (digestValue != null) {
        this.digestValue = (byte[])digestValue.clone();
        this.digested = true;
    }
    this.appliedTransformData = result;
    this.provider = provider;
}