Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpContext


       
        //make a new Server
        JettyHttpServer httpServer = new JettyHttpServer();
        httpServer.bind(new InetSocketAddress ("localhost", 8080), 0);
       
        HttpContext context = httpServer.createContext("/foo", new FooHandler());
        context.getAttributes().put("fooAttribute", "fooValue");
        context.getFilters().add(new FooFilter());
        context.getFilters().add(new BarFilter());      
        context.setAuthenticator(new FooBasicAuthenticator("foorealm"));
       
        httpServer.start()
      
        URL url = new URL("http://localhost:8080/foo");      
        HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
View Full Code Here


 
  @Override
  protected void exposeService(Object service, String context)
      throws Exception {
   
    HttpContext httpsContext = httpsServer.createContext(context);
   
    Endpoint endpoint = Endpoint.create(service);
   
    endpoint.publish(httpsContext);
   
View Full Code Here

    super.afterPropertiesSet();
  }

  protected void publishEndpoint(Endpoint endpoint, WebService annotation) {
    String fullPath = this.basePath + annotation.serviceName();
    HttpContext httpContext = this.server.createContext(fullPath);
    if (this.filters != null) {
      httpContext.getFilters().addAll(this.filters);
    }
    if (this.authenticator != null) {
      httpContext.setAuthenticator(this.authenticator);
    }
    endpoint.publish(httpContext);
  }
View Full Code Here

    if (this.executor != null) {
      this.server.setExecutor(this.executor);
    }
    if (this.contexts != null) {
      for (String key : this.contexts.keySet()) {
        HttpContext httpContext = this.server.createContext(key, this.contexts.get(key));
        if (this.filters != null) {
          httpContext.getFilters().addAll(this.filters);
        }
        if (this.authenticator != null) {
          httpContext.setAuthenticator(this.authenticator);
        }
      }
    }
    if (this.logger.isInfoEnabled()) {
      this.logger.info("Starting HttpServer at address " + address);
View Full Code Here

    */
  public void start() throws java.io.IOException {
    _webServer = HttpServer.create(new InetSocketAddress(_port), _backlog);
    _webServer.setExecutor(Executors.newFixedThreadPool(_threadCount));

    HttpContext context = _webServer.createContext("/", this);
    context.setAuthenticator(new WikiAuthenticator("/", _authenticationMode, _users));

    for (int iWiki = 0; iWiki < _wikiListing.size(); iWiki++) {
      DatabaseWikiHttpHandler wiki = _wikiListing.get(iWiki);
      context = _webServer.createContext("/" + wiki.name(), wiki);
      context.setAuthenticator(wiki.authenticator());
    }
       
    System.out.println("START SERVER ON ADDRESS " + _webServer.getAddress() + " AT " + new java.util.Date().toString());

    _webServer.start();
View Full Code Here

      // this should now only be called when starting a web server
      assert(_webServer != null);

      String realm = wiki.database().identifier().databaseHomepage();
      HttpContext context = _webServer.createContext(realm, wiki);
      context.setAuthenticator(authenticator);
     
      _wikiListing.add(wiki);
      Collections.sort(_wikiListing);
      //
      // Import data into created database wiki if the user specified an import resource.
View Full Code Here

      // Create a EHS on the current machine on port 8123
      HttpServer ehs = HttpServer.create(new InetSocketAddress(InetAddress.getLocalHost(), 8123), 50);
      // Add a context associating a handler with a URI pattern
      // See URL below for details about handler and URI pattern :
      // http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html
      HttpContext ctx = ehs.createContext("/jse6ehs", new SimpleHttpHandler());
      // Add a authenticator to the context
      ctx.setAuthenticator(new SimpleBasicAuthenticator("JSE6EHS Realm"));
      // Add filters to the context
      ctx.getFilters().add(new SimpleFilter("Filter01"));
      ctx.getFilters().add(new SimpleFilter("Filter02"));
      ctx.getFilters().add(new SimpleFilter("Filter03"));
      // Start the server
      ehs.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

    @Test
    public void restGatewayReferenceTimeout() throws Exception {
        HttpServer httpServer = HttpServer.create(new InetSocketAddress(8090), 10);
        httpServer.setExecutor(null); // creates a default executor
        httpServer.start();
        HttpContext httpContext = httpServer.createContext("/forever", new HttpHandler() {
            public void handle(HttpExchange exchange) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException ie) {
                        //Ignore
View Full Code Here

                     + "   <arg0>Hello</arg0>"
                     + "</test:sayHello>").getDocumentElement();
        HttpServer httpServer = HttpServer.create(new InetSocketAddress(8090), 10);
        httpServer.setExecutor(null); // creates a default executor
        httpServer.start();
        HttpContext httpContext = httpServer.createContext("/forever", new HttpHandler() {
            public void handle(HttpExchange exchange) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException ie) {
                        //Ignore
View Full Code Here

                    logger.fine("Creating new HTTP Server at "+inetAddress);
                    server = HttpServer.create(inetAddress, 5);
                    server.setExecutor(Executors.newCachedThreadPool());
                    String path = url.toURI().getPath();
                    logger.fine("Creating HTTP Context at = "+path);
                    HttpContext context = server.createContext(path);
                    server.start();
                    logger.fine("HTTP server started = "+inetAddress);
                    state = new ServerState(server);
                    servers.put(inetAddress, state);
                    return context;
                }
            }
            server = state.getServer();
            logger.fine("Creating HTTP Context at = "+url.getPath());
            HttpContext context = server.createContext(url.getPath());
            state.oneMoreContext();
            return context;
        } catch(Exception e) {
            throw new ServerRtException("server.rt.err",e );
        }
View Full Code Here

TOP

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

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.