Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

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

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java

@Override
public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) {
    Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials");
    String id = (String) serviceData.get("name");
    try {/*  w  ww  .  j  av  a2 s .c o  m*/
        URI uri = new URI((String) credentials.get("url"));
        String scheme = uri.getScheme();
        int port = uri.getPort();
        String host = uri.getHost();
        String path = uri.getPath();
        String query = uri.getQuery();
        String fragment = uri.getFragment();
        String url = new URI(scheme, "", host, port, path, query, fragment).toString();
        String[] userInfo = uri.getUserInfo().split(":");
        return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url);
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:org.nuclos.common.activemq.NuclosHttpTransportFactory.java

@Override
protected Transport createTransport(URI location, WireFormat wf) throws IOException {
    if (location.getScheme().equals("myhttp")) {
        try {/* w ww  .j  a  va2 s . c  o m*/
            location = new URI(location.toString().substring(2));
        } catch (URISyntaxException e) {
            throw new IOException(e);
        }
    }
    final HttpClientTransport result = (HttpClientTransport) super.createTransport(location, wf);
    result.setSoTimeout(NuclosHttpClientFactory.SO_TIMEOUT_MILLIS);
    final HttpClient httpClient = getHttpClient();
    result.setReceiveHttpClient(httpClient);
    result.setSendHttpClient(httpClient);
    return result;
}

From source file:com.google.caja.plugin.DataUriFetcher.java

private boolean isDataUri(URI uri) {
    if (null != uri && "data".equals(uri.getScheme()) && uri.isOpaque()) {
        return true;
    }/*ww w .java  2s.c  o m*/
    return false;
}

From source file:com.nesscomputing.httpserver.SoloJetty8HttpServer.java

@Inject
SoloJetty8HttpServer(final SoloHttpServerConfig soloHttpServerConfig, final HttpServerConfig httpServerConfig,
        @Named(CATCHALL_NAME) final Servlet catchallServlet) {
    super(httpServerConfig, catchallServlet);

    final ImmutableMap.Builder<String, HttpConnector> builder = ImmutableMap.builder();

    final URI[] serviceUris = soloHttpServerConfig.getServiceUris();

    Preconditions.checkState(ArrayUtils.isNotEmpty(serviceUris), "at least one valid URI must be given!");

    int count = 0;
    for (URI serviceUri : serviceUris) {

        final String scheme = serviceUri.getScheme();
        final boolean secure = "https".equals(scheme);
        int port = serviceUri.getPort();
        if (port == 0) {
            port = secure ? 443 : 80;/*from w  ww.  j  av a2 s. c  o  m*/
        }
        builder.put(count == 0 ? "service" : String.format("service-%d", count),
                new HttpConnector(secure, scheme, serviceUri.getHost(), port));
        count++;
    }

    connectors = builder.build();
}

From source file:com.netflix.spinnaker.halyard.config.validate.v1.security.PublicServiceValidator.java

@Override
public void validate(ConfigProblemSetBuilder p, PublicService n) {
    String overrideBaseUrl = n.getOverrideBaseUrl();
    if (!StringUtils.isEmpty(overrideBaseUrl)) {
        try {/*from   w w w.ja  v  a2s .com*/
            URI uri = new URIBuilder(overrideBaseUrl).build();

            if (StringUtils.isEmpty(uri.getScheme())) {
                p.addProblem(ERROR, "You must supply a URI scheme, e.g. 'http://' or 'https://'");
            }

            if (StringUtils.isEmpty(uri.getHost())) {
                p.addProblem(ERROR, "You must supply a URI host");
            }
        } catch (URISyntaxException e) {
            p.addProblem(ERROR, "Invalid base URL: " + e.getMessage());
        }
    }
}

From source file:com.googlecode.jsonschema2pojo.ContentResolver.java

/**
 * Resolve a given URI to read its contents and parse the result as JSON.
 * <p>/*from  w  w w .  j  a  v a  2  s.c  o m*/
 * Supported protocols:
 * <ul>
 * <li>http/https
 * <li>file
 * <li>classpath/resource/java (all synonymous, used to resolve a schema
 * from the classpath)
 * </ul>
 * 
 * @param uri
 *            the URI to read schema content from
 * @return the JSON tree found at the given URI
 */
public JsonNode resolve(URI uri) {

    if (CLASSPATH_SCHEMES.contains(uri.getScheme())) {
        return resolveFromClasspath(uri);
    }

    try {
        return OBJECT_MAPPER.readTree(uri.toURL());
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException("Error parsing document: " + uri, e);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
    }

}

From source file:org.mulgara.scon.Connection.java

/**
 * Encodes a URI if it looks like it needs it.
 * @param u The URI to encode, if needed.
 * @return a minimally encoded URI./*from  w w w.  j  a  v  a2s  .c om*/
 */
private static final String enc(URI u) {
    try {
        // if there is no query, then just return the unencoded URI
        String query = u.getRawQuery();
        if (query == null)
            return u.toString();
        // encode the query, and add it to the end of the URI
        String encQuery = encode(query);
        String encU = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), encQuery,
                u.getFragment()).toString();
        // if the partial encoding works, then return it
        if (decode(encU).equals(u.toString()))
            return encU;
        // nothing else worked, so encode it fully
        return encode(u.toString());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Unable to encode a URI", e);
    }
}

From source file:gate.tagger.tagme.TaggerTagMeWS.java

public static String recodeForDbp38(String uriString) {
    String ret;/*  w w  w.  j  a v  a2  s  . c o m*/
    URI uri = null;
    if (uriString.startsWith("http://") || uriString.startsWith("https://")) {
        // First try to parse the string as an URI so that any superfluous 
        // percent-encodings can get decoded later
        try {
            uri = new URI(uriString);
        } catch (Exception ex) {
            throw new GateRuntimeException("Could not parse URI " + uriString, ex);
        }
        // now use this constructor to-recode only the necessary parts
        try {
            String path = uri.getPath();
            path = path.trim();
            path = path.replaceAll(" +", "_");
            uri = new URI(uri.getScheme(), null, uri.getHost(), -1, path, uri.getQuery(), uri.getFragment());
        } catch (Exception ex) {
            throw new GateRuntimeException("Could not re-construct URI: " + uri);
        }
        ret = uri.toString();
    } else {
        if (uriString.contains("\\u")) {
            uriString = StringEscapeUtils.unescapeJava(uriString);
        }
        uriString = uriString.trim();
        uriString = uriString.replaceAll(" +", "_");
        // We need to %-encode colons, otherwise the getPath() method will return
        // null ...
        uriString = uriString.replaceAll(":", "%3A");
        try {
            uri = new URI(uriString);
            // decode and prepare for minimal percent encoding
            uriString = uri.getPath();
        } catch (URISyntaxException ex) {
            // do nothing: the uriString must already be ready for percent-encoding
        }
        uriString = uriString.replaceAll(" +", "_");
        try {
            uri = new URI(null, null, null, -1, "/" + uriString, null, null);
        } catch (Exception ex) {
            throw new GateRuntimeException("Could not re-construct URI part: " + uriString);
        }
        ret = uri.toString().substring(1);
    }
    return ret;
}

From source file:eu.esdihumboldt.hale.io.codelist.InspireCodeListAdvisor.java

@Override
public void copyResource(LocatableInputSupplier<? extends InputStream> resource, final Path target,
        IContentType resourceType, boolean includeRemote, IOReporter reporter) throws IOException {

    URI uri = resource.getLocation();
    String uriScheme = uri.getScheme();
    if (uriScheme.equals("http")) {
        // Get the response for the given uri
        Response response = INSPIRECodeListReader.getResponse(uri);

        // Handle the fluent response
        response.handleResponse(new ResponseHandler<Boolean>() {

            @Override/*from w  ww .  j a v a2s  . c o  m*/
            public Boolean handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                StatusLine status = response.getStatusLine();
                HttpEntity entity = response.getEntity();

                if (status.getStatusCode() >= 300) {
                    throw new HttpResponseException(status.getStatusCode(), status.getReasonPhrase());
                }
                if (entity == null) {
                    throw new ClientProtocolException();
                }
                // Copy the resource file to the target path
                Files.copy(entity.getContent(), target);
                return true;
            }
        });
    } else {
        super.copyResource(resource, target, resourceType, includeRemote, reporter);
    }
}

From source file:org.nuclos.common.activemq.NuclosHttpsTransportFactory.java

@Override
protected Transport createTransport(URI location, WireFormat wf) throws MalformedURLException {
    if (location.getScheme().equals("myhttps")) {
        try {/*from  w  ww  . j  ava 2s.  c  o  m*/
            location = new URI(location.toString().substring(2));
        } catch (URISyntaxException e) {
            throw new MalformedURLException(e.toString());
        }
    }
    final HttpsClientTransport result = (HttpsClientTransport) super.createTransport(location, wf);
    final HttpClient httpClient = getHttpClient();
    result.setReceiveHttpClient(httpClient);
    result.setSendHttpClient(httpClient);
    return result;
}