本文整理汇总了Java中org.simpleframework.http.Response.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setStatus方法的具体用法?Java Response.setStatus怎么用?Java Response.setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.simpleframework.http.Response
的用法示例。
在下文中一共展示了Response.setStatus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.simpleframework.http.Response; //导入方法依赖的package包/类
@Override
public void handle(Request req, Response resp) {
final String requestUrl = req.getAddress().toString();
// Ignore favicon requests.
if ("/favicon.ico".equals(requestUrl)) {
resp.setStatus(Status.NOT_FOUND);
return;
}
LOG.info("Request: " + requestUrl);
Optional<String> returnValue = Optional.empty();
if (requestUrl.startsWith(IO_PREFIX)) {
returnValue = handleIoRequest(requestUrl.substring(IO_PREFIX.length()));
}
try {
resp.setStatus(returnValue.isPresent() ? Status.OK : Status.NOT_FOUND);
resp.getPrintStream().append(returnValue.isPresent() ? returnValue.get() : "");
resp.close();
} catch (final IOException e) {
LOG.warn("Could not deliver response");
}
LOG.debug("Request handled");
}
示例2: serveError
import org.simpleframework.http.Response; //导入方法依赖的package包/类
/**
* Write a {@link HTTPTrackerErrorMessage} to the response with the given
* HTTP status code.
*
* @param response The HTTP response object.
* @param body The response output stream to write to.
* @param status The HTTP status code to return.
* @param error The error reported by the tracker.
*/
private void serveError(Response response, OutputStream body,
Status status, HTTPTrackerErrorMessage error) throws IOException {
response.setStatus(status);
LOG.warn("Could not process announce request ({}) !",
error.getReason());
BytesBEncoder encoder = new BytesBEncoder();
encoder.bencode(error.toBEValue());
body.write(encoder.toByteArray()); // This is the raw network stream.
}
示例3: serveMotionJpegAsync
import org.simpleframework.http.Response; //导入方法依赖的package包/类
void serveMotionJpegAsync(final Response response) throws IOException {
LOG.info("Serving MJPEG...");
response.setContentType("multipart/x-mixed-replace;boundary=ipcamera");
response.setStatus(Status.OK);
OutputStream outputStream = response.getOutputStream();
Executor mMjpegExecutor = Executors.newSingleThreadExecutor();
mMjpegExecutor.execute(() -> {
byte[] jpegData = null;
try {
// Immediately serve most recent frame.
synchronized (mBytesLock) {
serveMotionJpegFrame(mCurrentImageBytes, outputStream);
}
// Skip the first frame, since it's old. Then continue to read updated frames.
mmJpegQueue.take();
while ((jpegData = mmJpegQueue.take()) != null) {
serveMotionJpegFrame(jpegData, outputStream);
}
} catch (IOException | InterruptedException e) {
LOG.warn("Interrupted while serving MJPEG data. Exiting MJPEG loop.");
try {
response.close();
} catch (IOException ignore) {
}
}
});
}
示例4: serveData
import org.simpleframework.http.Response; //导入方法依赖的package包/类
/** Serves the given data and content type to the given response. */
private void serveData(String contentType, byte[] data, Response response) throws IOException {
response.setStatus(Status.OK);
response.setContentType(contentType);
response.getOutputStream().write(data);
response.getOutputStream().close();
}
示例5: handleUnsupportedMethod
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleUnsupportedMethod(Request request, Response response) {
int index = this.requestIndex;
++this.requestIndex; // Increment before any possible exception.
response.setStatus(Status.METHOD_NOT_ALLOWED);
String responseBody = "UNSUPPORTED_METHOD " + index;
this.respond(response, responseBody);
}
示例6: handleGet
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleGet(Request request, Response response) {
int index = this.requestIndex;
++this.requestIndex; // Increment before any possible exception.
response.setStatus(Status.OK);
String responseBody = "TODO GET " + index;
this.respond(response, responseBody);
}
示例7: handleMethodNotAllowed
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleMethodNotAllowed(Response resp){
resp.setStatus(Status.METHOD_NOT_ALLOWED);
resp.setValue("Content-Type", "text/plain");
PrintStream body;
try {
body = resp.getPrintStream();
body.println("METHOD_NOT_ALLOWED");
body.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: handleInternalServerError
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleInternalServerError(Response resp){
resp.setStatus(Status.INTERNAL_SERVER_ERROR);
resp.setValue("Content-Type", "text/plain");
PrintStream body;
try {
body = resp.getPrintStream();
body.println("INTERNAL_SERVER_ERROR");
body.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: print
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void print(Status status, Response response, String str) throws Exception {
PrintStream body = response.getPrintStream();
response.setStatus(status);
response.setValue("Content-Type", "application/json");
if (str != null)
body.println(str);
body.close();
}
示例10: serveData
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void serveData(String contentType, byte[] data, Response response) throws IOException {
response.setStatus(Status.OK);
response.setContentType(contentType);
response.getOutputStream().write(data);
response.getOutputStream().close();
}