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


Java Status类代码示例

本文整理汇总了Java中fi.iki.elonen.NanoHTTPD.Response.Status的典型用法代码示例。如果您正苦于以下问题:Java Status类的具体用法?Java Status怎么用?Java Status使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
/**
 * Override this to customize the server.
 * <p/>
 * <p/>
 * (By default, this returns a 404 "Not Found" plain text error response.)
 *
 * @param session
 *            The HTTP session
 * @return HTTP response, see class Response for details
 */
public Response serve(IHTTPSession session) {
    Map<String, String> files = new HashMap<String, String>();
    Method method = session.getMethod();
    if (Method.PUT.equals(method) || Method.POST.equals(method)) {
        try {
            session.parseBody(files);
        } catch (IOException ioe) {
            return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
        } catch (ResponseException re) {
            return newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
        }
    }

    Map<String, String> parms = session.getParms();
    parms.put(NanoHTTPD.QUERY_STRING_PARAMETER, session.getQueryParameterString());
    return serve(session.getUri(), method, session.getHeaders(), parms, files);
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:28,代码来源:NanoHTTPD.java

示例2: serve_internal

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
public Response serve_internal(String uri, Method method, JSONObject jsonQuery) {
    try {
        Route route = findRoute(method, uri);
        if (route != null && route.getProc() != null) {
            return handleRoute(route, jsonQuery);
        }
        if (route == null) {
            return newFixedLengthResponse(Status.NOT_FOUND, MIME_PLAINTEXT, "Not Implemented: (route is null)");
        }
        if (route.getProc() == null) {
            return newFixedLengthResponse(Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Not Implemented: route = " + route);
        }
    } catch (Throwable e) {
        LOGGER.log(Level.WARNING, e.getMessage(), e);
        e.printStackTrace();
    }
    return newFixedLengthResponse(Status.BAD_REQUEST, MIME_HTML, "");
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JavaServer.java

示例3: get

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response get(UriResource uriResource, Map<String, String> urlParams, IHTTPSession session) {
    Method method = session.getMethod();
    String uri = session.getUri();
    //Log.d(TAG, "Method: " + method + ", Url: " + uri);

    try {
        EpubFetcher fetcher = uriResource.initParameter(EpubFetcher.class);

        int offset = uri.indexOf("/", 0);
        int startIndex = uri.indexOf("/", offset + 1);
        String filePath = uri.substring(startIndex + 1);
        Link link = fetcher.publication.getResourceMimeType(filePath);
        String mimeType = link.getTypeLink();

        InputStream inputStream = fetcher.getDataInputStream(filePath);
        response = serveResponse(session, inputStream, mimeType);
    } catch (EpubFetcherException e) {
        e.printStackTrace();
        return NanoHTTPD.newFixedLengthResponse(Status.INTERNAL_ERROR, getMimeType(), ResponseStatus.FAILURE_RESPONSE);
    }
    return response;
}
 
开发者ID:codetoart,项目名称:r2-streamer-java,代码行数:24,代码来源:ResourceHandler.java

示例4: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response serve(IHTTPSession session) {
    
    Method m = session.getMethod();
    switch(m)
    {
    
      case GET:
        return doGet(session);
      case POST:
        return doPost(session);
      default:
        return newFixedLengthResponse(Status.NOT_IMPLEMENTED, MimeTypeUtils.TEXT_PLAIN_VALUE,"HTTP "+m);
    
    }
}
 
开发者ID:javanotes,项目名称:reactive-data,代码行数:17,代码来源:SimpleHttpServerBean.java

示例5: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
/**
 * Override this to customize the server.
 * <p/>
 * <p/>
 * (By default, this returns a 404 "Not Found" plain text error response.)
 * 
 * @param session
 *            The HTTP session
 * @return HTTP response, see class Response for details
 */
public Response serve(IHTTPSession session) {
    Map<String, String> files = new HashMap<String, String>();
    Method method = session.getMethod();
    if (Method.PUT.equals(method) || Method.POST.equals(method)) {
        try {
            session.parseBody(files);
        } catch (IOException ioe) {
            return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
        } catch (ResponseException re) {
            return newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage());
        }
    }

    Map<String, String> parms = session.getParms();
    parms.put(NanoHTTPD.QUERY_STRING_PARAMETER, session.getQueryParameterString());
    return serve(session.getUri(), method, session.getHeaders(), parms, files);
}
 
开发者ID:panda73111,项目名称:FakeLocation,代码行数:28,代码来源:NanoHTTPD.java

示例6: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response serve(String uri, Method method, Map<String, String> header, Map<String, String> parms, Map<String, String> files) {
    StringBuilder sb = new StringBuilder(String.valueOf(method) + ':' + this.response);

    if (parms.size() > 1) {
        parms.remove("NanoHttpd.QUERY_STRING");
        sb.append("-params=").append(parms.size());
        List<String> p = new ArrayList<String>(parms.keySet());
        Collections.sort(p);
        for (String k : p) {
            sb.append(';').append(k).append('=').append(parms.get(k));
        }
    }
    if ("/encodingtest".equals(uri)) {
        return newFixedLengthResponse(Response.Status.OK, MIME_HTML, "<html><head><title>Testé ça</title></head><body>Testé ça</body></html>");
    } else if ("/chin".equals(uri)) {
        return newFixedLengthResponse(Status.OK, "application/octet-stream", sb.toString());
    } else {
        return newFixedLengthResponse(sb.toString());
    }
}
 
开发者ID:panda73111,项目名称:FakeLocation,代码行数:22,代码来源:GetAndPostIntegrationTest.java

示例7: testMessages

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Test
public void testMessages() {
	// These are values where the name of the enum does not match the status code description.
	// By default you should not need to add any new values to this map if you
	// make the name of the enum name match the status code description.
	Map<Status, String> overrideValues = new HashMap<Status, String>();
	overrideValues.put(Status.INTERNAL_ERROR, "500 Internal Server Error");
	overrideValues.put(Status.SWITCH_PROTOCOL, "101 Switching Protocols");
	overrideValues.put(Status.OK, "200 OK");
	overrideValues.put(Status.MULTI_STATUS, "207 Multi-Status");
	overrideValues.put(Status.REDIRECT, "301 Moved Permanently");
	overrideValues.put(Status.REDIRECT_SEE_OTHER, "303 See Other");
	overrideValues.put(Status.RANGE_NOT_SATISFIABLE, "416 Requested Range Not Satisfiable");
	overrideValues.put(Status.UNSUPPORTED_HTTP_VERSION, "505 HTTP Version Not Supported");

	for(Status status : Status.values()) {
		if (overrideValues.containsKey(status)) {
			Assert.assertEquals(overrideValues.get(status), status.getDescription());
		} else {
			Assert.assertEquals(getExpectedMessage(status), status.getDescription());
		}
	}
}
 
开发者ID:panda73111,项目名称:FakeLocation,代码行数:24,代码来源:StatusTest.java

示例8: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response serve(IHTTPSession session) {
	System.out.println(session.getUri());
	EndPoint endpoint = null;
	if (session.getMethod() == Method.GET) {
		endpoint = getEndpoints.get(session.getUri());			
	} else if (session.getMethod() == Method.POST) {
		endpoint = postEndpoints.get(session.getUri());
	}
	
	if (endpoint != null) {
		return newFixedLengthResponse(endpoint.getStatus(), endpoint.getMimeType(), gson.toJson(endpoint.call(session)));			
	} else {
		return newFixedLengthResponse(Status.NOT_FOUND, "text/plain", "Not Found");
	}
}
 
开发者ID:pankrator,项目名称:PISS,代码行数:17,代码来源:RestServer.java

示例9: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response serve(String uriString, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files) {
	URI uri = URI.create(uriString);
	String path = uri.getPath();
	if (path.length() < 2) {
		return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST, "text/html", uriString + " invalid");
	}
	int applicationNameEnd = path.indexOf('/', 1);
	if (applicationNameEnd < 0) {
		return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST, "text/html", uriString + " invalid");
	}

	String applicationName = path.substring(1, applicationNameEnd);
	application.setCurrentApplication(applicationName);
	
	String uriWithoutApplicationName = path.substring(applicationNameEnd);
	return super.serve(uriWithoutApplicationName, method, headers, parms, files);
}
 
开发者ID:BrunoEberhard,项目名称:minimal-j,代码行数:19,代码来源:DemoNanoWebServer.java

示例10: serveCameraImage

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
private Response serveCameraImage(IHTTPSession session) {
	Mat image = getImage();
	if (image.empty()) {
		image.create(new Size(640,  480), CvType.CV_8UC3);
		image.setTo(new Scalar(255, 0, 0));
	}
	
	MatOfInt  params = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, jpeg_quality);
	MatOfByte mat_of_buf = new MatOfByte();
	Imgcodecs.imencode(".jpg", image, mat_of_buf, params);
	byte[] byteArray = mat_of_buf.toArray();
	ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
	
	NanoHTTPD.Response res = new NanoHTTPD.Response(Status.OK, "image/jpeg", bis);
	res.addHeader("X-Content-Type-Options", "nosniff");
	res.addHeader("Access-Control-Allow-Origin", "*");
	return res;
}
 
开发者ID:yoggy,项目名称:HTTPCamera,代码行数:19,代码来源:HTTPImageServer.java

示例11: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> params, Map<String, String> files) {
    try {
        if (uri.equalsIgnoreCase("/execute")) { return execute(params); }
        else if(method == Method.GET && uri.equalsIgnoreCase("/clean")) { return clean(); }
        else if(method == Method.POST && uri.equalsIgnoreCase("/packages")) { return packages(params); }
        else if (method == Method.GET && uri.equalsIgnoreCase("/gc")) { return gc(params); }
        else if (method == Method.GET && uri.equalsIgnoreCase("/dump")) { return screenDump(); }
        else if (method == Method.GET && uri.equalsIgnoreCase("/terminate")) { return terminate(); }
        else if (method == Method.GET && uri.equalsIgnoreCase("/version")) { return version(); }
    } catch (Throwable e) {
        if (e.getCause() instanceof AssertionFailedError) { e = e.getCause(); }
        else if (e instanceof InvocationTargetException) { e = e.getCause(); }
        UIHelp.log("Reporting exception: " + UIHelp.exceptionToString(e));
        e.printStackTrace();
        return new Response(Status.NOT_ACCEPTABLE,"text/plain", UIHelp.exceptionToString(e));
    }
    return new Response("no dice grandma, params are:" + params);
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:20,代码来源:Server.java

示例12: lookup

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
public static Status lookup(int requestStatus) {
    for (Status status : Status.values()) {
        if (status.getRequestStatus() == requestStatus) {
            return status;
        }
    }
    return null;
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:9,代码来源:NanoHTTPD.java

示例13: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
@Override
public Response serve ( IHTTPSession sess ) {
    System.out.println("Serving " + sess.getUri());
    Response response = newFixedLengthResponse(Status.OK, "application/octet-stream", new ByteArrayInputStream(data), data.length);
    synchronized ( this.waitLock ) {
        this.waitLock.notify();
    }
    return response;
}
 
开发者ID:hucheat,项目名称:APacheSynapseSimplePOC,代码行数:10,代码来源:RemoteClassLoadingTest.java

示例14: render

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
public Response render(ModelAndView model) {
	IStatus status;
	if (model.getStatus() != null) {
		status = model.getStatus();
	} else {
		status = Status.OK;
	}
	return NanoHTTPD.newFixedLengthResponse(status, MimeType.JSON.getType(), model.getData());
}
 
开发者ID:dernasherbrezon,项目名称:r2cloud,代码行数:10,代码来源:GsonRenderer.java

示例15: serve

import fi.iki.elonen.NanoHTTPD.Response.Status; //导入依赖的package包/类
private Response serve(IHTTPSession session) {
    String path = session.getUri();
    Map<String, String> parameters = session.getParms();
    LOGGER.debug("Request received: {} {}", path, parameters);
    String resource = resources.getResource(path, parameters);
    if (resource == null) {
        resource = resources.getResource("404");
    }
    if (resource == null) {
        resource = "Not found.";
    }
    return NanoHTTPD.newFixedLengthResponse(Status.OK, NanoHTTPD.MIME_PLAINTEXT, resource);
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:14,代码来源:TestServer.java


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