Class HttpContextBuilder


  • public class HttpContextBuilder
    extends Object
    Helper class to create a ResteasyDeployment and bind it to an HttpContext of an HttpServer. Setting the SecurityDomain will turn on Basic Authentication. Right now, only BasicAuthentication is supported. HttpContext.getAttributes() data is available within Providers and Resources by injecting a ResteasyConfiguration interface
         HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 10);
         contextBuilder = new HttpContextBuilder();
         contextBuilder.getDeployment().getActualResourceClasses().add(SimpleResource.class);
         HttpContext context = contextBuilder.bind(httpServer);
         context.getAttributes().put("some.config.info", "42");
         httpServer.start();
    
         contextBuilder.cleanup();
         httpServer.stop(0);
     
    Create your HttpServer the way you want then use the org.jboss.resteasy.plugins.server.sun.http.HttpContextBuilder to initialize Resteasy and bind it to an HttpContext. The HttpContext attributes are available by injecting in a org.jboss.resteasy.spi.ResteasyConfiguration interface using @Context within your provider and resource classes.
    Author:
    Bill Burke* @version $Revision: 1 $
    • Constructor Detail

      • HttpContextBuilder

        public HttpContextBuilder()
    • Method Detail

      • getPath

        public String getPath()
      • setPath

        public void setPath​(String path)
        Path to bind context
        Parameters:
        path -
      • setSecurityDomain

        public void setSecurityDomain​(SecurityDomain securityDomain)
        Will turn on Basic Authentication
        Parameters:
        securityDomain -
      • bind

        public com.sun.net.httpserver.HttpContext bind​(com.sun.net.httpserver.HttpServer server)
      • cleanup

        public void cleanup()