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


Java HttpExchange.getRequestURI方法代码示例

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


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

示例1: parseGetParameters

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
private Map<String, List<String>> parseGetParameters(HttpExchange exchange)
{
	URI requestedUri = exchange.getRequestURI();
	String query = requestedUri.getRawQuery();
	return parseQuery(query, new HashMap<String, List<String>>());
}
 
开发者ID:equella,项目名称:Equella,代码行数:7,代码来源:SuperDuperFilter.java

示例2: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange t) throws IOException {
	URI uri = t.getRequestURI();
	String query = uri.getQuery();
	if ("kill".equals(query)) {
		// a kill request will stop the server
		System.exit(0);
	}
	else if (query==null || query.length()==0 || "test".equals(query)) {
		// an empty request or a test request will return an empty page;
		// this is used to check whether the server is running
		t.sendResponseHeaders(200, 0);
		OutputStream os = t.getResponseBody();
		os.write("Connected!".getBytes(Charset.forName("UTF-8")));
		os.close();
	}
}
 
开发者ID:SimplifiedLogic,项目名称:creoson,代码行数:18,代码来源:StatusHttpHandler.java

示例3: getResponseType

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
private int getResponseType(HttpExchange exchange) {
  URI uri = exchange.getRequestURI();
  String rawQuery = uri.getRawQuery();
  if (rawQuery == null) {
    return HttpURLConnection.HTTP_OK;
  }
  if ("status=400".equals(rawQuery)) {
    return HttpURLConnection.HTTP_BAD_REQUEST;
  }
  return HttpURLConnection.HTTP_OK;
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:12,代码来源:ApptuitPutClientTest.java

示例4: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange t) throws IOException {
    InputStream is = t.getRequestBody();
    Headers map = t.getRequestHeaders();
    Headers rmap = t.getResponseHeaders();
    URI uri = t.getRequestURI();

    debug("Server: received request for " + uri);
    String path = uri.getPath();
    if (path.endsWith("a.jar"))
        aDotJar++;
    else if (path.endsWith("b.jar"))
        bDotJar++;
    else if (path.endsWith("c.jar"))
        cDotJar++;
    else
        System.out.println("Unexpected resource request" + path);

    while (is.read() != -1);
    is.close();

    File file = new File(docsDir, path);
    if (!file.exists())
        throw new RuntimeException("Error: request for " + file);
    long clen = file.length();
    t.sendResponseHeaders (200, clen);
    OutputStream os = t.getResponseBody();
    FileInputStream fis = new FileInputStream(file);
    try {
        byte[] buf = new byte [16 * 1024];
        int len;
        while ((len=fis.read(buf)) != -1) {
            os.write (buf, 0, len);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    fis.close();
    os.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:Basic.java

示例5: moved

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
void moved(HttpExchange t) throws IOException {
    Headers req = t.getRequestHeaders();
    Headers map = t.getResponseHeaders();
    URI uri = t.getRequestURI();
    String host = req.getFirst("Host");
    String location = "http://" + host + uri.getPath() + "/";
    map.set("Content-Type", "text/html");
    map.set("Location", location);
    t.sendResponseHeaders(301, -1);
    t.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SimpleHttpServer.java

示例6: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange event) throws IOException {
    URI uri = event.getRequestURI();

    // favicon.ico, OPTION は 無視する
    if (uri.getPath().endsWith("favicon.ico")
            || event.getRequestMethod().equalsIgnoreCase("OPTION")) {
        sendOk(event);
        return;
    }

    System.out.println(generateCurl(event));
    sendOk(event);
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:14,代码来源:MockServer.java

示例7: handle

import com.sun.net.httpserver.HttpExchange; //导入方法依赖的package包/类
public void handle(HttpExchange t)
        throws IOException {
    InputStream is = t.getRequestBody();
    Headers map = t.getRequestHeaders();
    Headers rmap = t.getResponseHeaders();
    OutputStream os = t.getResponseBody();
    URI uri = t.getRequestURI();
    String path = uri.getPath();


    while (is.read() != -1) ;
    is.close();

    File f = new File(_docroot, path);
    if (!f.exists()) {
        notfound(t, path);
        return;
    }

    String method = t.getRequestMethod();
    if (method.equals("HEAD")) {
        rmap.set("Content-Length", Long.toString(f.length()));
        t.sendResponseHeaders(200, -1);
        t.close();
    } else if (!method.equals("GET")) {
        t.sendResponseHeaders(405, -1);
        t.close();
        return;
    }

    if (path.endsWith(".html") || path.endsWith(".htm")) {
        rmap.set("Content-Type", "text/html");
    } else {
        rmap.set("Content-Type", "text/plain");
    }

    t.sendResponseHeaders (200, f.length());

    FileInputStream fis = new FileInputStream(f);
    int count = 0;
    try {
        byte[] buf = new byte[16 * 1024];
        int len;
        while ((len = fis.read(buf)) != -1) {
            os.write(buf, 0, len);
            count += len;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    fis.close();
    os.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:54,代码来源:SimpleHttpServer.java


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