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:org.dasein.cloud.azure.platform.AzureSQLDatabaseSupportRequests.java

private String getEncodedUri(String urlString) throws InternalException {
    try {//from ww  w .j a  v a 2s.  c  o m
        URL url = new URL(urlString);
        return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef()).toString();
    } catch (Exception e) {
        throw new InternalException(e.getMessage());
    }
}

From source file:blue.lapis.pore.launch.PoreBootstrap.java

@Inject
public PoreBootstrap(Injector injector) {
    URL location = getClass().getProtectionDomain().getCodeSource().getLocation();
    String path = location.getPath();
    if (location.getProtocol().equals("jar")) {
        int pos = path.lastIndexOf('!');
        if (pos >= 0) {
            path = path.substring(0, pos + 2);
        }/*from   w w  w.  j  a v  a 2  s.  c  o m*/
    } else {
        path = StringUtils.removeEnd(path, getClass().getName().replace('.', '/') + ".class");
    }

    try {
        ClassLoader loader = new PoreClassLoader(getClass().getClassLoader(),
                new URL(location.getProtocol(), location.getHost(), location.getPort(), path));
        Class<?> poreClass = Class.forName(IMPLEMENTATION_CLASS, true, loader);
        this.pore = (PoreEventManager) injector.getInstance(poreClass);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Failed to load Pore implementation", e);
    } catch (MalformedURLException e) {
        throw new RuntimeException("Failed to load Pore implementation", e);
    }
}

From source file:com.predic8.membrane.core.interceptor.swagger.SwaggerRewriterInterceptor.java

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    ((ServiceProxy) exc.getRule()).setTargetHost(swagger.getHost());
    URL url = new URL(swaggerUrl);
    exc.getDestinations().set(0, url.getProtocol() + "://" + url.getHost()
            + (url.getPort() < 0 ? "" : ":" + url.getPort()) + exc.getOriginalRequestUri());
    return super.handleRequest(exc);
}

From source file:com.zextras.zimbradrive.statustest.ConnectionTestUtils.java

public boolean pingHost(URL url, int connectionTimeout) throws MalformedURLException {
    String host = url.getHost();/* ww w  .  j  a  va 2  s.  c o  m*/
    int port = url.getPort();
    if (port == -1) {
        if (url.getProtocol().equals("https")) {
            port = 443;
        } else {
            port = 80;
        }
    }
    try (Socket socket = new Socket()) {
        InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port);
        socket.connect(inetSocketAddress, connectionTimeout);
        return true;
    } catch (IOException e) {
        return false; // Either timeout or unreachable or failed DNS lookup.
    }
}

From source file:com.basetechnology.s0.agentserver.webaccessmanager.WebAccessManager.java

public WebSite getWebSite(String url) {
    String webSiteUrl = null;//from  w w w  . java 2s  . c  o  m
    try {
        URL tempUrl = new URL(url);

        String protocol = tempUrl.getProtocol();
        String host = tempUrl.getHost();
        int port = tempUrl.getPort();
        webSiteUrl = protocol + "://" + host + (port > 0 ? ":" + port : "") + "/";
    } catch (MalformedURLException e) {
        throw new InvalidUrlException(e.getMessage());
    }

    // Check if we already know about this site
    if (!webSites.containsKey(webSiteUrl)) {
        // No, create a new WebSite entry
        WebSite webSite = new WebSite(this, webSiteUrl);
        webSites.put(webSiteUrl, webSite);
    }

    // Return the WebSite for this URL
    return webSites.get(webSiteUrl);
}

From source file:com.t2.drupalsdk.ServicesClient.java

public ServicesClient(String urlString) throws DataOutHandlerException, MalformedURLException {

    if (urlString == null || urlString == "") {
        throw new DataOutHandlerException("Remote database URL must not be null or blank");
    }//  w  w  w .j ava2 s . c om
    // Break down the remote URL string into constituant parts
    String[] tokens = urlString.split("/");

    if (tokens.length < MIN_PARAMETERS) {
        throw new DataOutHandlerException("Remote database URL incorrectly formatted - "
                + "must include Drupal service and Drupal Rest Endpoint");
    }
    this.mDrupalRestEndpoint = tokens[INDEX_DRUPAL_REST_ENDPOINT];
    this.mDrupalService = tokens[INDEX_DRUPAL_SERVICE];
    this.mUrlString = urlString;

    URL url = new URL(urlString);

    mProtocol = url.getProtocol();
    mHost = url.getHost();

    mAsyncHttpClient.setTimeout(60000);
}

From source file:eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinitionBackwardCompatibility.java

private String createRepoBaseUrlWithImplicitUser() throws MalformedURLException {
    StringBuilder credentialsIdBuilder = new StringBuilder();

    URL url = new URL(this.getRepoBaseUrl());

    credentialsIdBuilder.append(url.getProtocol());
    credentialsIdBuilder.append("://");
    credentialsIdBuilder.append(this.username);
    credentialsIdBuilder.append("@");
    credentialsIdBuilder.append(url.getHost());

    int port = url.getPort();
    if (port > -1) {
        credentialsIdBuilder.append(":");
        credentialsIdBuilder.append(port);
    }/* w  w  w  .java 2s.  c  o m*/

    credentialsIdBuilder.append(url.getPath());

    return credentialsIdBuilder.toString();
}

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

@Override
public boolean fetchProofData() {

    String tweetUrl = null;//from   w w  w .  j  a va2  s.c  o  m
    try {
        JSONObject sigJSON = readSig(mProof.getSigId());

        // the magic string is the base64 of the SHA of the raw message
        mShortenedMessageHash = JWalk.getString(sigJSON, "sig_id_short");

        // find the tweet's url and fetch it
        tweetUrl = mProof.getProofUrl();
        Fetch fetch = new Fetch(tweetUrl);
        String problem = fetch.problem();
        if (problem != null) {
            mLog.add(problem);
            return false;
        }

        // Paranoid Interlude:
        // 1. It has to be a tweet https://twitter.com/<nametag>/status/\d+
        // 2. the magic string has to appear in the <title>; were worried that
        //    someone could @-reply and fake us out with the magic string down in someone
        //    elses tweet

        URL suspectUrl = new URL(tweetUrl);
        String scheme = suspectUrl.getProtocol();
        String host = suspectUrl.getHost();
        String path = suspectUrl.getPath();
        String nametag = mProof.getNametag();
        if (!(scheme.equals("https") && host.equals("twitter.com")
                && path.startsWith("/" + nametag + "/status/") && endsWithDigits(path))) {
            mLog.add("Unacceptable Twitter proof Url: " + tweetUrl);
        }

        // dig through the tweet to find the magic string in the <title>
        String tweet = fetch.getBody();

        // make sure were looking only through the header
        int index1 = tweet.indexOf("</head>");
        if (index1 == -1) {
            mLog.add("</head> not found in proof tweet");
            mLog.add("Proof tweet is malformed.");
            return false;
        }
        tweet = tweet.substring(0, index1);

        index1 = tweet.indexOf("<title>");
        int index2 = tweet.indexOf("</title>");
        if (index1 == -1 || index2 == -1 || index1 >= index2) {
            mLog.add("Bogus head locations: " + index1 + "/" + index2);
            mLog.add("Unable to find proof tweet header.");
            return false;
        }

        // ensure the magic string appears in the tweets <title>
        tweet = tweet.substring(index1, index2);
        if (tweet.contains(mShortenedMessageHash)) {
            return true;
        } else {
            mLog.add("Encoded message not found in proof tweet.");
            return false;
        }

    } 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("Unparsable tweet URL: " + tweetUrl);
    }
    return false;
}

From source file:org.bpmscript.js.reload.LibraryFileMonitor.java

/**
 * Checks whether the internal libraries have changed. If they do, publishes
 * out to a queue the list of files that need to be reloaded as a result
 *///www .j av  a2 s  .c  o m
@SuppressWarnings("unchecked")
protected void checkLibraries() {
    ArrayList<ILibraryToFile> newLibraryToFiles = new ArrayList<ILibraryToFile>();
    libraryAssociationQueue.drainTo(newLibraryToFiles);
    for (ILibraryToFile libraryToFile : newLibraryToFiles) {
        Set set = libraryToFilesMap.get(libraryToFile.getLibrary());
        if (set == null) {
            set = new HashSet<String>();
            libraryToFilesMap.put(libraryToFile.getLibrary(), set);
        }
        set.add(libraryToFile.getFile());
    }
    Iterator iterator = libraryToFilesMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Entry) iterator.next();
        String library = (String) entry.getKey();
        URL resource = this.getClass().getResource(library);
        if ("file".equals(resource.getProtocol())) {
            String path = resource.getPath();
            File file = new File(path);
            Long newLastModified = file.lastModified();
            Long oldLastModified = libraryToLastModifiedMap.get(library);
            if (oldLastModified != null && !(oldLastModified.equals(newLastModified))) {
                // library has changed, we should go through its files and notify listeners
                // that they need to reload. also, we need to check to see if the files are
                // libraries themselves...
                Collection values = (Collection) entry.getValue();
                for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
                    String value = (String) valueIterator.next();
                    if (libraryToFilesMap.containsKey(value)) {
                        // TODO: here we need to recurse
                    } else {
                        // notify listeners that the file has changed. consider notifying
                        // listeners that the library has changed...
                        libraryChangeQueue.add(new LibraryToFile(library, value));
                    }
                }
                libraryToLastModifiedMap.put(library, newLastModified);
            } else if (oldLastModified == null) {
                libraryToLastModifiedMap.put(library, newLastModified);
            }
        }
    }
}

From source file:org.apache.cxf.fediz.service.idp.STSPortFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    Assert.isTrue(applicationContext != null, "Application context must not be null");
    STSAuthenticationProvider authProvider = authenticationProvider;
    if (authProvider == null) {
        authProvider = applicationContext.getBean(STSAuthenticationProvider.class);
    }//from  w  ww. ja  v  a 2  s .  c om
    Assert.isTrue(authProvider != null, "STSAuthenticationProvider must be configured");

    //Only update the port if HTTPS is used, otherwise ignored (like retrieving the WADL over HTTP)
    if (!isPortSet && request.isSecure()) {
        try {
            URL url = new URL(authProvider.getWsdlLocation());
            if (url.getPort() == 0) {
                URL updatedUrl = new URL(url.getProtocol(), url.getHost(), request.getLocalPort(),
                        url.getFile());
                setSTSWsdlUrl(authProvider, updatedUrl.toString());
                LOG.info("STSAuthenticationProvider.wsdlLocation set to " + updatedUrl.toString());
            } else {
                setSTSWsdlUrl(authProvider, url.toString());
            }
        } catch (MalformedURLException e) {
            LOG.error("Invalid Url '" + authProvider.getWsdlLocation() + "': " + e.getMessage());
        }
    }

    chain.doFilter(request, response);
}