如果您想了解GAE“没有属性“HTTPSHandler””dev_appserver.py和没有属性怎么办的知识,那么本篇文章将是您的不二之选。我们将深入剖析GAE“没有属性“HTTPSHandler
如果您想了解GAE“没有属性“ HTTPSHandler”” dev_appserver.py和没有属性怎么办的知识,那么本篇文章将是您的不二之选。我们将深入剖析GAE“没有属性“ HTTPSHandler”” dev_appserver.py的各个方面,并为您解答没有属性怎么办的疑在这篇文章中,我们将为您介绍GAE“没有属性“ HTTPSHandler”” dev_appserver.py的相关知识,同时也会详细的解释没有属性怎么办的运用方法,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- GAE“没有属性“ HTTPSHandler”” dev_appserver.py(没有属性怎么办)
- com.sun.net.httpserver.HttpHandler的实例源码
- com.sun.net.httpserver.HttpsExchange的实例源码
- com.sun.net.httpserver.spi.HttpServerProvider的实例源码
- dev_appserver.py 找不到 pkg_resources
GAE“没有属性“ HTTPSHandler”” dev_appserver.py(没有属性怎么办)
我正在尝试从我的ubuntu lucid使用google appengine python SKD。我已经编译了python2.5。但是,当我用它执行任何“
dev_appserver.py”命令时,会出现以下错误:
Traceback (most recent call last): File "dev_appserver.py", line 69, in <module> run_file(__file__, globals()) File "dev_appserver.py", line 65, in run_file execfile(script_path, globals_) File "/home/rohan/workspace/app_en/google_appengine/google/appengine/tools/dev_appserver_main.py", line 90, in <module> from google.appengine.tools import appcfg File "/media/Ultimate/WebD/django/app_engine/google_appengine/google/appengine/tools/appcfg.py", line 59, in <module> from google.appengine.tools import appengine_rpc File "/media/Ultimate/WebD/django/app_engine/google_appengine/google/appengine/tools/appengine_rpc.py", line 24, in <module> import fancy_urllib File "/media/Ultimate/WebD/django/app_engine/google_appengine/lib/fancy_urllib/fancy_urllib/__init__.py", line 328, in <module> class FancyHTTPSHandler(urllib2.HTTPSHandler):AttributeError: ''module'' object has no attribute ''HTTPSHandler''
我已经检查了python2.6和python2.5的urllib2模块,但是模型定义没有区别,并且python2.5中也有HTTPSHandelr。所以我想这是其他错误。
我也尝试使用默认的python2.6运行,但是随后出现以下错误:
WARNING 2010-09-11 12:08:40,848 datastore_file_stub.py:657] Could not read datastore data from /tmp/dev_appserver.datastoreTraceback (most recent call last): File "./dev_appserver.py", line 69, in <module> run_file(__file__, globals()) File "./dev_appserver.py", line 65, in run_file execfile(script_path, globals_) File "/home/rohan/workspace/app_en/google_appengine/google/appengine/tools/dev_appserver_main.py", line 449, in <module> sys.exit(main(sys.argv)) File "/home/rohan/workspace/app_en/google_appengine/google/appengine/tools/dev_appserver_main.py", line 426, in main static_caching=static_caching) File "/home/rohan/workspace/app_en/google_appengine/google/appengine/tools/dev_appserver.py", line 3820, in CreateServer server = HTTPServerWithScheduler((serve_address, port), handler_class) File "/home/rohan/workspace/app_en/google_appengine/google/appengine/tools/dev_appserver.py", line 3840, in __init__ request_handler_class) File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ self.server_bind() File "/usr/lib/python2.6/BaseHTTPServer.py", line 108, in server_bind SocketServer.TCPServer.server_bind(self) File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind self.socket.bind(self.server_address) File "<string>", line 1, in bindsocket.error: [Errno 98] Address already in use
它在窗户甚至酒下也能很好地工作。 解决了python2.6的
更新
问题。
我早些时候已经为8080和80端口上的Django部署配置了apache服务器。
但是python2.5 istallation仍然存在相同的错误。
答案1
小编典典解决了问题…只需使用以下命令即可构建python的所有依赖项:
apt-get build-dep python
即使没有安装所有依赖项,python编译也不会出错。它只是跳过需要它们的模块并构建python。
com.sun.net.httpserver.HttpHandler的实例源码
@Override public HttpHandler getServlet() { return exchange -> { final ByteArrayOutputStream response = new ByteArrayOutputStream(1 << 20); final OutputStreamWriter osw = new OutputStreamWriter(response); textformat.write004(osw,registry.metricFamilySamples()); osw.flush(); osw.close(); response.flush(); response.close(); exchange.getResponseHeaders().set("Content-Type",textformat.CONTENT_TYPE_004); exchange.getResponseHeaders().set("Content-Length",String.valueOf(response.size())); exchange.sendResponseHeaders(200,response.size()); response.writeto(exchange.getResponseBody()); exchange.close(); }; }
public static void initServer() throws Exception { String portstring = System.getProperty("port.number"); port = portstring != null ? Integer.parseInt(portstring) : 0; portstring = System.getProperty("port.number1"); proxyPort = portstring != null ? Integer.parseInt(portstring) : 0; Logger logger = Logger.getLogger("com.sun.net.httpserver"); ConsoleHandler ch = new ConsoleHandler(); logger.setLevel(Level.ALL); ch.setLevel(Level.ALL); logger.addHandler(ch); String root = System.getProperty ("test.src")+ "/docs"; InetSocketAddress addr = new InetSocketAddress (port); s1 = HttpServer.create (addr,0); if (s1 instanceof HttpsServer) { throw new RuntimeException ("should not be httpsserver"); } HttpHandler h = new FileServerHandler (root); HttpContext c = s1.createContext ("/files",h); HttpHandler h1 = new RedirectHandler ("/redirect"); HttpContext c1 = s1.createContext ("/redirect",h1); executor = Executors.newCachedThreadPool(); s1.setExecutor (executor); s1.start(); if (port == 0) port = s1.getAddress().getPort(); else { if (s1.getAddress().getPort() != port) throw new RuntimeException("Error wrong port"); System.out.println("Port was assigned by Driver"); } System.out.println("HTTP server port = " + port); httproot = "http://127.0.0.1:" + port + "/files/"; redirectroot = "http://127.0.0.1:" + port + "/redirect/"; uri = new URI(httproot); fileuri = httproot + "foo.txt"; }
static HttpServer createHttpsServer() throws IOException,NoSuchAlgorithmException { HttpsServer server = com.sun.net.httpserver.HttpsServer.create(); HttpContext context = server.createContext(PATH); context.setHandler(new HttpHandler() { @Override public void handle(HttpExchange he) throws IOException { he.getResponseHeaders().add("encoding","UTF-8"); he.sendResponseHeaders(200,RESPONSE.length()); he.getResponseBody().write(RESPONSE.getBytes(StandardCharsets.UTF_8)); he.close(); } }); server.setHttpsConfigurator(new Configurator(SSLContext.getDefault())); server.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(),0),0); return server; }
public static HTTPTestServer createServer(HttpProtocolType protocol,HttpAuthType authType,HttpTestAuthenticator auth,HttpSchemeType schemeType,HttpHandler delegate,String path) throws IOException { Objects.requireNonNull(authType); Objects.requireNonNull(auth); HttpServer impl = createHttpServer(protocol); final HTTPTestServer server = new HTTPTestServer(impl,null,delegate); final HttpHandler hh = server.createHandler(schemeType,auth,authType); HttpContext ctxt = impl.createContext(path,hh); server.configureAuthentication(ctxt,schemeType,authType); impl.start(); return server; }
public static HTTPTestServer createProxy(HttpProtocolType protocol,String path) throws IOException { Objects.requireNonNull(authType); Objects.requireNonNull(auth); HttpServer impl = createHttpServer(protocol); final HTTPTestServer server = protocol == HttpProtocolType.HTTPS ? new HttpsProxyTunnel(impl,delegate) : new HTTPTestServer(impl,authType); impl.start(); return server; }
/** * run */ public void run() { HttpServer server = null; try { server = HttpServer.create(new InetSocketAddress(16358),0); } catch (IOException e) { Basic.caught(e); } server.createContext("/start",new HttpHandler() { public void handle(HttpExchange httpExchange) throws IOException { URI uri = httpExchange.getRequestURI(); System.err.println("URI: " + uri); String command = uri.toString().substring(uri.toString().indexOf('?') + 1); System.err.println("Command: " + command); String response = "ok"; httpExchange.sendResponseHeaders(200,2); OutputStream outputStream = httpExchange.getResponseBody(); outputStream.write(response.getBytes()); outputStream.close(); } }); server.setExecutor(null); server.start(); }
public void run() { try { HttpServer server = HttpServer.create(new InetSocketAddress(port),0); server.createContext("/",new HttpHandler() { @Override public void handle(HttpExchange t) throws IOException { System.out.println(t.getRequestURI()); String name = LockServer.validateRequest(LockServer.this.gson,t); if (name == null) { return; } System.out.println("Lock name is: " + name); LockServer.this.handleLockServe(name,t); } }); server.start(); } catch (IOException ex) { ex.printstacktrace(); } }
public MockarangoServer(int port) throws IOException { server = HttpServer.create(new InetSocketAddress(port),0); server.createContext("/",new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { final String req = exchange.getRequestMethod() + " " + exchange.getRequestURI(); final arangoResponse response = responses.get(req); if (response != null) { exchange.sendResponseHeaders(response.status,response.body != null ? response.body.length() : 0); if (response.body != null) { final OutputStream out = exchange.getResponseBody(); out.write(response.body.getBytes()); out.close(); } } } }); server.setExecutor(null); }
@Before public void start() throws IOException { final String path = "/1234.xml"; // create the HttpServer InetSocketAddress address = new InetSocketAddress(serverAddress,0); httpServer = com.sun.net.httpserver.HttpServer.create(address,0); // create and register our handler HttpHandler handler = new ConfigurableHttpHandler(serverResponse); httpServer.createContext(path,handler); // start the server httpServer.start(); port = httpServer.getAddress().getPort(); LOG.debug("started http server {}:{} with handler {}",serverAddress,port,handler); httpAddress = String.format("http://%s:%d/1234.xml",port); LOG.debug("test url is: {}",httpAddress); }
private static HttpHandler createHttpExchange(String pathToServe) { return httpExchange -> { String requestUri = httpExchange.getRequestURI().toString(); String name = pathToServe + requestUri; name = name.replaceFirst("/+","/"); URL resource = HttpServerFromresourceInner.class.getResource(name); try (OutputStream os = httpExchange.getResponseBody()) { if (resource == null) { log.warn("Could not find " + requestUri); httpExchange.sendResponseHeaders(404,0); } else { byte[] bytes = Files.readAllBytes(Paths.get(resource.getFile())); httpExchange.sendResponseHeaders(200,bytes.length); os.write(bytes); } } }; }
private void startHTTPServer() throws IOException { Assert.assertNull(httpServer); InetSocketAddress address = new InetSocketAddress("127.0.0.1",8080); httpServer = HttpServer.create(address,100); httpServer.start(); httpServer.createContext("/",new HttpHandler() { @Override public void handle(HttpExchange t) throws IOException { String response = "<html><body><b>This is a unit test</b></body></html>"; t.sendResponseHeaders(200,response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); } }); }
@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() { @Override public void handle(HttpExchange exchange) { try { Thread.sleep(10000); } catch (InterruptedException ie) { //Ignore }}}); try { Message responseMsg = _consumerService2.operation("addGreeter").sendInOut("magesh"); } catch (Exception e) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); e.printstacktrace(new PrintStream(baos)); Assert.assertTrue(baos.toString().contains("SocketTimeoutException: Read timed out")); } httpServer.stop(0); }
@Test public void soapGatewayReferenceTimeout() throws Exception { Element input = SOAPUtil.parseAsDom("<test:sayHello xmlns:test=\"urn:switchyard-component-soap:test-ws:1.0\">" + " <arg0>Hello</arg0>" + "</test:sayHello>").getDocumentElement(); HttpServer httpServer = HttpServer.create(new InetSocketAddress(8090),new HttpHandler() { public void handle(HttpExchange exchange) { try { Thread.sleep(10000); } catch (InterruptedException ie) { //Ignore }}}); try { Message responseMsg = _consumerService3.operation("sayHello").sendInOut(input); } catch (Exception e) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); e.printstacktrace(new PrintStream(baos)); Assert.assertTrue(baos.toString().contains("SocketTimeoutException: Read timed out")); } httpServer.stop(0); }
public PiEzo() throws IOException { InetSocketAddress anyhost = new InetSocketAddress(2111); server = HttpServer.create(anyhost,0); HttpHandler userInterfaceHttpHander = new ClassPathResourceHttpHandler(); HttpHandler songsHttpHandler = new SongListHttpHander(); HttpHandler playSongHttpHandler = new PlaySongHttpHandler(); HttpHandler quitHttpHandler = new EndOfRunHttpHandler(server); HttpHandler rtttlHttpHandler = new RtttlHttpHandler(); server.createContext("/",userInterfaceHttpHander); server.createContext("/play/",playSongHttpHandler); server.createContext("/quit",quitHttpHandler); server.createContext("/rtttl",rtttlHttpHandler); server.createContext("/songs",songsHttpHandler); }
public static synchronized void startOrUpdate(InetSocketAddress addr,String filename,HttpHandler handler) throws IOException { if (addr == null) { throw new IllegalArgumentException("InetSocketAddress was null for HttpServer"); } if (filename == null) { throw new IllegalArgumentException("filename was null for HttpServer"); } boolean toStart = false; if (instance == null) { instance = new JwHttpServer(); JwHttpServer.addr = addr; server = HttpServer.create(addr,/*system default backlog for TCP connections*/ 0); // server.setExecutor(Executors.newCachedThreadPool()); toStart = true; } HttpContext context = server.createContext(filename,handler); context.getFilters().add(new ParameterFilter()); if (toStart) { server.start(); } }
private HttpServer startServer(final String... response) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(0),0); server.createContext("/").setHandler( new HttpHandler() { int responseIndex = 0; public void handle(HttpExchange exchange) throws IOException { byte[] responseBytes; if (responseIndex < response.length) { responseBytes = response[responseIndex].getBytes(UTF_8); responseIndex++; } else { responseBytes = new byte[0]; } exchange.sendResponseHeaders(200,responseBytes.length); OutputStream out = exchange.getResponseBody(); IOHelper.copyStream(new ByteArrayInputStream(responseBytes),out); exchange.close(); } }); server.start(); return server; }
private void createContextAndRegisterHandler() { httpServer.createContext("/",new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { System.out.println(exchange.getRequestMethod() + " " + exchange.getRequestURI()); switch (exchange.getRequestMethod()) { case HttpMethods.GET: handleGet(exchange); break; case HttpMethods.PUT: handlePut(exchange); break; case HttpMethods.DELETE: handleDelete(exchange); break; default: System.out.println("Don't kNow how to " + exchange.getRequestMethod()); throw new UnsupportedOperationException("Don't kNow how to " + exchange.getRequestMethod()); } } }); }
private HttpHandler createHandler(final int status,final TableSizeInfo tableSize,final int sleepTimeMs) { return new HttpHandler() { @Override public void handle(HttpExchange httpExchange) throws IOException { if (sleepTimeMs > 0) { try { Thread.sleep(sleepTimeMs); } catch (InterruptedException e) { LOGGER.info("Handler interrupted during sleep"); } } String json = new ObjectMapper().writeValueAsstring(tableSize); httpExchange.sendResponseHeaders(status,json.length()); OutputStream responseBody = httpExchange.getResponseBody(); responseBody.write(json.getBytes()); responseBody.close(); } }; }
private HttpHandler createHandler(final int status,final String msg,final int sleepTimeMs) { return new HttpHandler() { @Override public void handle(HttpExchange httpExchange) throws IOException { if (sleepTimeMs > 0) { try { Thread.sleep(sleepTimeMs); } catch (InterruptedException e) { LOGGER.info("Handler interrupted during sleep"); } } httpExchange.sendResponseHeaders(status,msg.length()); OutputStream responseBody = httpExchange.getResponseBody(); responseBody.write(msg.getBytes()); responseBody.close(); } }; }
public void start(HttpsServerProperties properties,SSLContext sslContext,HttpHandler handler) throws Exception { logger.info("start {}",properties); executor = new ThreadPoolExecutor(100,200,60,TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(10)); name = handler.getClass().getSimpleName(); executor.setRejectedExecutionHandler(this); InetSocketAddress socketAddress = new InetSocketAddress(properties.getPort()); httpsServer = HttpsServer.create(socketAddress,16); httpsServer.setHttpsConfigurator(HttpsConfiguratorFactory. createHttpsConfigurator(sslContext,properties.isClientAuth())); httpsServer.setExecutor(executor); httpsServer.createContext("/",handler); httpsServer.start(); logger.info("init {}",properties); }
public static void main(String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(8000),0); server.createContext("/simple",new HttpHandler() { @Override public void handle(HttpExchange t) throws IOException { try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException e) { // ignore } String response = "This is the response"; t.sendResponseHeaders(200,response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); } }); server.setExecutor(null); // creates a default executor server.start(); }
private static void startHTTPServer() throws IOException { httpServer = HttpServer.create( new InetSocketAddress( JobEntryHTTP_PDI208_Test.HTTP_HOST,JobEntryHTTP_PDI208_Test.HTTP_PORT ),10 ); httpServer.createContext( "/uploadFile",new HttpHandler() { @Override public void handle( HttpExchange httpExchange ) throws IOException { Headers h = httpExchange.getResponseHeaders(); h.add( "Content-Type","application/octet-stream" ); httpExchange.sendResponseHeaders( 200,0 ); InputStream is = httpExchange.getRequestBody(); OutputStream os = httpExchange.getResponseBody(); int inputChar = -1; while ( ( inputChar = is.read() ) >= 0 ) { os.write( inputChar ); } is.close(); os.flush(); os.close(); httpExchange.close(); } } ); httpServer.start(); }
private void createContext(HttpServer server,String path,HttpHandler handler,Authenticator auth) { final HttpContext context = server.createContext(path,handler); if( auth != null ) { context.setAuthenticator(auth); } context.getFilters().addAll(filters); }
private void registerRootbrowserView() { if (httpServer == null) return; try { httpServer.createContext("/",new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { String requestMethod = exchange.getRequestMethod(); Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type","text/html"); exchange.sendResponseHeaders(200,0); OutputStream responseBody = exchange.getResponseBody(); if (requestMethod.equalsIgnoreCase("GET")) { String path = exchange.getRequestURI().getPath(); StringWriter so = new StringWriter(); if (path.length() < 2) { // it is the root so.append("<html><head><title>Jason Mind Inspector -- Web View</title></head><body>"); so.append("<iframe width=\"20%\" height=\"100%\" align=left src=\"/agents\" border=5 frameborder=0 ></iframe>"); so.append("<iframe width=\"78%\" height=\"100%\" align=left src=\"/agent-mind/no_ag\" name=\"am\" border=5 frameborder=0></iframe>"); so.append("</body></html>"); } else if (path.indexOf("agent-mind") >= 0) { if (tryToIncludeMindInspectorForAg(path)) so.append("<Meta http-equiv=\"refresh\" content=0>"); else so.append("unkown agent!"); } responseBody.write(so.toString().getBytes()); } responseBody.close(); } }); } catch (Exception e) { e.printstacktrace(); } }
private void registeragentsbrowserView() { if (httpServer == null) return; try { httpServer.createContext("/agents",0); OutputStream responseBody = exchange.getResponseBody(); if (requestMethod.equalsIgnoreCase("GET")) { responseBody.write(("<html><head><title>Jason (list of agents)</title><Meta http-equiv=\"refresh\" content=\""+refreshInterval+"\" ></head><body>").getBytes()); responseBody.write(("<font size=\"+2\"><p>Agents</p></font>").getBytes()); for (String a: histories.keySet()) { responseBody.write( ("- <a href=\"/agent-mind/"+a+"/latest\" target=\"am\" style=\"font-family: arial; text-decoration: none\">"+a+"</a><br/>").getBytes()); } } responseBody.write("<hr/>by <a href=\"http://jason.sf.net\" target=\"_blank\">Jason</a>".getBytes()); responseBody.write("</body></html>".getBytes()); responseBody.close(); } }); } catch (Exception e) { e.printstacktrace(); } }
public static void main(String[] args) throws Exception { boolean error = true; // Start a dummy server to return 404 HttpServer server = HttpServer.create(new InetSocketAddress(0),0); HttpHandler handler = new HttpHandler() { public void handle(HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); while (is.read() != -1); t.sendResponseHeaders (404,-1); t.close(); } }; server.createContext("/",handler); server.start(); // Client request try { URL url = new URL("http://localhost:" + server.getAddress().getPort()); String name = args.length >= 2 ? args[1] : "foo.bar.Baz"; ClassLoader loader = new urlclassloader(new URL[] { url }); System.out.println(url); Class c = loader.loadClass(name); System.out.println("Loaded class \"" + c.getName() + "\"."); } catch (ClassNotFoundException ex) { System.out.println(ex); error = false; } finally { server.stop(0); } if (error) throw new RuntimeException("No ClassNotFoundException generated"); }
/** * Http Server */ static HttpServer startHttpServer() throws IOException { HttpServer httpServer = HttpServer.create(new InetSocketAddress(0),0); HttpHandler httpHandler = new SimpleHandler(); httpServer.createContext("/chunked/",httpHandler); httpServer.start(); return httpServer; }
public static void main(String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0),0); try { server.setExecutor(Executors.newFixedThreadPool(1)); server.createContext(someContext,new HttpHandler() { @Override public void handle(HttpExchange msg) { try { try { msg.sendResponseHeaders(noMsgCode,-1); } catch(IOException ioe) { ioe.printstacktrace(); } } finally { msg.close(); } } }); server.start(); System.out.println("Server started at port " + server.getAddress().getPort()); runRawSocketHttpClient("localhost",server.getAddress().getPort()); } finally { ((ExecutorService)server.getExecutor()).shutdown(); server.stop(0); } System.out.println("Server finished."); }
/** * Create and start the HTTP server. */ public DeafServer() throws IOException { InetSocketAddress addr = new InetSocketAddress(0); server = HttpServer.create(addr,0); HttpHandler handler = new DeafHandler(); server.createContext("/",handler); server.setExecutor(Executors.newCachedThreadPool()); server.start(); }
private HttpHandler getHttpHandler() { return new HttpHandler() { @Override public void handle(HttpExchange httpExchange) throws IOException { try { final Headers headers = httpExchange.getResponseHeaders(); final String requestMethod = httpExchange.getRequestMethod().toupperCase(); switch (requestMethod) { case METHOD_GET: final String responseBody = getUrlComponent(httpExchange.getRequestURI()); headers.set(HEADER_CONTENT_TYPE,String.format("%s; charset=%s",TYPE.getMimeType(httpExchange.getRequestURI().toString()),CHARSET)); final byte[] rawResponseBody = responseBody.getBytes(CHARSET); httpExchange.sendResponseHeaders(STATUS_OK,rawResponseBody.length); httpExchange.getResponseBody().write(rawResponseBody); break; case METHOD_OPTIONS: headers.set(HEADER_ALLOW,ALLOWED_METHODS); httpExchange.sendResponseHeaders(STATUS_OK,NO_RESPONSE_LENGTH); break; default: headers.set(HEADER_ALLOW,ALLOWED_METHODS); httpExchange.sendResponseHeaders(STATUS_METHOD_NOT_ALLOWED,NO_RESPONSE_LENGTH); break; } } finally { httpExchange.close(); } } }; }
public static void main(String[] args) throws Exception { boolean error = true; // Start a dummy server to return 404 HttpServer server = HttpServer.create(new InetSocketAddress(0),handler); server.start(); // Client request try { URL url = new URL("http://localhost:" + server.getAddress().getPort()); String name = args.length >= 2 ? args[1] : "foo.bar.Baz"; ClassLoader loader = new urlclassloader(new URL[] { url }); System.out.println(url); Class c = loader.loadClass(name); System.out.println("Loaded class \"" + c.getName() + "\"."); } catch (ClassNotFoundException ex) { System.out.println(ex); error = false; } finally { server.stop(0); } if (error) throw new RuntimeException("No ClassNotFoundException generated"); }
static void initServer() throws Exception { Logger logger = Logger.getLogger("com.sun.net.httpserver"); ConsoleHandler ch = new ConsoleHandler(); logger.setLevel(Level.SEVERE); ch.setLevel(Level.SEVERE); logger.addHandler(ch); String root = System.getProperty ("test.src")+ "/docs"; InetSocketAddress addr = new InetSocketAddress (0); s1 = HttpServer.create (addr,0); if (s1 instanceof HttpsServer) { throw new RuntimeException ("should not be httpsserver"); } s2 = HttpsServer.create (addr,0); HttpHandler h = new FileServerHandler(root); HttpContext c1 = s1.createContext("/files",h); HttpContext c2 = s2.createContext("/files",h); HttpContext c3 = s1.createContext("/echo",new EchoHandler()); redirectHandler = new RedirectHandler("/redirect"); redirectHandlerSecure = new RedirectHandler("/redirect"); HttpContext c4 = s1.createContext("/redirect",redirectHandler); HttpContext c41 = s2.createContext("/redirect",redirectHandlerSecure); HttpContext c5 = s2.createContext("/echo",new EchoHandler()); HttpContext c6 = s1.createContext("/keepalive",new KeepAliveHandler()); redirectErrorHandler = new RedirectErrorHandler("/redirecterror"); redirectErrorHandlerSecure = new RedirectErrorHandler("/redirecterror"); HttpContext c7 = s1.createContext("/redirecterror",redirectErrorHandler); HttpContext c71 = s2.createContext("/redirecterror",redirectErrorHandlerSecure); delayHandler = new DelayHandler(); HttpContext c8 = s1.createContext("/delay",delayHandler); HttpContext c81 = s2.createContext("/delay",delayHandler); executor = Executors.newCachedThreadPool(); s1.setExecutor(executor); s2.setExecutor(executor); ctx = new SimpleSSLContext().get(); sslparams = ctx.getSupportedSSLParameters(); s2.setHttpsConfigurator(new Configurator(ctx)); s1.start(); s2.start(); port = s1.getAddress().getPort(); System.out.println("HTTP server port = " + port); httpsport = s2.getAddress().getPort(); System.out.println("HTTPS server port = " + httpsport); httproot = "http://127.0.0.1:" + port + "/"; httpsroot = "https://127.0.0.1:" + httpsport + "/"; proxy = new ProxyServer(0,false); proxyPort = proxy.getPort(); System.out.println("Proxy port = " + proxyPort); }
static void initServer() throws Exception { InetSocketAddress addr = new InetSocketAddress (0); s1 = HttpServer.create (addr,0); HttpHandler h = new Handler(); HttpContext c1 = s1.createContext("/",h); executor = Executors.newCachedThreadPool(); s1.setExecutor(executor); s1.start(); port = s1.getAddress().getPort(); uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/foo"); System.out.println("HTTP server port = " + port); }
public static void initServer() throws IOException { Logger logger = Logger.getLogger("com.sun.net.httpserver"); ConsoleHandler ch = new ConsoleHandler(); logger.setLevel(Level.ALL); ch.setLevel(Level.ALL); logger.addHandler(ch); String root = System.getProperty("test.src") + "/docs"; InetSocketAddress addr = new InetSocketAddress(0); httpServer = HttpServer.create(addr,0); if (httpServer instanceof HttpsServer) { throw new RuntimeException("should not be httpsserver"); } httpsServer = HttpsServer.create(addr,0); HttpHandler h = new FileServerHandler(root); HttpContext c1 = httpServer.createContext("/files",h); HttpContext c2 = httpsServer.createContext("/files",h); HttpContext c3 = httpServer.createContext("/echo",new EchoHandler()); redirectHandler = new RedirectHandler("/redirect"); redirectHandlerSecure = new RedirectHandler("/redirect"); HttpContext c4 = httpServer.createContext("/redirect",redirectHandler); HttpContext c41 = httpsServer.createContext("/redirect",redirectHandlerSecure); HttpContext c5 = httpsServer.createContext("/echo",new EchoHandler()); HttpContext c6 = httpServer.createContext("/keepalive",new KeepAliveHandler()); redirectErrorHandler = new RedirectErrorHandler("/redirecterror"); redirectErrorHandlerSecure = new RedirectErrorHandler("/redirecterror"); HttpContext c7 = httpServer.createContext("/redirecterror",redirectErrorHandler); HttpContext c71 = httpsServer.createContext("/redirecterror",redirectErrorHandlerSecure); delayHandler = new DelayHandler(); HttpContext c8 = httpServer.createContext("/delay",delayHandler); HttpContext c81 = httpsServer.createContext("/delay",delayHandler); executor = Executors.newCachedThreadPool(); httpServer.setExecutor(executor); httpsServer.setExecutor(executor); ctx = new SimpleSSLContext().get(); httpsServer.setHttpsConfigurator(new HttpsConfigurator(ctx)); httpServer.start(); httpsServer.start(); port = httpServer.getAddress().getPort(); System.out.println("HTTP server port = " + port); httpsport = httpsServer.getAddress().getPort(); System.out.println("HTTPS server port = " + httpsport); httproot = "http://127.0.0.1:" + port + "/"; httpsroot = "https://127.0.0.1:" + httpsport + "/"; proxy = new ProxyServer(0,false); proxyPort = proxy.getPort(); System.out.println("Proxy port = " + proxyPort); }
public static HTTPTestServer create(HttpProtocolType protocol,HttpHandler delegate) throws IOException { Objects.requireNonNull(authType); Objects.requireNonNull(auth); switch(authType) { // A server that performs Server Digest authentication. case SERVER: return createServer(protocol,authType,delegate,"/"); // A server that pretends to be a Proxy and performs // Proxy Digest authentication. If protocol is HTTPS,// then this will create a HttpsProxyTunnel that will // handle the CONNECT request for tunneling. case PROXY: return createProxy(protocol,"/"); // A server that sends 307 redirect to a server that performs // Digest authentication. // Note: 301 doesn't work here because it transforms POST into GET. case SERVER307: return createServerAndRedirect(protocol,HttpAuthType.SERVER,307); // A server that sends 305 redirect to a proxy that performs // Digest authentication. case PROXY305: return createServerAndRedirect(protocol,HttpAuthType.PROXY,305); default: throw new InternalError("UnkNown server type: " + authType); } }
public static HTTPTestServer createServerAndRedirect( HttpProtocolType protocol,HttpAuthType targetAuthType,HttpHandler targetDelegate,int code300) throws IOException { Objects.requireNonNull(targetAuthType); Objects.requireNonNull(auth); // The connection between client and proxy can only // be a plain connection: SSL connection to proxy // is not supported by our client connection. HttpProtocolType targetProtocol = targetAuthType == HttpAuthType.PROXY ? HttpProtocolType.HTTP : protocol; HTTPTestServer redirectTarget = (targetAuthType == HttpAuthType.PROXY) ? createProxy(protocol,targetAuthType,targetDelegate,"/") : createServer(targetProtocol,"/"); HttpServer impl = createHttpServer(protocol); final HTTPTestServer redirectingServer = new HTTPTestServer(impl,redirectTarget,null); InetSocketAddress redirectAddr = redirectTarget.getAddress(); URL locationURL = url(targetProtocol,redirectAddr,"/"); final HttpHandler hh = redirectingServer.create300Handler(locationURL,code300); impl.createContext("/",hh); impl.start(); return redirectingServer; }
public HttpsProxyTunnel(HttpServer server,HTTPTestServer target,HttpHandler delegate) throws IOException { super(server,target,delegate); System.out.flush(); System.err.println("WARNING: HttpsProxyTunnel is an experimental test class"); ss = new ServerSocket(0,InetAddress.getByName("127.0.0.1")); start(); }
static HttpHandler createCapturingHandler(CompletableFuture<Headers> headers) { return new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { headers.complete(exchange.getRequestHeaders()); exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,-1); exchange.close(); } }; }
/** * Http Server */ static HttpServer startHttpServer() throws IOException { HttpServer httpServer = HttpServer.create(new InetSocketAddress(0),httpHandler); httpServer.start(); return httpServer; }
public static void main(String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0),server.getAddress().getPort()); } finally { ((ExecutorService)server.getExecutor()).shutdown(); server.stop(0); } System.out.println("Server finished."); }
com.sun.net.httpserver.HttpsExchange的实例源码
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
private URI getBaseUri(final HttpExchange exchange,final String decodedBasePath) { final String scheme = (exchange instanceof HttpsExchange) ? "https" : "http"; final URI baseUri; try { final List<String> hostHeader = exchange.getRequestHeaders().get("Host"); if (hostHeader != null) { baseUri = new URI(scheme + "://" + hostHeader.get(0) + decodedBasePath); } else { final InetSocketAddress addr = exchange.getLocalAddress(); baseUri = new URI(scheme,null,addr.getHostName(),addr.getPort(),decodedBasePath,null); } } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } return baseUri; }
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
@Override @NotNull public String getBaseAddress() { /* * Computes the Endpoint's address from the request. Use "Host" header * so that it has correct address(IP address or someother hostname) * through which the application reached the endpoint. * */ StringBuilder strBuf = new StringBuilder(); strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http"); strBuf.append("://"); String hostHeader = httpExchange.getRequestHeaders().getFirst("Host"); if (hostHeader != null) { strBuf.append(hostHeader); // Uses Host header } else { strBuf.append(httpExchange.getLocalAddress().getHostName()); strBuf.append(":"); strBuf.append(httpExchange.getLocalAddress().getPort()); } //Do not include URL pattern here //strBuf.append(httpExchange.getRequestURI().getPath()); return strBuf.toString(); }
@NotNull public static Headers withoutEntityHeaders(@NotNull final HttpExchange httpExchange,@NotNull final String cacheControlHeaderValue) { final Headers responseHeaders = httpExchange.getResponseHeaders(); responseHeaders.set(ServerHeaderName,ServerHeaderValue); responseHeaders.set(DateHeaderName,rfc2822DateForNow()); responseHeaders.set(ContentLanguageHeaderName,ContentLanguageHeaderValue); responseHeaders.set(ConnectionHeaderName,"close"); final boolean isHttps = httpExchange instanceof HttpsExchange; if (isHttps) { responseHeaders.set(StrictTransportSecurityHeaderName,StrictTransportSecurityHeaderValueMaximum); } responseHeaders.set(XFrameOptionsHeaderName,"DENY"); responseHeaders.set(XXssprotectionHeaderName,"1; mode=block"); responseHeaders.set(XRimAutoMatchHeaderName,"none"); responseHeaders.set(XRobotsTagHeaderName,"none"); responseHeaders.set(AccessControlAllowOriginHeaderName,"*"); responseHeaders.set(AccessControlAllowMethodsHeaderName,"POST,PUT,DELETE,GET,HEAD,OPTIONS"); responseHeaders.set(AccessControlAllowHeadersHeaderName,"Authorization,Content-Type"); responseHeaders.set(CacheControlHeaderName,cacheControlHeaderValue); responseHeaders.set(AcceptRangesHeaderName,"none"); return responseHeaders; }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
@Override public String getRequestScheme() { return (httpExchange instanceof HttpsExchange) ? "https" : "http"; }
public void handle(HttpExchange httpExchange) throws IOException { HttpsExchange exchange = (HttpsExchange) httpExchange; Boolean hasPassword = false; String myPassword = ""; String myHdrUser = ""; String myHdrMessage = ""; String[] uriQueryList = null; // Get the path and query string from the URI URI uriData = exchange.getRequestURI(); String uriPath = uriData.getPath(); String uriQuery = uriData.getQuery(); if (uriQuery != null) { uriQueryList = uriQuery.split("&"); } // Get the headers Headers headers = exchange.getRequestHeaders(); // Get the Request Method (GET/PUT) String requestMethod = exchange.getRequestMethod(); // Get any data from the body,although,we just discard it,this is required InputStream inputStream = exchange.getRequestBody(); while (inputStream.read() != -1) { inputStream.skip(0x10000); } inputStream.close(); if (headers.containsKey("password")) { myPassword = headers.getFirst("password"); if (myPassword.equals(serverPassword) || myPassword.equals("oauth:" + serverPassword)) { hasPassword = true; } } if (headers.containsKey("webauth")) { myPassword = headers.getFirst("webauth"); if (myPassword.equals(serverWebAuth)) { hasPassword = true; } } if (headers.containsKey("user")) { myHdrUser = headers.getFirst("user"); } if (headers.containsKey("message")) { myHdrMessage = headers.getFirst("message"); } if (requestMethod.equals("GET")) { if (uriPath.contains("..")) { sendHTMLError(403,"Invalid URL",exchange); } else if (uriPath.startsWith("/inistore")) { handleIniStore(uriPath,exchange,hasPassword); } else if (uriPath.startsWith("/dbquery")) { handleDBQuery(uriPath,uriQueryList,hasPassword); } else if (uriPath.startsWith("/addons") || uriPath.startsWith("/logs")) { handleFile(uriPath,hasPassword,true); } else if (uriPath.equals("/playlist")) { handleFile("/web/playlist/index.html",false); } else if (uriPath.equals("/")) { handleFile("/web/index.html",false); } else { handleFile("/web" + uriPath,false); } } if (requestMethod.equals("PUT")) { handlePutRequest(myHdrUser,myHdrMessage,hasPassword); } }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
@Override public String getRequestScheme() { return (httpExchange instanceof HttpsExchange) ? "https" : "http"; }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
@Override public String getRequestScheme() { return (httpExchange instanceof HttpsExchange) ? "https" : "http"; }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
@Override public String getRequestScheme() { return (httpExchange instanceof HttpsExchange) ? "https" : "http"; }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
@Override public String getRequestScheme() { return (httpExchange instanceof HttpsExchange) ? "https" : "http"; }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
@Override public String getRequestScheme() { return (httpExchange instanceof HttpsExchange) ? "https" : "http"; }
@Override public String getProtocol() { boolean isSecure = this.ex instanceof HttpsExchange; return ex.getProtocol().split("/")[0].toLowerCase() + (isSecure ? "s" : ""); }
@Override public boolean isSecure() { return (httpExchange instanceof HttpsExchange); }
public SSLSession getSSLSession() { return ((HttpsExchange) delegate).getSSLSession(); }
public X509Certificate getPeerCertficate() throws SSLPeerUnverifiedException { return ((HttpsExchange) delegate).getSSLSession().getPeerCertificateChain()[0]; }
com.sun.net.httpserver.spi.HttpServerProvider的实例源码
public void startServer() throws Exception { executeUpgrader(); Authenticator auth = new MyAuthenticator(config); server = HttpServerProvider.provider().createHttpServer( new InetSocketAddress(config.getManagerDetails().getManagerPort()),50); AjaxState ajaxState = new AjaxStateImpl(); createContext(server,"/",new WebrootHandler()); //$NON-NLS-1$ createContext(server,"/pages/",new PagesHandler(config),auth); //$NON-NLS-1$ createContext(server,"/server/",new ServerHandler(config),"/deploy/",new DeployHandler(config,ajaxState),"/ajax/",new AjaxProgressHandler(ajaxState)); //$NON-NLS-1$ createContext(server,"/upload/",new UploadHandler(config)); //$NON-NLS-1$ server.start(); }
@Override public Archive<?> createAuxiliaryArchive() { JavaArchive arquillianPactConsumer = null; arquillianPactConsumer = ShrinkWrap.create(JavaArchive.class,"arquillian-pact-consumer.jar") // Add Core classes required in container part .addClasses(AbstractConsumerPactTest.class,RemoteConsumerPactTest.class,PactConsumerConfiguration.class,MockProviderConfigCreator.class,PactConsumerConfigurator.class,PactConsumerRemoteExtension.class,PactFilesCommand.class,ConsumerProviderPair.class,PactMismatchesException.class,ConsumerPactRunnerKt.class,HttpHandler.class,HttpServer.class,HttpServerProvider.class,ResolveClassAnnotation.class,StubServer.class,StubServerEnricher.class,HttpsServer.class,HttpContext.class) .addPackages(true,Pact.class.getPackage()) .addAsServiceProvider(RemoteLoadableExtension.class,PactConsumerRemoteExtension.class); arquillianPactConsumer = addSunHttpServer(arquillianPactConsumer); final Properties properties = pactConsumerConfigurationInstance.get().asProperties(); String configuration = toString(properties); arquillianPactConsumer.add(new StringAsset(configuration),"/pact-consumer-configuration.properties"); final JavaArchive[] pactConsumerDeps = Maven.resolver() .resolve("au.com.dius:pact-jvm-consumer_2.11:" + getVersion()) .withtransitivity().as(JavaArchive.class); final JavaArchive merge = merge(arquillianPactConsumer,pactConsumerDeps); return merge; }
public static void httpserverService() throws IOException { HttpServerProvider provider = HttpServerProvider.provider(); HttpServer httpserver =provider.createHttpServer(new InetSocketAddress(6666),100);//�����˿�6666,��ͬʱ�� ��100������ httpserver.createContext("/yns3_hdfs",new MyHttpHandler()); httpserver.setExecutor(null); httpserver.start(); System.out.println("server started"); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,if <code>null</code> then bind() must be called * to set the address * @param backlog the socket backlog. If this value is less than or equal to zero,* then a system default value is used. * @throws BindException if the server cannot bind to the requested address,* or if the server is already bound. * @throws IOException */ public static HttpServer create ( InetSocketAddress addr,int backlog ) throws IOException { HttpServerProvider provider = HttpServerProvider.provider(); return provider.createHttpServer (addr,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
/** * Create a <code>HttpServer</code> instance which will bind to the * specified {@link java.net.InetSocketAddress} (IP address and port number) * * A maximum backlog can also be specified. This is the maximum number of * queued incoming connections to allow on the listening socket. * Queued TCP connections exceeding this limit may be rejected by the TCP implementation. * The HttpServer is acquired from the currently installed {@link HttpServerProvider} * * @param addr the address to listen on,backlog); }
dev_appserver.py 找不到 pkg_resources
我发现使用 pkg_resources
在本地运行时不需要 dev_appserver.py
。仅用于部署。
虽然我无法解决问题,但一个好的解决方法是将 appengine_config.py
更新为:
from google.appengine.ext import vendor
vendor.add('lib')
try:
import pkg_resources
pkg_resources.working_set.add_entry('lib')
except ImportError:
pass
通过此修改,它可以在本地和部署时工作。
,作为使用 GAE Python 2 从 ndb 迁移到 cloud-ndb 的一部分,您需要将以下内容添加到 appengine_config.py:
这是在某个地方的文档中吗?我很好奇是什么让你得出这个结论。
不久前,我在本地主机和远程服务器上遇到了 google-cloud-storage
一个奇怪的错误
DistributionNotFound: The 'google-cloud-storage' distribution was not found and is required by the application
似乎我在多个地方都有 pkg_resources
,我需要 pkg_resources
文件夹中的 lib
才能被加载。我认为 google-cloud-xxxxxxx 库需要 pkg_resources
与它们位于同一目录中才能使其工作。 (打印 pkg_resources.__file__
会显示您正在获取哪些 pkg_resources)。
对我来说,解决方法是在 import pkg_resources
之后执行 reload(pkg_resources)
& vendor.add('lib')
:
vendor.add('lib')
import pkg_resources
reload(pkg_resources)
我最近刚迁移到 google-cloud-ndb
并且不需要对 pkg_resources
进行任何进一步的更改,所以现在我认为 reload(pkg_resources)
可能使我免于您遇到的问题面对。
我们今天的关于GAE“没有属性“ HTTPSHandler”” dev_appserver.py和没有属性怎么办的分享就到这里,谢谢您的阅读,如果想了解更多关于com.sun.net.httpserver.HttpHandler的实例源码、com.sun.net.httpserver.HttpsExchange的实例源码、com.sun.net.httpserver.spi.HttpServerProvider的实例源码、dev_appserver.py 找不到 pkg_resources的相关信息,可以在本站进行搜索。
本文标签: