Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpServer


        final boolean isHttp = scheme.equalsIgnoreCase("http");
        final int port = (uri.getPort() == -1)
                ? (isHttp ? ConfigHelper.DEFAULT_HTTP_PORT : ConfigHelper.DEFAULT_HTTPS_PORT)
                : uri.getPort();

        final HttpServer server;
        try {
            server = isHttp
                    ? HttpServer.create(new InetSocketAddress(port), 0)
                    : HttpsServer.create(new InetSocketAddress(port), 0);
        } catch (final IOException ioe) {
            throw new ProcessingException(LocalizationMessages.ERROR_CONTAINER_EXCEPTION_IO(), ioe);
        }

        server.setExecutor(Executors.newCachedThreadPool());
        server.createContext(path, handler);

        final HttpServer wrapper = isHttp
                ? createHttpServerWrapper(server, handler)
                : createHttpsServerWrapper((HttpsServer) server, handler);

        if (start) {
            wrapper.start();
        }

        return wrapper;
    }
View Full Code Here


            }
        };
    }

    private static HttpServer createHttpServerWrapper(final HttpServer delegate, final JdkHttpHandlerContainer handler) {
        return new HttpServer() {

            @Override
            public void bind(final InetSocketAddress inetSocketAddress, final int i) throws IOException {
                delegate.bind(inetSocketAddress, i);
            }
View Full Code Here

        }
    }

    @Test
    public void testFetch() throws Exception {
        final HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
        final HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new Application() {

            @Override
            public Set<Class<?>> getClasses() {
                return Collections.<Class<?>>singleton(Resource.class);
            }
        }, HttpHandler.class);

        try {
            server.createContext("/", handler);
            server.start();

            final Response response = ClientBuilder.newClient()
                    .target(UriBuilder.fromUri("http://localhost/").port(server.getAddress().getPort()).build())
                    .request()
                    .get();

            assertThat(response.readEntity(String.class), is("get"));
        } finally {
            server.stop(0);
        }
    }
View Full Code Here

* @author Martin Matula (martin.matula at oracle.com)
*/
public class HelloWorldTest {
    @Test
    public void testHelloWorld() throws Exception {
        HttpServer server = App.startServer();

        WebTarget target = ClientBuilder.newClient().target(App.getBaseURI() + "helloworld");
        assertEquals(HelloWorldResource.CLICHED_MESSAGE, target.request(MediaType.TEXT_PLAIN).get(String.class));

        server.stop(0);
    }
View Full Code Here

    System.out.println("Starting Ambari API server using the following properties: " + mapArgs);
    System.setProperty("ambariapi.dbfile", mapArgs.get("db"));

    ResourceConfig config = new PackagesResourceConfig("org.apache.ambari.server.api.services");
    System.out.println("Starting server: http://localhost:" + mapArgs.get("port") + '/');
    HttpServer server = HttpServerFactory.create("http://localhost:" + mapArgs.get("port") + '/', config);
    server.start();

    System.out.println("SERVER RUNNING: http://localhost:" + mapArgs.get("port") + '/');
    System.out.println("Hit return to stop...");
    System.in.read();
    System.out.println("Stopping server");
    server.stop(0);
    System.out.println("Server stopped");
  }
View Full Code Here

            opts[0] = new Option("--help", "-h", false);
            opts[1] = new Option("--accept", "-a", true);
            if (!parseOptions(args, opts)) {
                return;
            }
            HttpServer server = HttpServer.create(
                    new InetSocketAddress((Integer) opts[1].value), 0);
            server.createContext("/", new MyHandler());
            server.setExecutor(null);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }        // TODO code application logic here
View Full Code Here

      httpPort = 80;
    } else {
      httpPort = Integer.parseInt(port);
    }

    HttpServer server;
    server = HttpServer.create(new InetSocketAddress(httpPort), 0);
    server.createContext("/sw_version.txt", new SimpleHandler());
    server.setExecutor(null);

    return server;
  }
View Full Code Here

      //TODO port eventuell variabel machen

      BufferedReader in = new BufferedReader( new InputStreamReader( System.in ));

      ResourceConfig config = new ResourceConfig(DependencyRestService.class);
      HttpServer server = this.startServer( config ) ;

      if (Desktop.isDesktopSupported())
      {
        Desktop desktop=Desktop.getDesktop();


        File tempDir = com.google.common.io.Files.createTempDir();
        tempDir.deleteOnExit();

        this.transferResourceToTmp( "clashInspectorStyle", "css",tempDir,false );
        this.transferResourceToTmp( "jquery-1.11.0", "js",tempDir ,false);
        this.transferResourceToTmp( "main", "js",tempDir,true );
        this.transferResourceToTmp( "openDepNode", "png",tempDir,false );
        this.transferResourceToTmp( "openDepNode_hasWinner", "png",tempDir,false );
        this.transferResourceToTmp( "clashinspectorLogo", "jpg",tempDir,false );
        this.transferResourceToTmp( "fhReutlingenLogo", "jpg",tempDir,false );
        this.transferResourceToTmp( "legendArrowHasDependencies", "png",tempDir,false );
        this.transferResourceToTmp( "legendArrowHasUnsafeDependencies", "png",tempDir,false );
        this.transferResourceToTmp( "legendArrowHasCriticalDependencies", "png",tempDir,false );
        this.transferResourceToTmp( "legendArrowHasUnresolvedDependencies", "png",tempDir,false );
        this.transferResourceToTmp( "legendScopes_long", "png",tempDir,false );
        this.transferResourceToTmp( "legendOptional", "png",tempDir,false );




        desktop.browse(this.transferResourceToTmp( "clashInspector", "html",tempDir,false ));
      }
      else
      {
        super.getLog().warn( "Couldn't open File with default-browser. Please open file manually under: " + System.getProperty("java.io.tmpdir")+"clashInspector.html" );
      }


      super.getLog().info( "Local ClashInspector-Server running on port "+port+". To stop server press enter." );


      String inLine = in.readLine();
      server.stop( 0 );


    }
    catch ( Exception e ) {
      throw new MojoFailureException( e.getMessage(), e );
View Full Code Here

      private HttpServer startServer(ResourceConfig resourceConfig) throws Exception {


        try
        {
          HttpServer server = JdkHttpServerFactory.createHttpServer(new URI( "http://localhost:"+port+"/"), resourceConfig );
          return server;
        }
        catch(ProcessingException processingException)
        {
          if(this.port>8050)
View Full Code Here

      //TODO port eventuell variabel machen

      BufferedReader in = new BufferedReader( new InputStreamReader( System.in ));

      ResourceConfig config = new ResourceConfig(DependencyRestService.class);
      HttpServer server = JdkHttpServerFactory.createHttpServer(new URI( "http://localhost:"+port+"/"), config );


      if (Desktop.isDesktopSupported())
      {
        Desktop desktop=Desktop.getDesktop();


        this.transferResourceToTmp( "clashInspectorStyle", "css" );
        this.transferResourceToTmp( "jquery-1.11.0", "js" );
        this.transferResourceToTmp( "main", "js" );
        this.transferResourceToTmp( "openDepNode", "png" );
        this.transferResourceToTmp( "openDepNode_hasWinner", "png" );
        this.transferResourceToTmp( "clashinspectorLogo", "jpg" );
        this.transferResourceToTmp( "fhReutlingenLogo", "jpg" );
        this.transferResourceToTmp( "legendArrowHasDependencies", "png" );
        this.transferResourceToTmp( "legendArrowHasUnsafeDependencies", "png" );
        this.transferResourceToTmp( "legendArrowHasCriticalDependencies", "png" );
        this.transferResourceToTmp( "legendArrowHasUnresolvedDependencies", "png" );
        this.transferResourceToTmp( "legendScopes_long", "png" );
        this.transferResourceToTmp( "legendOptional", "png" );








        desktop.browse(this.transferResourceToTmp( "clashInspector", "html" ));
      }
      else
      {
        super.getLog().warn( "Couldn't open File with default-browser. Please open file manually under: " + System.getProperty("java.io.tmpdir")+"clashInspector.html" );
      }


      super.getLog().info( "Local ClashInspector-Server running on port "+port+". To stop server press enter." );


      String inLine = in.readLine();
      server.stop( 0 );


    }
    catch ( Exception e ) {
      throw new MojoFailureException( e.getMessage(), e );
View Full Code Here

TOP

Related Classes of com.sun.net.httpserver.HttpServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.