Example usage for java.net URL toExternalForm

List of usage examples for java.net URL toExternalForm

Introduction

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

Prototype

public String toExternalForm() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL relativeURL, baseURL;
    baseURL = new URL("http://www.yourserver.com/");
    relativeURL = new URL(baseURL, "./a.htm");
    System.out.println(relativeURL.toExternalForm());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL relativeURL, baseURL;
    baseURL = new URL("http://www.java2s.com/abc/d.htm");
    relativeURL = new URL(baseURL, "../a.htm");
    System.out.println(relativeURL.toExternalForm());

}

From source file:com.gvmax.web.WebMain.java

@SuppressWarnings("deprecation")
public static void main(String[] args) {
    try {/*from   w w w. j a  va  2 s.c o  m*/
        MetricRegistry registry = MetricsUtil.getRegistry();
        Properties props = new Properties();
        props.load(new ClassPathResource("/web.properties").getInputStream());

        int httpPort = Integer.parseInt(props.getProperty("web.http.port", "19080"));
        int httpsPort = Integer.parseInt(props.getProperty("web.https.port", "19443"));
        logger.info("Starting server: " + httpPort + " :: " + httpsPort);

        Server server = new Server(httpPort);
        ThreadPool threadPool = new InstrumentedQueuedThreadPool(registry);
        server.setThreadPool(threadPool);

        // Setup HTTPS
        if (new File("gvmax.jks").exists()) {
            SslSocketConnector connector = new SslSocketConnector();
            connector.setPort(httpsPort);
            connector.setKeyPassword(props.getProperty("web.keystore.password"));
            connector.setKeystore("gvmax.jks");
            server.addConnector(connector);
        } else {
            logger.warn("keystore gvmax.jks not found, ssl disabled");
        }

        // Setup WEBAPP
        URL warUrl = WebMain.class.getClassLoader().getResource("webapp");
        String warUrlString = warUrl.toExternalForm();
        WebAppContext ctx = new WebAppContext(warUrlString, "/");
        ctx.setAttribute(MetricsServlet.METRICS_REGISTRY, registry);
        InstrumentedHandler handler = new InstrumentedHandler(registry, ctx);
        server.setHandler(handler);
        server.start();
        server.join();
    } catch (Exception e) {
        logger.error(e);
        System.exit(0);
    }
}

From source file:alpine.embedded.EmbeddedJettyServer.java

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

    final CliArgs cliArgs = new CliArgs(args);
    final String contextPath = cliArgs.switchValue("-context", "/");
    final String host = cliArgs.switchValue("-host", "0.0.0.0");
    final int port = cliArgs.switchIntegerValue("-port", 8080);

    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();/*from   www  .  ja  va 2s  .  c  o  m*/

    final Server server = new Server();
    final ServerConnector connector = new ServerConnector(server);
    connector.setHost(host);
    connector.setPort(port);
    server.setConnectors(new Connector[] { connector });

    final WebAppContext context = new WebAppContext();
    context.setServer(server);
    context.setContextPath(contextPath);
    context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
            ".*/[^/]*taglibs.*\\.jar$");
    context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
    context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    context.addBean(new ServletContainerInitializersStarter(context), true);

    // Prevent loading of logging classes
    context.getSystemClasspathPattern().add("org.apache.log4j.");
    context.getSystemClasspathPattern().add("org.slf4j.");
    context.getSystemClasspathPattern().add("org.apache.commons.logging.");

    final ProtectionDomain protectionDomain = EmbeddedJettyServer.class.getProtectionDomain();
    final URL location = protectionDomain.getCodeSource().getLocation();
    context.setWar(location.toExternalForm());

    server.setHandler(context);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

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:org.zaizi.sensefy.api.SensefyResourceApplication.java

public static void main(String[] args) {
    SpringApplication.run(SensefyResourceApplication.class, args);
    int port = Integer.parseInt(System.getProperty("jetty.port", "8080"));
    int requestHeaderSize = Integer.parseInt(System.getProperty("jetty.header.size", "65536"));
    Server server = new Server(port);
    server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1);
    ProtectionDomain domain = SensefyResourceApplication.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    // Set request header size
    //   server.getConnectors()[0].setRequestHeaderSize(requestHeaderSize);

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/api");
    webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
    webapp.setServer(server);//from  w ww. ja va 2s  . c  o  m
    webapp.setWar(location.toExternalForm());

    // (Optional) Set the directory the war will extract to.
    // If not set, java.io.tmpdir will be used, which can cause problems
    // if the temp directory gets cleaned periodically.
    // Your build scripts should remove this directory between deployments
    // webapp.setTempDirectory(new File("/path/to/webapp-directory"));

    server.setHandler(webapp);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:embedding.events.ExampleEvents.java

/**
 * Main method./*  ww  w .ja  v a2 s .co  m*/
 * @param args command-line arguments
 */
public static void main(String[] args) {
    try {
        System.out.println("FOP ExampleEvents\n");
        System.out.println("Preparing...");

        //Setup directories
        File baseDir = new File(".");
        File outDir = new File(baseDir, "out");
        outDir.mkdirs();

        //Setup input and output files
        URL fo = ExampleEvents.class.getResource("missing-image.fo");
        File pdffile = new File(outDir, "out.pdf");

        System.out.println("Input: XSL-FO (" + fo.toExternalForm() + ")");
        System.out.println("Output: PDF (" + pdffile + ")");
        System.out.println();
        System.out.println("Transforming...");

        ExampleEvents app = new ExampleEvents();

        try {
            app.convertFO2PDF(fo, pdffile);
        } catch (TransformerException te) {
            //Note: We don't get the original exception here!
            //FOP needs to embed the exception in a SAXException and the TraX transformer
            //again wraps the SAXException in a TransformerException. Even our own
            //RuntimeException just wraps the original FileNotFoundException.
            //So we need to unpack to get the original exception (about three layers deep).
            Throwable originalThrowable = getOriginalThrowable(te);
            originalThrowable.printStackTrace(System.err);
            System.out.println("Aborted!");
            System.exit(-1);
        }

        System.out.println("Success!");
    } catch (Exception e) {
        //Some other error (shouldn't happen in this example)
        e.printStackTrace(System.err);
        System.exit(-1);
    }
}

From source file:org.zaizi.sensefy.ui.SensefySearchUiApplication.java

public static void main(String[] args) {
    // SpringApplication.run(SensefySearchUiApplication.class, args);

    SpringApplication.run(SensefySearchUiApplication.class, args);
    int port = Integer.parseInt(System.getProperty("jetty.port", "8080"));
    int requestHeaderSize = Integer.parseInt(System.getProperty("jetty.header.size", "65536"));
    Server server = new Server(port);
    ProtectionDomain domain = SensefySearchUiApplication.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    // Set request header size
    // server.getConnectors()[0].setRequestHeaderSize(requestHeaderSize);

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/ui");
    webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
    webapp.setServer(server);//from w  w w.java2s .c  o m
    webapp.setWar(location.toExternalForm());

    // (Optional) Set the directory the war will extract to.
    // If not set, java.io.tmpdir will be used, which can cause problems
    // if the temp directory gets cleaned periodically.
    // Your build scripts should remove this directory between deployments
    // webapp.setTempDirectory(new File("/path/to/webapp-directory"));

    server.setHandler(webapp);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.zaizi.sensefy.auth.AuthServerApplication.java

public static void main(String[] args) {
    SpringApplication.run(AuthServerApplication.class, args);

    int port = Integer.parseInt(System.getProperty("jetty.port", "8080"));
    int requestHeaderSize = Integer.parseInt(System.getProperty("jetty.header.size", "65536"));
    Server server = new Server(port);
    server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1);
    ProtectionDomain domain = AuthServerApplication.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    // Set request header size
    // server.getConnectors()[0].setRequestHeaderSize(requestHeaderSize);

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/auth");
    webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
    webapp.setServer(server);/*from  www  .  ja  va  2  s.  co m*/
    webapp.setWar(location.toExternalForm());

    // (Optional) Set the directory the war will extract to.
    // If not set, java.io.tmpdir will be used, which can cause problems
    // if the temp directory gets cleaned periodically.
    // Your build scripts should remove this directory between deployments
    // webapp.setTempDirectory(new File("/path/to/webapp-directory"));

    server.setHandler(webapp);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:RedPenRunner.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "help");
    options.addOption("v", "version", false, "print the version information and exit");

    OptionBuilder.withLongOpt("port");
    OptionBuilder.withDescription("port number");
    OptionBuilder.hasArg();/* w ww  .  j av  a 2  s .com*/
    OptionBuilder.withArgName("PORT");
    options.addOption(OptionBuilder.create("p"));

    OptionBuilder.withLongOpt("key");
    OptionBuilder.withDescription("stop key");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("STOP_KEY");
    options.addOption(OptionBuilder.create("k"));

    OptionBuilder.withLongOpt("conf");
    OptionBuilder.withDescription("configuration file");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("CONFIG_FILE");
    options.addOption(OptionBuilder.create("c"));

    OptionBuilder.withLongOpt("lang");
    OptionBuilder.withDescription("Language of error messages");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("LANGUAGE");
    options.addOption(OptionBuilder.create("L"));

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = null;

    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        printHelp(options);
        System.exit(-1);
    }

    int portNum = 8080;
    String language = "en";
    if (commandLine.hasOption("h")) {
        printHelp(options);
        System.exit(0);
    }
    if (commandLine.hasOption("v")) {
        System.out.println(RedPen.VERSION);
        System.exit(0);
    }
    if (commandLine.hasOption("p")) {
        portNum = Integer.parseInt(commandLine.getOptionValue("p"));
    }
    if (commandLine.hasOption("L")) {
        language = commandLine.getOptionValue("L");
    }
    if (isPortTaken(portNum)) {
        System.err.println("port is taken...");
        System.exit(1);
    }

    // set language
    if (language.equals("ja")) {
        Locale.setDefault(new Locale("ja", "JA"));
    } else {
        Locale.setDefault(new Locale("en", "EN"));
    }

    final String contextPath = System.getProperty("redpen.home", "/");

    Server server = new Server(portNum);
    ProtectionDomain domain = RedPenRunner.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    HandlerList handlerList = new HandlerList();
    if (commandLine.hasOption("key")) {
        // Add Shutdown handler only when STOP_KEY is specified
        ShutdownHandler shutdownHandler = new ShutdownHandler(commandLine.getOptionValue("key"));
        handlerList.addHandler(shutdownHandler);
    }

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(contextPath);
    if (location.toExternalForm().endsWith("redpen-server/target/classes/")) {
        // use redpen-server/target/redpen-server instead, because target/classes doesn't contain web resources.
        webapp.setWar(location.toExternalForm() + "../redpen-server/");
    } else {
        webapp.setWar(location.toExternalForm());
    }
    if (commandLine.hasOption("c")) {
        webapp.setInitParameter("redpen.conf.path", commandLine.getOptionValue("c"));
    }

    handlerList.addHandler(webapp);
    server.setHandler(handlerList);

    server.start();
    server.join();
}