Example usage for java.net URL getProtocol

List of usage examples for java.net URL getProtocol

Introduction

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

Prototype

public String getProtocol() 

Source Link

Document

Gets the protocol name of this URL .

Usage

From source file:io.kamax.mxisd.dns.ClientDnsOverwrite.java

public URIBuilder transform(URI initial) {
    URIBuilder builder = new URIBuilder(initial);
    Entry mapping = mappings.get(initial.getHost());
    if (mapping == null) {
        throw new InternalServerError("No DNS client override for " + initial.getHost());
    }/*from w ww  .  j  a  v  a2  s.  c  o m*/

    try {
        URL target = new URL(mapping.getValue());
        builder.setScheme(target.getProtocol());
        builder.setHost(target.getHost());
        if (target.getPort() != -1) {
            builder.setPort(target.getPort());
        }

        return builder;
    } catch (MalformedURLException e) {
        log.warn("Skipping DNS overwrite entry {} due to invalid value [{}]: {}", mapping.getName(),
                mapping.getValue(), e.getMessage());
        throw new ConfigurationException(
                "Invalid DNS overwrite entry in homeserver client: " + mapping.getName(), e.getMessage());
    }
}

From source file:eu.cloud4soa.soa.jaxrs.test.SemanticAppInitializer.java

public void initialize() {

    try {//from   www.  jav a2s.c  o  m
        String developerUserDir = "applicationProfiles";
        URL resource = scanPackage(developerUserDir);
        String protocol = resource.getProtocol();
        if (protocol.equals("file")) {
            File file = new File(resource.getFile());
            if (file.isDirectory()) {
                String[] list = file.list();
                for (String fileName : list) {
                    String applicationTurtleProfile = loadTurtleFileIntoString(developerUserDir, fileName);
                    logger.info("Loaded application profile: " + fileName);
                    storeTurtleApplicationProfile(applicationTurtleProfile, developerUriId);
                }
            }
        }
    } catch (IOException ex) {
        logger.error("Error during the creation of the Application profiles", ex);
    }
}

From source file:org.joinfaces.tomcat.JsfTomcatApplicationListener.java

private String base(URL url) {
    String result;/*w  w w .  java 2s  .  co  m*/
    if (url.getProtocol().equals("jar")) {
        result = url.getFile();
        result = result.substring("file:".length());
        result = result.substring(0, result.indexOf("!/"));
    } else {
        result = url.getFile();
    }
    return result;
}

From source file:com.ge.predix.sample.blobstore.config.LocalConfig.java

@Bean
public BlobstoreService objectStoreService() {
    log.info("objectStoreService(): " + objectStoreProperties.getAccessKey()
            + objectStoreProperties.getSecretKey() + ", " + objectStoreProperties.getBucket());

    AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(objectStoreProperties.getAccessKey(),
            objectStoreProperties.getSecretKey()));
    s3Client.setEndpoint(objectStoreProperties.getUrl());

    try {//from w w  w  .j  a v  a2s  .  c  o  m
        // Remove the Credentials from the Object Store URL
        URL url = new URL(objectStoreProperties.getUrl());
        String urlWithoutCredentials = url.getProtocol() + "://" + url.getHost();

        // Return BlobstoreService
        return new BlobstoreService(s3Client, objectStoreProperties.getBucket(), urlWithoutCredentials);
    } catch (MalformedURLException e) {
        log.error("create(): Couldnt parse the URL provided by VCAP_SERVICES. Exception = " + e.getMessage());
        throw new RuntimeException("Blobstore URL is Invalid", e);
    }
}

From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHttpRequestHandler.java

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    checkAndPrepare(request, response, true);

    // check whether a matching resource exists
    Resource resource = getResource(request);
    if (resource == null) {
        logger.debug("No matching resource found - returning 404");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from w ww  .j a va  2  s.  co m*/
    }

    // check the resource's media type
    MediaType mediaType = getMediaType(resource);
    if (mediaType != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Determined media type '" + mediaType + "' for " + resource);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("No media type found for " + resource + " - not sending a content-type header");
        }
    }

    // header phase
    // Use a Vfs2Resource when asset are probided by the JBoss 5 Virtaul File System
    URL url = resource.getURL();
    if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
        resource = new Vfs2Resource(Vfs2Utils.getRoot(url));
    }

    if (new ServletWebRequest(request, response).checkNotModified(resource.lastModified())) {
        logger.debug("Resource not modified - returning 304");
        return;
    }
    setHeaders(response, resource, mediaType);

    // content phase
    if (METHOD_HEAD.equals(request.getMethod())) {
        logger.trace("HEAD request - skipping content");
        return;
    }
    writeContent(response, resource);
}

From source file:com.cisco.cta.taxii.adapter.httpclient.HttpClientFactory.java

public HttpClient create() {
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    if (proxySettings.getUrl() != null) {
        URL proxyUrl = proxySettings.getUrl();
        HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol());
        clientBuilder.setProxy(proxyHost);
    }/*w w  w  .jav  a2  s  .c  o  m*/
    return clientBuilder.build();
}

From source file:com.gargoylesoftware.htmlunit.util.URLCreator.java

protected URL toNormalUrl(final String url) throws MalformedURLException {
    final URL response = new URL(url);
    if (response.getProtocol().startsWith("http") && StringUtils.isEmpty(response.getHost())) {
        throw new MalformedURLException("Missing host name in url: " + url);
    }/*from   w w w.j  a v  a  2  s .  c  o m*/
    return response;
}

From source file:com.textuality.keybase.lib.prover.Coinbase.java

@Override
public boolean fetchProofData() {

    try {/* w w w.j av a  2  s  .com*/
        JSONObject sigJSON = readSig(mProof.getSigId());

        String proofUrl = mProof.getProofUrl();

        // fetch the post
        Fetch fetch = new Fetch(proofUrl);
        String problem = fetch.problem();
        if (problem != null) {
            mLog.add(problem);
            return false;
        }

        // Paranoid Interlude:
        // Lets make sure the URL is of the form https://coinbase.com/<nametag>/public-key
        //  and the actual host after redirects is coinbase
        //
        URL url = new URL(proofUrl);
        if (!(url.getProtocol().equals("https") && url.getHost().equals("coinbase.com")
                && url.getPath().equals("/" + mProof.getHandle() + "/public-key"))) {
            mLog.add("Bogus Coinbase proof URL: " + proofUrl);
            return false;
        }
        url = new URL(fetch.getActualUrl());
        if (!url.getHost().equals("coinbase.com")) {
            mLog.add("Coinbase proof doesnt come from coinbase.com: " + fetch.getActualUrl());
            return false;
        }

        // verify that message appears in body, which coinbase messes up with \rs
        String body = fetch.getBody().replace("\r", "");
        if (!body.contains(mPgpMessage)) {
            mLog.add("Coinbase proof doesnt contain signed PGP message");
            return false;
        }

        return true;

    } catch (KeybaseException e) {
        mLog.add("Keybase API problem: " + e.getLocalizedMessage());
    } catch (JSONException e) {
        mLog.add("Broken JSON message: " + e.getLocalizedMessage());
    } catch (MalformedURLException e) {
        mLog.add("Malformed Coinbase proof URL");
    }
    return false;
}

From source file:com.fengduo.bee.commons.core.utilities.ClassPathScanner.java

public List<Class<?>> scan() {
    List<Class<?>> list = new ArrayList<Class<?>>();
    Enumeration<URL> en = null;
    try {//from w w  w. j  ava 2 s  .c  o  m
        en = getClass().getClassLoader().getResources(dotToPath(packageName));
    } catch (IOException e) {
        e.printStackTrace();
    }
    while (en.hasMoreElements()) {
        URL url = en.nextElement();
        if (PROTOCOL_FILE.equals(url.getProtocol())) {
            File root = new File(url.getFile());
            findInDirectory(list, root, root, packageName);
        } else if (PROTOCOL_JAR.equals(url.getProtocol())) {
            findInJar(list, getJarFile(url), packageName);
        }
    }
    return list;
}

From source file:com.brightcove.com.zartan.verifier.video.VideoStillVerifier.java

@ZartanCheck(value = "VideoStill is delivered over http")
public ResultEnum assertVideoStillProtocolCorrect(UploadData upData) throws Throwable {
    URL u = getStillUrl(upData);
    assertEquals("Protocol should be http", "http", u.getProtocol());
    return ResultEnum.PASS;
}