Example usage for java.net URISyntaxException URISyntaxException

List of usage examples for java.net URISyntaxException URISyntaxException

Introduction

In this page you can find the example usage for java.net URISyntaxException URISyntaxException.

Prototype

public URISyntaxException(String input, String reason) 

Source Link

Document

Constructs an instance from the given input string and reason.

Usage

From source file:eu.asterics.mw.services.ResourceRegistry.java

public static Path toPath(URI uri) throws URISyntaxException {
    String scheme = uri.getScheme();
    if (scheme != null && !scheme.startsWith("file")) {
        throw new URISyntaxException(uri.toString(), "The uri does not start with the scheme <file>");
    }//from ww  w. jav a2  s  .  c  o m
    Path p = toFile(uri).toPath();
    return p;
}

From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java

public static <T> PropertyStore<T> getEphemeralStore(ZKConnection zkclient, String store,
        PropertySerializer<T> serializer, ZooKeeperPropertyMerger<T> merger)
        throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);

    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {

            ZooKeeperEphemeralStore<T> zkStore = new ZooKeeperEphemeralStore<T>(zkclient, serializer, merger,
                    storeUri.getPath());
            startStore(zkStore);//from  w w w . j  a v  a2s . c  o m
            return zkStore;
        } else {
            throw new URISyntaxException(store,
                    "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<T>(storeUri.getPath(), ".json", serializer);
    }

}

From source file:com.att.nsa.mr.client.impl.MRSimplerBatchPublisher.java

private void DME2Configue() throws Exception {
    try {//from   ww w.  j  ava  2  s .c o m

        /*   FileReader reader = new FileReader(new File (producerFilePath));
           Properties props = new Properties();      
           props.load(reader);*/
        latitude = props.getProperty("Latitude");
        longitude = props.getProperty("Longitude");
        version = props.getProperty("Version");
        serviceName = props.getProperty("ServiceName");
        env = props.getProperty("Environment");
        partner = props.getProperty("Partner");
        routeOffer = props.getProperty("routeOffer");
        subContextPath = props.getProperty("SubContextPath") + fTopic;
        /*if(props.getProperty("partition")!=null && !props.getProperty("partition").equalsIgnoreCase("")){
           subContextPath=subContextPath+"?partitionKey="+props.getProperty("partition");
        }*/
        protocol = props.getProperty("Protocol");
        methodType = props.getProperty("MethodType");
        dmeuser = props.getProperty("username");
        dmepassword = props.getProperty("password");
        contentType = props.getProperty("contenttype");
        handlers = props.getProperty("sessionstickinessrequired");
        routerFilePath = props.getProperty("DME2preferredRouterFilePath");

        /**
         * Changes to DME2Client url to use Partner for auto failover between data centers
         * When Partner value is not provided use the routeOffer value for auto failover within a cluster 
         */

        String partitionKey = props.getProperty("partition");

        if (partner != null && !partner.isEmpty()) {
            url = protocol + "://" + serviceName + "?version=" + version + "&envContext=" + env + "&partner="
                    + partner;
            if (partitionKey != null && !partitionKey.equalsIgnoreCase("")) {
                url = url + "&partitionKey=" + partitionKey;
            }
        } else if (routeOffer != null && !routeOffer.isEmpty()) {
            url = protocol + "://" + serviceName + "?version=" + version + "&envContext=" + env + "&routeoffer="
                    + routeOffer;
            if (partitionKey != null && !partitionKey.equalsIgnoreCase("")) {
                url = url + "&partitionKey=" + partitionKey;
            }
        }

        DMETimeOuts = new HashMap<String, String>();
        DMETimeOuts.put("AFT_DME2_EP_READ_TIMEOUT_MS", props.getProperty("AFT_DME2_EP_READ_TIMEOUT_MS"));
        DMETimeOuts.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", props.getProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS"));
        DMETimeOuts.put("AFT_DME2_EP_CONN_TIMEOUT", props.getProperty("AFT_DME2_EP_CONN_TIMEOUT"));
        DMETimeOuts.put("Content-Type", contentType);
        System.setProperty("AFT_LATITUDE", latitude);
        System.setProperty("AFT_LONGITUDE", longitude);
        System.setProperty("AFT_ENVIRONMENT", props.getProperty("AFT_ENVIRONMENT"));
        //System.setProperty("DME2.DEBUG", "true");
        //   System.setProperty("AFT_DME2_HTTP_EXCHANGE_TRACE_ON", "true");
        //System.out.println("XXXXXX"+url);

        //SSL changes
        System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "SSLv3,TLSv1,TLSv1.1");
        System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
        System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");

        //SSL changes

        sender = new DME2Client(new URI(url), 5000L);

        sender.setAllowAllHttpReturnCodes(true);
        sender.setMethod(methodType);
        sender.setSubContext(subContextPath);
        sender.setCredentials(dmeuser, dmepassword);
        sender.setHeaders(DMETimeOuts);
        if (handlers.equalsIgnoreCase("yes")) {
            sender.addHeader("AFT_DME2_EXCHANGE_REQUEST_HANDLERS",
                    props.getProperty("AFT_DME2_EXCHANGE_REQUEST_HANDLERS"));
            sender.addHeader("AFT_DME2_EXCHANGE_REPLY_HANDLERS",
                    props.getProperty("AFT_DME2_EXCHANGE_REPLY_HANDLERS"));
            sender.addHeader("AFT_DME2_REQ_TRACE_ON", props.getProperty("AFT_DME2_REQ_TRACE_ON"));
        } else {
            sender.addHeader("AFT_DME2_EXCHANGE_REPLY_HANDLERS",
                    "com.att.nsa.mr.dme.client.HeaderReplyHandler");
        }
    } catch (DME2Exception x) {
        getLog().warn(x.getMessage(), x);
        throw new DME2Exception(x.getErrorCode(), x.getErrorMessage());
    } catch (URISyntaxException x) {

        getLog().warn(x.getMessage(), x);
        throw new URISyntaxException(url, x.getMessage());
    } catch (Exception x) {

        getLog().warn(x.getMessage(), x);
        throw new Exception(x.getMessage());
    }
}

From source file:annis.AnnisRunner.java

private QueryData extractSaltIds(String param) {
    QueryData queryData = new QueryData();
    SaltURIGroupSet saltIDs = new SaltURIGroupSet();

    Set<String> corpusNames = new TreeSet<String>();

    int i = 0;/*  w ww. ja v  a  2s.  c  o m*/
    for (String group : param.split("\\s*;\\s*")) {
        SaltURIGroup urisForGroup = new SaltURIGroup();

        for (String id : group.split("[,\\s]+")) {
            java.net.URI uri;
            try {
                uri = new java.net.URI(id);

                if (!"salt".equals(uri.getScheme()) || uri.getFragment() == null) {
                    throw new URISyntaxException("not a salt id", uri.toString());
                }
            } catch (URISyntaxException ex) {
                log.error(null, ex);
                continue;
            }
            urisForGroup.getUris().add(uri);
        }

        // collect list of used corpora and created pseudo QueryNodes for each URI
        List<QueryNode> pseudoNodes = new ArrayList<QueryNode>(urisForGroup.getUris().size());
        for (java.net.URI u : urisForGroup.getUris()) {
            pseudoNodes.add(new QueryNode());
            corpusNames.add(CommonHelper.getCorpusPath(u).get(0));
        }
        queryData.addAlternative(pseudoNodes);
        saltIDs.getGroups().put(++i, urisForGroup);
    }
    List<Long> corpusIDs = annisDao.mapCorpusNamesToIds(new LinkedList<String>(corpusNames));

    queryData.setCorpusList(corpusIDs);

    log.debug(saltIDs.toString());
    queryData.addExtension(saltIDs);
    return queryData;
}

From source file:org.gss_project.gss.server.rest.FilesHandler.java

/**
 * A helper method that extracts the relative resource path,
 * after removing the 'files' namespace.
 * The path returned is <i>not</i> URL-decoded.
 *
 * @param req the HTTP request// w  w  w.j a  v  a 2s  .c  om
 * @param path the specified path
 * @return the path relative to the root folder
 * @throws URISyntaxException
 * @throws RpcException in case an error occurs while communicating
 *                   with the backend
 * @throws UnsupportedEncodingException
 */
private String getDestinationPath(HttpServletRequest req, String path)
        throws URISyntaxException, RpcException, UnsupportedEncodingException {
    URI uri = new URI(path);
    String dest = uri.getRawPath();
    // Remove the context path from the destination URI.
    String contextPath = req.getContextPath();
    if (!dest.startsWith(contextPath))
        throw new URISyntaxException(dest, "Destination path does not start with " + contextPath);
    dest = dest.substring(contextPath.length());
    // Remove the servlet path from the destination URI.
    String servletPath = req.getServletPath();
    if (!dest.startsWith(servletPath))
        throw new URISyntaxException(dest, "Destination path does not start with " + servletPath);
    dest = dest.substring(servletPath.length());
    // Strip the username part
    if (dest.length() < 2)
        throw new URISyntaxException(dest, "No username in the destination URI");
    int slash = dest.substring(1).indexOf('/');
    if (slash == -1)
        throw new URISyntaxException(dest, "No username in the destination URI");
    // Decode the user to get the proper characters (mainly the @)
    String owner = URLDecoder.decode(dest.substring(1, slash + 1), "UTF-8");
    User o;
    o = getService().findUser(owner);
    if (o == null)
        throw new URISyntaxException(dest, "User " + owner + " not found");

    req.setAttribute(DESTINATION_OWNER_ATTRIBUTE, o);
    dest = dest.substring(slash + 1);

    // Chop the resource namespace part
    dest = dest.substring(RequestHandler.PATH_FILES.length());

    dest = dest.endsWith("/") ? dest : dest + '/';
    return dest;
}