本文整理汇总了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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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");
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}