本文整理汇总了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);
}
示例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;
}
示例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());
}
示例4: getStatus
@Override
public IStatus getStatus() {
return Status.OK;
}
示例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);
}
示例6: getStatus
@Override
public IStatus getStatus() {
return Status.OK;
}
示例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();
}
示例8: version
private Response version() {
return new Response(Status.OK,"text/plain","1.0.1");
}
示例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!");
}
示例10: clean
public Response clean() {
la.clear();
return new Response(Status.OK,"text/plain","Cleaning successful!");
}
示例11: screenDump
public Response screenDump() {
UIHelp.log("Creating dump of views");
return new Response(Status.OK,"application/json", UIHelp.getScreenDump());
}
示例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);
}