String decodedBasePath = exchange.getHttpContext().getPath();
String decodedBasePath = exchange.getHttpContext().getPath();
@Override public void handle(HttpExchange he) throws IOException { System.out.println("Request " + count++); System.out.println(he.getHttpContext().getPath()); InputStream is = he.getRequestBody(); String response = "<font color='red'>Lets Learn Java8.</font>"; he.sendResponseHeaders(200, response.length()); OutputStream os = he.getResponseBody(); os.write(response.getBytes()); os.close(); } }
String contextPath = exchange.getHttpContext().getPath(); String path = PathHelper.getEncodedPathInfo(absoluteURI.getRawPath(), contextPath); if (!path.startsWith("/"))
public synchronized void removeContext (HttpContext context) throws IllegalArgumentException { if (!(context instanceof HttpContextImpl)) { throw new IllegalArgumentException ("wrong HttpContext type"); } contexts.remove ((HttpContextImpl)context); logger.config ("context removed: " + context.getPath()); }
@Override @Property(MessageContext.PATH_INFO) public String getPathInfo() { URI requestUri = httpExchange.getRequestURI(); String reqPath = requestUri.getPath(); String ctxtPath = httpExchange.getHttpContext().getPath(); if (reqPath.length() > ctxtPath.length()) { return reqPath.substring(ctxtPath.length()); } return null; }
@Override @Property(MessageContext.PATH_INFO) public String getPathInfo() { URI requestUri = httpExchange.getRequestURI(); String reqPath = requestUri.getPath(); String ctxtPath = httpExchange.getHttpContext().getPath(); if (reqPath.length() > ctxtPath.length()) { return reqPath.substring(ctxtPath.length()); } return null; }
public static String fetchPathInfo(HttpExchange httpExchange) { String baseRequestPath = httpExchange.getHttpContext().getPath(); //TODO: Caution, getRequestURI does most likely also return the querystring. URI requestURI = httpExchange.getRequestURI(); String requestPath = requestURI.getPath(); int startOfPathInfo = requestPath.indexOf(baseRequestPath) + baseRequestPath.length(); return requestPath.substring(startOfPathInfo); }
@Override @Property(MessageContext.PATH_INFO) public String getPathInfo() { URI requestUri = httpExchange.getRequestURI(); String reqPath = requestUri.getPath(); String ctxtPath = httpExchange.getHttpContext().getPath(); if (reqPath.length() > ctxtPath.length()) { return reqPath.substring(ctxtPath.length()); } return null; }
@Override public void publish(Object serverContext) { canPublish(); if (!com.sun.net.httpserver.HttpContext.class.isAssignableFrom(serverContext.getClass())) { throw new IllegalArgumentException(serverContext.getClass() + " is not a supported context."); } createEndpoint(((com.sun.net.httpserver.HttpContext)serverContext).getPath()); ((HttpEndpoint) actualEndpoint).publish(serverContext); }
@Override public void publish(Object serverContext) { canPublish(); if (!com.sun.net.httpserver.HttpContext.class.isAssignableFrom(serverContext.getClass())) { throw new IllegalArgumentException(serverContext.getClass() + " is not a supported context."); } createEndpoint(((com.sun.net.httpserver.HttpContext)serverContext).getPath()); ((HttpEndpoint) actualEndpoint).publish(serverContext); }
@Override public void publish(Object serverContext) { canPublish(); if (!com.sun.net.httpserver.HttpContext.class.isAssignableFrom(serverContext.getClass())) { throw new IllegalArgumentException(serverContext.getClass() + " is not a supported context."); } createEndpoint(((com.sun.net.httpserver.HttpContext)serverContext).getPath()); ((HttpEndpoint) actualEndpoint).publish(serverContext); }
public static final void redirect( final HttpExchange exchange, final URI uri, final String path ) throws IOException { try { final URI newUri = new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), exchange.getHttpContext().getPath() + path, uri.getQuery(), uri.getFragment() ); redirect( exchange, HttpResponseCode.REDIRECT_FOUND, newUri.toString() ); } catch( URISyntaxException use ) { throw new IOException( use ); } }
public static final void redirectPermanently( final HttpExchange exchange, final URI uri, final String path ) throws IOException { try { final URI newUri = new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), exchange.getHttpContext().getPath() + path, uri.getQuery(), uri.getFragment() ); redirect( exchange, HttpResponseCode.REDIRECT_MOVED_PERMANENTLY, newUri.toString() ); } catch( URISyntaxException use ) { throw new IOException( use ); } }
@Override public void processGet( final HttpExchange exchange ) throws IOException { // Get the file path , minus the context path final String fullPath = exchange.getRequestURI().getPath(); final String path = fullPath.substring( exchange.getHttpContext().getPath().length() ); try { final URL url = getClass().getResource( basePackage + path ); sendFile( exchange, url ); } catch( IOException ioe ) { throw ioe; } catch( Exception ex ) { RequestUtils.sendResponse( exchange, 500, "%s is forbidden", path ); } }
context.getPath(), httpServer.getAddress() );
/*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()); } } }
/*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()); } } }
/*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()); } } }
getLog().info( "%s: %s %s", exchange.getHttpContext().getPath(), method, exchange.getRequestURI() );