Example usage for java.net URL getPort

List of usage examples for java.net URL getPort

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Gets the port number of this URL .

Usage

From source file:org.apache.infra.reviewboard.ReviewBoard.java

public static void main(String... args) throws IOException {

    URL url = new URL(REVIEW_BOARD_URL);
    HttpHost host = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());

    Executor executor = Executor.newInstance().auth(host, REVIEW_BOARD_USERNAME, REVIEW_BOARD_PASSWORD)
            .authPreemptive(host);/*from w  w w  . j  av a  2  s  .  c  o m*/

    Request request = Request.Get(REVIEW_BOARD_URL + "/api/review-requests/");
    Response response = executor.execute(request);

    request = Request.Get(REVIEW_BOARD_URL + "/api/review-requests/");
    response = executor.execute(request);

    ObjectMapper mapper = new ObjectMapper();
    JsonNode json = mapper.readTree(response.returnResponse().getEntity().getContent());

    JsonFactory factory = new JsonFactory();
    JsonGenerator generator = factory.createGenerator(new PrintWriter(System.out));
    generator.setPrettyPrinter(new DefaultPrettyPrinter());
    mapper.writeTree(generator, json);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    URL hp = new URL("http://www.java2s.com");
    System.out.println("Protocol: " + hp.getProtocol());
    System.out.println("Port: " + hp.getPort());
    System.out.println("Host: " + hp.getHost());
    System.out.println("File: " + hp.getFile());
    System.out.println("Ext:" + hp.toExternalForm());
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL u = new URL("http://www.yourserver.com:80/abc/demo.htm");
    System.out.println("The URL is " + u);
    System.out.println("The port part is " + u.getPort());

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.yahoo.com:80/en/index.html?name=joe#first");
    System.out.println("protocol:" + url.getProtocol());
    System.out.println("prot:" + url.getPort());
    System.out.println("host:" + url.getHost());
    System.out.println("path:" + url.getPath());
    System.out.println("file:" + url.getFile());
    System.out.println("query:" + url.getQuery());
    System.out.println("ref:" + url.getRef());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    URL url = new URL("http://hostname:80/index.html#_top_");

    String protocol = url.getProtocol(); // http
    String host = url.getHost(); // hostname
    int port = url.getPort(); // 80
    String file = url.getFile(); // index.html
    String ref = url.getRef(); // _top_
}

From source file:MinAppletviewer.java

public static void main(String args[]) throws Exception {
    AppSupport theAppSupport = new AppSupport();
    JFrame f = new JFrame();
    URL toload = new URL(args[0]);
    String host = toload.getHost();
    int port = toload.getPort();
    String protocol = toload.getProtocol();
    String path = toload.getFile();
    int join = path.lastIndexOf('/');
    String file = path.substring(join + 1);
    path = path.substring(0, join + 1);// w  ww.  jav a 2s . co m

    theAppSupport.setCodeBase(new URL(protocol, host, port, path));
    theAppSupport.setDocumentBase(theAppSupport.getCodeBase());

    URL[] bases = { theAppSupport.getCodeBase() };
    URLClassLoader loader = new URLClassLoader(bases);
    Class theAppletClass = loader.loadClass(file);
    Applet theApplet = (Applet) (theAppletClass.newInstance());

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.add(theApplet, BorderLayout.CENTER);

    theApplet.setStub(theAppSupport);

    f.setSize(200, 200);
    f.setVisible(true);
    theApplet.init();
    theApplet.start();
}

From source file:com.ebay.spine.Launcher.java

public static void main(String[] args) throws Exception {

    // not using the default parsing for the hub. Creating a simple one from the default.
    GridHubConfiguration config = new GridHubConfiguration();

    // adding the VNC capable servlet.
    List<String> servlets = new ArrayList<String>();
    servlets.add("web.ConsoleVNC");
    config.setServlets(servlets);//from w  w  w .j  a v  a 2  s  .  c o  m

    // capabilities are dynamic for VMs.
    config.setThrowOnCapabilityNotPresent(false);

    // forcing the host from command line param as the hub gets confused by all the VMWare network interfaces.
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("hubhost=")) {
            config.setHost(args[i].replace("hubhost=", ""));
        }
    }

    Hub h = new Hub(config);
    h.start();

    // and the nodes.

    // load the node templates.
    Map<String, JSONObject> templatesByNameMap = getTemplates("eugrid.json");

    // get the template to use for each VM
    Map<String, String> vmsMapping = getVMtoTemplateMapping("nodes.properties");

    // register each node using its template.
    for (String id : vmsMapping.keySet()) {
        String templateName = vmsMapping.get(id);
        JSONObject request = templatesByNameMap.get(templateName);
        request.getJSONObject("configuration").put("vm", id);

        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
                "http://" + hub + "/grid/register/");
        r.setEntity(new StringEntity(request.toString()));
        DefaultHttpClient client = new DefaultHttpClient();
        URL hubURL = new URL("http://" + hub);
        HttpHost host = new HttpHost(hubURL.getHost(), hubURL.getPort());
        HttpResponse response = client.execute(host, r);
    }

}

From source file:GetURLParts.java

public static void main(String args[]) {

    try {//  ww w . j  a  v  a2  s.com
        URL u = new URL("http://www.java2s.com");
        System.out.println("The URL is " + u);
        System.out.println("The protocol part is " + u.getProtocol());
        System.out.println("The host part is " + u.getHost());
        System.out.println("The port part is " + u.getPort());
        System.out.println("The file part is " + u.getFile());
        System.out.println("The ref part is " + u.getRef());
    } // end try
    catch (MalformedURLException e) {
        System.err.println("not a URL I understand.");
    }

}

From source file:ParseURL.java

public static void main(String[] args) throws Exception {
    URL aURL = new URL("http://java.sun.com:80/docs/books/" + "tutorial/index.html#DOWNLOADING");
    System.out.println("protocol = " + aURL.getProtocol());
    System.out.println("host = " + aURL.getHost());
    System.out.println("filename = " + aURL.getFile());
    System.out.println("port = " + aURL.getPort());
    System.out.println("ref = " + aURL.getRef());
}

From source file:com.hortonworks.registries.storage.tool.sql.TablesInitializer.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH)
            .desc("Root directory of script path").build());

    options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH)
            .desc("Config file path").build());

    options.addOption(Option.builder("m").numberOfArgs(1).longOpt(OPTION_MYSQL_JAR_URL_PATH)
            .desc("Mysql client jar url to download").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.CREATE.toString())
            .desc("Run sql migrations from scatch").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.DROP.toString())
            .desc("Drop all the tables in the target database").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.CHECK_CONNECTION.toString())
            .desc("Check the connection for configured data source").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.MIGRATE.toString())
            .desc("Execute schema migration from last check point").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.INFO.toString())
            .desc("Show the status of the schema migration compared to the target database").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.VALIDATE.toString())
            .desc("Validate the target database changes with the migration scripts").build());

    options.addOption(Option.builder().hasArg(false).longOpt(SchemaMigrationOption.REPAIR.toString()).desc(
            "Repairs the DATABASE_CHANGE_LOG by removing failed migrations and correcting checksum of existing migration script")
            .build());//  w  w  w.ja  v a  2  s .  com

    options.addOption(Option.builder().hasArg(false).longOpt(DISABLE_VALIDATE_ON_MIGRATE)
            .desc("Disable flyway validation checks while running migrate").build());

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption(OPTION_CONFIG_FILE_PATH) || !commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) {
        usage(options);
        System.exit(1);
    }

    boolean isSchemaMigrationOptionSpecified = false;
    SchemaMigrationOption schemaMigrationOptionSpecified = null;
    for (SchemaMigrationOption schemaMigrationOption : SchemaMigrationOption.values()) {
        if (commandLine.hasOption(schemaMigrationOption.toString())) {
            if (isSchemaMigrationOptionSpecified) {
                System.out.println(
                        "Only one operation can be execute at once, please select one of 'create', ',migrate', 'validate', 'info', 'drop', 'repair', 'check-connection'.");
                System.exit(1);
            }
            isSchemaMigrationOptionSpecified = true;
            schemaMigrationOptionSpecified = schemaMigrationOption;
        }
    }

    if (!isSchemaMigrationOptionSpecified) {
        System.out.println(
                "One of the option 'create', ',migrate', 'validate', 'info', 'drop', 'repair', 'check-connection' must be specified to execute.");
        System.exit(1);
    }

    String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH);
    String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH);
    String mysqlJarUrl = commandLine.getOptionValue(OPTION_MYSQL_JAR_URL_PATH);

    StorageProviderConfiguration storageProperties;
    Map<String, Object> conf;
    try {
        conf = Utils.readConfig(confFilePath);

        StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader();
        storageProperties = confReader.readStorageConfig(conf);
    } catch (IOException e) {
        System.err.println("Error occurred while reading config file: " + confFilePath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    String bootstrapDirPath = null;
    try {
        bootstrapDirPath = System.getProperty("bootstrap.dir");
        Proxy proxy = Proxy.NO_PROXY;
        String httpProxyUrl = (String) conf.get(HTTP_PROXY_URL);
        String httpProxyUsername = (String) conf.get(HTTP_PROXY_USERNAME);
        String httpProxyPassword = (String) conf.get(HTTP_PROXY_PASSWORD);
        if ((httpProxyUrl != null) && !httpProxyUrl.isEmpty()) {
            URL url = new URL(httpProxyUrl);
            proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url.getHost(), url.getPort()));
            if ((httpProxyUsername != null) && !httpProxyUsername.isEmpty()) {
                Authenticator.setDefault(getBasicAuthenticator(url.getHost(), url.getPort(), httpProxyUsername,
                        httpProxyPassword));
            }
        }
        MySqlDriverHelper.downloadMySQLJarIfNeeded(storageProperties, bootstrapDirPath, mysqlJarUrl, proxy);
    } catch (Exception e) {
        System.err.println("Error occurred while downloading MySQL jar. bootstrap dir: " + bootstrapDirPath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    boolean disableValidateOnMigrate = commandLine.hasOption(DISABLE_VALIDATE_ON_MIGRATE);
    if (disableValidateOnMigrate) {
        System.out.println("Disabling validation on schema migrate");
    }
    SchemaMigrationHelper schemaMigrationHelper = new SchemaMigrationHelper(
            SchemaFlywayFactory.get(storageProperties, scriptRootPath, !disableValidateOnMigrate));
    try {
        schemaMigrationHelper.execute(schemaMigrationOptionSpecified);
        System.out
                .println(String.format("\"%s\" option successful", schemaMigrationOptionSpecified.toString()));
    } catch (Exception e) {
        System.err.println(
                String.format("\"%s\" option failed : %s", schemaMigrationOptionSpecified.toString(), e));
        System.exit(1);
    }

}