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.fabric8.kubernetes.pipeline.KubernetesPipelineTest.java

private void configureCloud(JenkinsRuleNonLocalhost r) throws Exception {
    // Slaves running in Kubernetes (minikube) need to connect to this server, so localhost does not work
    URL url = r.getURL();
    URL nonLocalhostUrl = new URL(url.getProtocol(), InetAddress.getLocalHost().getHostAddress(), url.getPort(),
            url.getFile());//from www  . java 2 s.  c  om
    JenkinsLocationConfiguration.get().setUrl(nonLocalhostUrl.toString());

    r.jenkins.clouds.add(cloud);
}

From source file:eu.cloud4soa.soa.utils.SemanticAppInitializer.java

public void initialize() throws SOAException {

    try {//from  w ww  .  j  a v  a  2  s .  c  om
        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:com.meltmedia.cadmium.core.util.WarUtils.java

/**
 * Gets the currently deployed war file name from the ServletContext.
 * @param context/* w  w w .j  a v  a 2 s  . co m*/
 * @return
 */
public static String getWarName(ServletContext context) {
    String[] pathSegments = context.getRealPath("/WEB-INF/web.xml").split("/");
    String warName = pathSegments[pathSegments.length - 3];
    if (!warName.endsWith(".war")) {
        URL webXml = WarUtils.class.getClassLoader().getResource("/cadmium-version.properties");
        if (webXml != null) {

            String urlString = webXml.toString().substring(0,
                    webXml.toString().length() - "/WEB-INF/classes/cadmium-version.properties".length());
            File warFile = null;
            if (webXml.getProtocol().equalsIgnoreCase("file")) {
                warFile = new File(urlString.substring(5));
            } else if (webXml.getProtocol().equalsIgnoreCase("vfszip")) {
                warFile = new File(urlString.substring(7));
            } else if (webXml.getProtocol().equalsIgnoreCase("vfsfile")) {
                warFile = new File(urlString.substring(8));
            } else if (webXml.getProtocol().equalsIgnoreCase("vfs")
                    && System.getProperty(JBOSS_7_DEPLOY_DIR) != null) {
                String path = urlString.substring("vfs:/".length());
                String deployDir = System.getProperty(JBOSS_7_DEPLOY_DIR);
                warFile = new File(deployDir, path);
            }
            if (warFile != null) {
                warName = warFile.getName();
            }
        }
    }
    return warName;
}

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

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

From source file:gemlite.core.internal.support.hotdeploy.scanner.ScannerIterator.java

public ScannerIterator(URL url) throws IOException, URISyntaxException {
    if (url.getProtocol().equals("http") || url.getFile().endsWith(".jar")) {
        jarFile = true;/*www .  j  ava  2 s.c o m*/
        jarInputStream = new JarInputStream(url.openStream());
    } else {
        Collection<File> colls = FileUtils.listFiles(new File(url.toURI()),
                new String[] { class_suffix.substring(1) }, true);
        classFileIterator = colls.iterator();
        classpathLen = url.getFile().length();
    }

}

From source file:name.martingeisse.webide.nodejs.AbstractNodejsServer.java

/**
 * Starts this server.//from  w ww.  j a  v  a 2  s.  com
 */
public void start() {

    // determine the path of the associated script
    URL url = getScriptUrl();
    if (!url.getProtocol().equals("file")) {
        throw new RuntimeException("unsupported protocol for associated script URL: " + url);
    }
    File scriptFile = new File(url.getPath());

    // build the command line
    CommandLine commandLine = new CommandLine(Configuration.getBashPath());
    commandLine.addArgument("--login");
    commandLine.addArgument("-c");
    commandLine.addArgument("node " + scriptFile.getName(), false);

    // build I/O streams
    ByteArrayInputStream inputStream = null;
    OutputStream outputStream = System.err;
    OutputStream errorStream = System.err;
    ExecuteStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream, inputStream);

    // build an environment map that contains the path to the node_modules
    Map<String, String> environment = new HashMap<String, String>();
    environment.put("NODE_PATH", new File("lib/node_modules").getAbsolutePath());

    // run Node.js
    Executor executor = new DefaultExecutor();
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    executor.setStreamHandler(streamHandler);
    try {
        executor.setWorkingDirectory(scriptFile.getParentFile());
        executor.execute(commandLine, environment, new ExecuteResultHandler() {

            @Override
            public void onProcessFailed(ExecuteException e) {
            }

            @Override
            public void onProcessComplete(int exitValue) {
            }

        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:ai.baby.util.Parameter.java

public String toURL() {
    try {/*from   w w w  .j  a  va  2s  . c  o  m*/
        final URL url = new URL(parameterString.getObjectAsValid());
        final URI returnVal = new URI(url.getProtocol(), null, url.getHost(), 80, url.getPath(), url.getQuery(),
                null);
        return returnVal.toString();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:top.lionxxw.zuulservice.filter.BookingCarRoutingFilter.java

/**
 * This method allows to set the route host into the Zuul request context provided as parameter.
 * The url is extracted from the orginal request and the host is extracted from it.
 *
 * @param ctx Zuul//from   w w w  .j a  v a  2s .  c  om
 *
 * @throws MalformedURLException
 */
private void setRouteHost(RequestContext ctx) throws MalformedURLException {

    String urlS = ctx.getRequest().getRequestURL().toString();
    URL url = new URL(urlS);
    String protocol = url.getProtocol();
    String rootHost = url.getHost();
    int port = url.getPort();
    String portS = (port > 0 ? ":" + port : "");
    ctx.setRouteHost(new URL(protocol + "://" + rootHost + portS));

}

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

public BasicAuthHttpRequestFactory(HttpClient httpClient, TaxiiServiceSettings settings,
        ProxySettings proxySettings, CredentialsProvider credsProvider) {
    super(httpClient);
    this.credsProvider = credsProvider;

    URL url = settings.getPollEndpoint();
    HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());

    // Create auth cache with BASIC scheme
    authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());
}

From source file:TextUtils.java

/**
 * Using the java API URL class, extract the http/https
 * hostname.//ww w  . ja  v a 2s.  co  m
 * 
 * e.g: http://www.google.com/search will return http://www.google.com
 * 
 * @return
 */
public String getHTTPHostname(final String urlStr) {
    try {
        URL url = new URL(urlStr);
        String curHostname = url.getHost();
        String scheme = url.getProtocol();
        String fullNewURL = "";
        if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) {
            fullNewURL = scheme + "://" + curHostname;
            return fullNewURL;
        } else {
            throw new MalformedURLException();
        }
    } catch (MalformedURLException e) {
        return "invalid-hostname";
    }
}