当前位置: 首页>>代码示例>>Java>>正文


Java HttpExchange.close方法代码示例

本文整理汇总了Java中com.sun.net.httpserver.HttpExchange.close方法的典型用法代码示例。如果您正苦于以下问题:Java HttpExchange.close方法的具体用法?Java HttpExchange.close怎么用?Java HttpExchange.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.net.httpserver.HttpExchange的用法示例。


在下文中一共展示了HttpExchange.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleExchange

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
private void handleExchange(HttpExchange msg) throws IOException {
    WSHTTPConnection con = new ServerConnectionImpl(adapter,msg);
    try {
        if (fineTraceEnabled) {
            LOGGER.log(Level.FINE, "Received HTTP request:{0}", msg.getRequestURI());
        }
        String method = msg.getRequestMethod();
        if(method.equals(GET_METHOD) || method.equals(POST_METHOD) || method.equals(HEAD_METHOD)
        || method.equals(PUT_METHOD) || method.equals(DELETE_METHOD)) {
            adapter.handle(con);
        } else {
            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.warning(HttpserverMessages.UNEXPECTED_HTTP_METHOD(method));
            }
        }
    } finally {
        msg.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:WSHttpHandler.java

示例2: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange t) throws IOException {
    InputStream is = t.getRequestBody();
    while (is.read() != -1);
    is.close();

    t.sendResponseHeaders (200, 0);
    OutputStream os = t.getResponseBody();
    DigestOutputStream dos = new DigestOutputStream(os, serverDigest);

    int offset = 0;
    for (int i=0; i<52; i++) {
        dos.write(baMessage, offset, CHUNK_SIZE);
        offset += CHUNK_SIZE;
    }
    serverMac = serverDigest.digest();
    os.close();
    t.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:ChunkedEncodingTest.java

示例3: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange t) throws IOException {
    InputStream is = t.getRequestBody();
    byte[] ba = new byte[BUFFER_SIZE];
    int read;
    long count = 0L;
    while((read = is.read(ba)) != -1) {
        count += read;
    }
    is.close();

    check(count == expected, "Expected: " + expected + ", received "
            + count);

    debug("Received " + count + " bytes");

    t.sendResponseHeaders(200, -1);
    t.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:FixedLengthInputStream.java

示例4: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle (HttpExchange t)
    throws IOException
{
    InputStream is = t.getRequestBody();
    Headers map = t.getRequestHeaders();
    Headers rmap = t.getResponseHeaders();
    while (is.read() != -1);
    is.close();
    t.sendResponseHeaders(200, -1);
    HttpPrincipal p = t.getPrincipal();
    if (!p.getUsername().equals("fred")) {
        error = true;
    }
    if (!p.getRealm().equals("[email protected]")) {
        error = true;
    }
    t.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:Deadlock.java

示例5: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange t) throws IOException {
    t.sendResponseHeaders(200, message.length());
    BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(t.getResponseBody(), "ISO8859-1"));
    writer.write(message, 0, message.length());
    writer.close();
    t.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:HttpsCreateSockTest.java

示例6: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public synchronized void handle(HttpExchange he) throws IOException {
    byte[] buf = Util.readAll(he.getRequestBody());
    try {
        bar1.await();
        bar2.await();
    } catch (Exception e) {}
    he.sendResponseHeaders(200, -1); // will probably fail
    he.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SmokeTest.java

示例7: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange t) throws IOException {
    try (InputStream is = t.getRequestBody()) {
        while (is.read() != -1);
    }
    t.sendResponseHeaders(respCode(), length());
    try (OutputStream os = t.getResponseBody()) {
        os.write(message());
    }
    t.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:HttpStreams.java

示例8: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public final void handle(HttpExchange exchange) throws IOException
{
	try
	{
		doHandle(exchange);
	}
	catch( Exception th )
	{
		HttpExchangeUtils.respondApplicationError(exchange, th);
	}
	finally
	{
		final Map<String, Pair<String, File>> streams = getMultipartStreams(exchange);
		if( streams != null )
		{
			for( Pair<String, File> file : streams.values() )
			{
				if( file.getSecond().exists() )
				{
					file.getSecond().delete();
				}
			}
		}
		exchange.close();
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:28,代码来源:AbstractDispatchHandler.java

示例9: errorReply

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
static void errorReply(HttpExchange exchange, String reply)
        throws IOException
{
    exchange.getResponseHeaders().add("Connection", "close");
    exchange.getResponseHeaders().add("WWW-Authenticate", reply);
    exchange.sendResponseHeaders(401, 0);
    exchange.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:B4769350.java

示例10: respondWithContent

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public static void respondWithContent(HttpExchange exchange, int code, String mimeType, String content)
	throws IOException
{
	setContentType(exchange, mimeType);

	byte[] bytes = content.getBytes();

	exchange.sendResponseHeaders(code, bytes.length);
	exchange.getResponseBody().write(bytes);
	exchange.close();
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:HttpExchangeUtils.java

示例11: main

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ClassLoad.java

示例12: sendOk

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public static void sendOk(HttpExchange event) throws IOException {
    try {
        event.sendResponseHeaders(200, 0);
    } finally {
        event.close();
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:8,代码来源:MockServer.java

示例13: okReply

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
static void okReply (HttpExchange exchange) throws IOException {
    exchange.getResponseHeaders().add("Connection", "close");
    String response = "Hello .";
    exchange.sendResponseHeaders(200, response.getBytes().length);
    OutputStream os = exchange.getResponseBody();
    os.write(response.getBytes());
    os.close();
    exchange.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:B4769350.java

示例14: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange exchange) throws IOException {
    exchange.getResponseHeaders().add("Location", "/redirect");
    exchange.sendResponseHeaders(302, -1);
    exchange.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:B6299712.java

示例15: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange t) throws IOException {
    t.sendResponseHeaders(200, 0);
    t.getResponseBody().write(CONTENT.getBytes());
    t.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:HttpNegotiateServer.java


注:本文中的com.sun.net.httpserver.HttpExchange.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。