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


Java Status.OK属性代码示例

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


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

示例1: execute

public Response execute(Map<String,String> params) throws Exception {
    String on = params.get("on");
    String method = params.get("method");
    String args = params.get("args");

    String res = la.run(on, method, args);

    return new Response(Status.OK,"text/plain",res);
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:9,代码来源:Server.java

示例2: serveCameraImage

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,代码行数:18,代码来源:HTTPImageServer.java

示例3: render

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,代码行数:9,代码来源:GsonRenderer.java

示例4: getStatus

@Override
public IStatus getStatus() {
    return Status.OK;
}
 
开发者ID:macacajs,项目名称:UIAutomatorWD,代码行数:4,代码来源:RouterNanoHTTPD.java

示例5: serve

@Override
public Response serve(IHTTPSession session) {
    String msg = "<html><body><h1>Hello server</h1>\n";
    String msgUnauthorized = "<html><body><h1>Unauthorized</h1>\n";
    Method method = session.getMethod();
    String uri = session.getUri();

    /**
     * if request is submit a job: 1. submit job POST: /submitJob return:
     * {"status": "/status/01218499-a5fe-47cf-a0a8-8e9b106c5219",
     * "progress": 0}
     * 
     * 2. poll progress GET: /status/{JobID}
     * 
     * 
     */

    logger.info("GET REQ: Method " + method + "  URL: " + uri);

    if (method == Method.POST && uri.contains("submitJob")) {

        // careful authorization may change to lower case
        if ((session.getHeaders().containsKey("authorization") && session
                .getHeaders().get("authorization")
                .equalsIgnoreCase(AUTH_KEY))) {

            NanoJob job = addJob();

            msg = "{\"status\": \"/status/" + job.getJobId()
                    + "\", \"progress\": 0}";
            logger.info("SERVER_RESPONSE_200: " + msg);
            return new fi.iki.elonen.NanoHTTPD.Response(Status.OK,
                    "application/json", msg);
        } else {
            logger.info("SERVER_RESPONSE_401: " + msg);
            return new fi.iki.elonen.NanoHTTPD.Response(
                    Status.UNAUTHORIZED, "application/json",
                    msgUnauthorized);
        }

    } else if (method == Method.GET && uri.contains("/status/")) {

        // poll progress
        String jobId = uri.replace("/status/", "");
        NanoJob pollJob = jobMap.get(jobId);
        if (pollJob == null) {
            msg = "{\"status\": \"/status/" + jobId
                    + "\", \"errorMsg\": \"job not found\"}";
            logger.info("SERVER_RESPONSE_404: " + msg);
            return new fi.iki.elonen.NanoHTTPD.Response(Status.NOT_FOUND,
                    "application/json", msg);
        } else {
            pollJob.makeProgress();
            msg = "{\"status\": \"/status/" + jobId + "\", \"progress\": "
                    + pollJob.getProgress() + "}";
            logger.info("SERVER_RESPONSE_200: " + msg);
            return new fi.iki.elonen.NanoHTTPD.Response(Status.OK,
                    "application/json", msg);
        }

    } else if (method == Method.GET && uri.contains("/testHeaders")) {

        if (session.getHeaders().containsKey("sample")) {
            logger.info("Sample Header value {}: "
                    + session.getHeaders().get("sample"));

            msg = session.getHeaders().get("sample");
            logger.info("SERVER_RESPONSE_200: " + msg);
            return new fi.iki.elonen.NanoHTTPD.Response(Status.OK,
                    "application/json", msg);

        }

    }// end else
    msg = "{ \"errorMsg\": \"bad request. Accept 1. POST: /submitJob; 2. GET: /status/$JOB_ID \"}";
    return new fi.iki.elonen.NanoHTTPD.Response(Status.BAD_REQUEST,
            "application/json", msg);

}
 
开发者ID:eBay,项目名称:parallec,代码行数:79,代码来源:ServerWithPollableJobs.java

示例6: getStatus

@Override
public IStatus getStatus() {
	return Status.OK;
}
 
开发者ID:pankrator,项目名称:PISS,代码行数:4,代码来源:ReceiveNeighbours.java

示例7: HttpServer

/**
 * Creates a new HTTP server, parsing the subclass of this for methods annoted
 * using the {@link Service} annotation. To launch the server you must still call
 * {@link ::start()}.
 *
 * @param port  the port to open this server on
 */
protected HttpServer(int port) {
    this.port = port;
    this.server = new NanoHTTPD(port) {

        @Override
        public Response serve(IHTTPSession session) {
            final URI uri;
            final Map<String, String> params;
            final String service;

            try {
                uri     = new URI(session.getUri());
                params  = session.getParms();
                service = parseURIForService(uri);
            } catch (URISyntaxException | ServiceException ex) {
                return new Response(Status.BAD_REQUEST, "text/plain", ex.getMessage());
            }

            final ServiceHook<HttpServer> hook;
            try {
                hook = findCorrectHook(service);
            } catch (ServiceException ex) {
                return new Response(Status.NOT_FOUND, "text/plain", ex.getMessage());
            }

            final String result;
            
            try {
                result = hook.getCache().get(session.getQueryParameterString(), 
                    u -> hook.call(params)
                );
            } catch (HttpResponseException ex) {
                return ex.createResponse();
            } catch (ServiceException ex) {
                System.err.println(ex.getMessage());
                return new Response(
                    Status.INTERNAL_ERROR, "text/plain", ex.getMessage());
            }

            return new Response(Status.OK, hook.getEncoder().getMimeType(), result);
        }
    };
    
    hooks = createServiceHooks();
}
 
开发者ID:Pyknic,项目名称:ServiceKit,代码行数:52,代码来源:HttpServer.java

示例8: version

private Response version() {
    return new Response(Status.OK,"text/plain","1.0.1");
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:3,代码来源:Server.java

示例9: packages

public Response packages(Map<String, String> params) throws ParseException {
    la.setPackages(params.get("packages"));

    return new Response(Status.OK,"text/plain","Packages set!");
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:5,代码来源:Server.java

示例10: clean

public Response clean() {
    la.clear();
    return new Response(Status.OK,"text/plain","Cleaning successful!");
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:4,代码来源:Server.java

示例11: screenDump

public Response screenDump() {
    UIHelp.log("Creating dump of views");
    return new Response(Status.OK,"application/json", UIHelp.getScreenDump());
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:4,代码来源:Server.java

示例12: gc

public Response gc(Map<String,String> params) throws Exception {
    String on = params.get("on");
    String res = la.clear(on)? "sucess" : "no found!";
    return new Response(Status.OK,"text/plain",res);
}
 
开发者ID:lookout,项目名称:ImperiusGeorge,代码行数:5,代码来源:Server.java


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