/** * Build the HttpContext for the given endpoint. * @param endpoint the JAX-WS Provider Endpoint object * @param serviceName the given service name * @return the fully populated HttpContext */ protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) { Assert.state(this.server != null, "No HttpServer available"); String fullPath = calculateEndpointPath(endpoint, serviceName); HttpContext httpContext = this.server.createContext(fullPath); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } return httpContext; }
String decodedBasePath = exchange.getHttpContext().getPath();
@Override public Set<String> getParameterNames() { return context.getAttributes().keySet(); }
/** * Enable authentication for this endpoint * * @param context The context to enable authentication for. * @param credentials The optional credentials to enforce. This is a (key,value) pair */ private static void withAuth(HttpContext context, Optional<Pair<String,String>> credentials) { credentials.ifPresent(c -> context.setAuthenticator(new BasicAuthenticator("corenlp") { @Override public boolean checkCredentials(String user, String pwd) { return user.equals(c.first) && pwd.equals(c.second); } })); }
public HttpContext bind(HttpServer server) { handler = new ResteasyHttpHandler(); boundContext = server.createContext(path, handler); HttpContextResteasyConfiguration config = new HttpContextResteasyConfiguration(boundContext); deployment.getDefaultContextObjects().put(ResteasyConfiguration.class, config); if (securityDomain != null) { boundContext.getFilters().add(new BasicAuthFilter(securityDomain)); } deployment.start(); handler.setDispatcher(deployment.getDispatcher()); handler.setProviderFactory(deployment.getProviderFactory()); return boundContext; }
public static String fetchRequestScheme(HttpExchange httpExchange) { if (httpExchange.getHttpContext().getServer() instanceof HttpsServer) { return URL_SCHEME_HTTPS; } return URL_SCHEME_HTTP; }
@Override public void setHandler(HttpHandler handler) { if (handler instanceof com.sun.net.httpserver.HttpHandler) { delegate.setHandler((com.sun.net.httpserver.HttpHandler) handler); } else { delegate.setHandler(new HttpHandlerDelegate(handler)); } }
/** * Initialize this JolokiaServer with the given HttpServer. The calle is responsible for managing (starting/stopping) * the HttpServer. * * @param pServer server to use * @param pConfig configuration * @param pLazy whether the initialization should be done lazy or not */ protected final void init(HttpServer pServer, JolokiaServerConfig pConfig, boolean pLazy) { config = pConfig; lazy = pLazy; // Create proper context along with handler final String contextPath = pConfig.getContextPath(); jolokiaHttpHandler = new JolokiaHttpHandler(pConfig.getJolokiaConfig()); HttpContext context = pServer.createContext(contextPath, jolokiaHttpHandler); // Add authentication if configured final Authenticator authenticator = pConfig.getAuthenticator(); if (authenticator != null) { context.setAuthenticator(authenticator); } url = detectAgentUrl(pServer, pConfig, contextPath); }
/*package*/ void removeContext(HttpContext context) { InetSocketAddress inetAddress = context.getServer().getAddress(); synchronized(servers) { ServerState state = servers.get(inetAddress); int instances = state.noOfContexts(); if (instances < 2) { ((ExecutorService)state.getServer().getExecutor()).shutdown(); state.getServer().stop(0); servers.remove(inetAddress); } else { state.getServer().removeContext(context); state.oneLessContext(context.getPath()); } } }
HttpContext c2d = httpServer.createContext("/mil-sym-service/renderer/mp2d/", new MultiPointHandler(true)); c3d.getFilters().add(new ParameterFilter()); c2d.getFilters().add(new ParameterFilter()); httpServer.setExecutor(Executors.newCachedThreadPool()); } catch(BindException bexc){
/** * This can be called only after publish * @return address of the Endpoint */ private String getEPRAddress() { if (address == null) return httpContext.getServer().getAddress().toString(); try { URL u = new URL(address); if (u.getPort() == 0) { return new URL(u.getProtocol(),u.getHost(), httpContext.getServer().getAddress().getPort(),u.getFile()).toString(); } } catch (MalformedURLException murl) {} return address; }
private void setHandler(HttpContext context) { context.setHandler(new WSHttpHandler(adapter, executor)); }
@Override public void afterPropertiesSet() throws IOException { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); this.server = HttpServer.create(address, this.backlog); if (this.executor != null) { this.server.setExecutor(this.executor); } if (this.contexts != null) { this.contexts.forEach((key, context) -> { HttpContext httpContext = this.server.createContext(key, context); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } }); } if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } this.server.start(); }
String decodedBasePath = exchange.getHttpContext().getPath();
/** * Enable authentication for this endpoint * * @param context The context to enable authentication for. * @param credentials The optional credentials to enforce. This is a (key,value) pair */ private static void withAuth(HttpContext context, Optional<Pair<String,String>> credentials) { credentials.ifPresent(c -> context.setAuthenticator(new BasicAuthenticator("corenlp") { @Override public boolean checkCredentials(String user, String pwd) { return user.equals(c.first) && pwd.equals(c.second); } })); }
/*package*/ void removeContext(HttpContext context) { InetSocketAddress inetAddress = context.getServer().getAddress(); synchronized(servers) { ServerState state = servers.get(inetAddress); int instances = state.noOfContexts(); if (instances < 2) { ((ExecutorService)state.getServer().getExecutor()).shutdown(); state.getServer().stop(0); servers.remove(inetAddress); } else { state.getServer().removeContext(context); state.oneLessContext(context.getPath()); } } }
HttpContext c2d = httpServer.createContext("/mil-sym-service/renderer/mp2d/", new MultiPointHandler(true)); c3d.getFilters().add(new ParameterFilter()); c2d.getFilters().add(new ParameterFilter()); httpServer.setExecutor(Executors.newCachedThreadPool()); } catch(BindException bexc){
/** * This can be called only after publish * @return address of the Endpoint */ private String getEPRAddress() { if (address == null) return httpContext.getServer().getAddress().toString(); try { URL u = new URL(address); if (u.getPort() == 0) { return new URL(u.getProtocol(),u.getHost(), httpContext.getServer().getAddress().getPort(),u.getFile()).toString(); } } catch (MalformedURLException murl) {} return address; }
private void setHandler(HttpContext context) { context.setHandler(new WSHttpHandler(adapter, executor)); }