本文整理了Java中org.simpleframework.http.Response.setCode
方法的一些代码示例,展示了Response.setCode
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.setCode
方法的具体详情如下:
包路径:org.simpleframework.http.Response
类名称:Response
方法名:setCode
暂无
代码示例来源:origin: mpetazzoni/ttorrent
@Override
public void serveResponse(int code, String description, ByteBuffer responseData) {
response.setCode(code);
response.setText(description);
try {
responseData.rewind();
final WritableByteChannel channel = Channels.newChannel(response.getOutputStream());
channel.write(responseData);
} catch (IOException e) {
e.printStackTrace();
}
}
};
代码示例来源:origin: jersey/jersey
@Override
public void failure(final Throwable error) {
try {
if (!response.isCommitted()) {
response.setCode(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
response.setDescription(error.getMessage());
}
} finally {
logger.debugLog("failure(...) called");
commit();
rethrow(error);
}
}
代码示例来源:origin: jersey/jersey
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
final ContainerResponse context) throws ContainerException {
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
final int code = statusInfo.getStatusCode();
final String reason = statusInfo.getReasonPhrase() == null
? Status.getDescription(code)
: statusInfo.getReasonPhrase();
response.setCode(code);
response.setDescription(reason);
if (contentLength != -1) {
response.setContentLength(contentLength);
}
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
for (final String value : e.getValue()) {
response.addValue(e.getKey(), value);
}
}
try {
return response.getOutputStream();
} catch (final IOException ioe) {
throw new ContainerException("Error during writing out the response headers.", ioe);
}
}
代码示例来源:origin: mpetazzoni/ttorrent
response.setCode(404);
response.setText("Not Found");
return;
代码示例来源:origin: SonarSource/sonarqube
public void handle(Request req, Response resp) {
try {
if (req.getPath().getPath().contains("/redirect/")) {
resp.setCode(303);
resp.add("Location", "/");
} else {
代码示例来源:origin: stackoverflow.com
response.setCode(400); // Bad request
response.setContent("time12 must be an integer between 1 and 12");
return;
response.setCode(400); // Bad request
response.setContent("pm must be one of " + AMPM.values());
return;
response.setCode(200);
switch( pm )
代码示例来源:origin: org.simpleframework/simple
/**
* This method allows the status for the response to be
* changed. This MUST be reflected the the response content
* given to the client. For a description of the codes see
* RFC 2616 section 10, Status Code Definitions.
*
* @param code the new status code for the HTTP response
*/
public void setCode(int code) {
response.setCode(code);
}
代码示例来源:origin: ngallagher/simpleframework
/**
* This method allows the status for the response to be
* changed. This MUST be reflected the the response content
* given to the client. For a description of the codes see
* RFC 2616 section 10, Status Code Definitions.
*
* @param code the new status code for the HTTP response
*/
public void setCode(int code) {
response.setCode(code);
}
代码示例来源:origin: miltonio/milton2
@Override
public void setStatus(Status status) {
this.status = status;
baseResponse.setCode(status.code);
}
代码示例来源:origin: org.simpleframework/simple-http
/**
* This method allows the status for the response to be
* changed. This MUST be reflected the the response content
* given to the client. For a description of the codes see
* RFC 2616 section 10, Status Code Definitions.
*
* @param code the new status code for the HTTP response
*/
public void setCode(int code) {
response.setCode(code);
}
代码示例来源:origin: restx/restx
@Override
protected void doSetStatus(HttpStatus httpStatus) {
response.setCode(httpStatus.getCode());
}
}
代码示例来源:origin: io.restx/restx-server-simple
@Override
protected void doSetStatus(HttpStatus httpStatus) {
response.setCode(httpStatus.getCode());
}
}
代码示例来源:origin: miltonio/milton2
private void respondError(Task t) {
try {
log.warn("setting error status becaue request could not be processed");
t.response.setCode(500);
// t.response.commit();
t.response.close();
} catch (Exception e) {
log.error("error setting last chance error status", e);
}
}
代码示例来源:origin: miltonio/milton2
private void respondFinalError(Task t) {
try {
log.warn("setting error status becaue request could not be processed");
t.response.setCode(500);
// t.response.commit();
t.response.close();
} catch (Exception e) {
log.error("error setting last chance error status", e);
}
}
代码示例来源:origin: miltonio/milton2
private void respondError( Task t ) {
try {
log.warn( "setting error status becaue request could not be processed" );
t.response.setCode( 500 );
// t.response.commit();
t.response.close();
} catch( Exception e ) {
log.error( "error setting last chance error status", e );
}
}
代码示例来源:origin: kristofa/mock-http-server
private void errorResponse(final Response response, final int httpCode, final String message) {
response.setCode(httpCode);
response.set(CONTENT_TYPE, "text/plain;charset=utf-8");
PrintStream body;
try {
body = response.getPrintStream();
body.print(message);
body.close();
} catch (final IOException e) {
throw new IllegalStateException("Exception when building response.", e);
}
}
代码示例来源:origin: org.glassfish.jersey.containers/jersey-container-simple-http
@Override
public void failure(final Throwable error) {
try {
if (!response.isCommitted()) {
response.setCode(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
response.setDescription(error.getMessage());
}
} finally {
logger.debugLog("failure(...) called");
commit();
rethrow(error);
}
}
代码示例来源:origin: opendedup/sdfs
void handlePut(Request req, Response rsp, String[] path) {
long fh = Long.parseLong(path[1]);
long start = Long.parseLong(path[2]);
int len = Integer.parseInt(path[3]);
try {
ByteBuffer buf = ByteBuffer.allocate(len);
req.getByteChannel().read(buf);
if (buf.position() != len) {
SDFSLogger.getLog().warn("length is " + len + " buffer size " + buf.position());
throw new FuseException().initErrno(Errno.EIO);
}
buf.position(0);
this.write(fh, buf, start);
rsp.setCode(200);
rsp.close();
} catch (FuseException e) {
SDFSLogger.getLog().error("error during write", e);
this.printError(req, rsp, e.getErrno(), e);
} catch (Exception e) {
SDFSLogger.getLog().error("error during write", e);
this.printError(req, rsp, -1, e);
}
}
代码示例来源:origin: com.sun.jersey.contribs/jersey-simple-server
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse cResponse) throws IOException {
int code = cResponse.getStatus();
String text = Status.getDescription(code);
String method = request.getMethod();
response.setCode(code);
response.setDescription(text);
if (!method.equalsIgnoreCase("HEAD") && contentLength != -1 && contentLength < Integer.MAX_VALUE) {
response.setContentLength((int) contentLength);
}
for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) {
for (Object value : e.getValue()) {
response.setValue(e.getKey(), ContainerResponse.getHeaderValue(value));
}
}
return response.getOutputStream();
}
代码示例来源:origin: org.restlet/org.restlet.ext.simple
@Override
public void writeResponseHead(org.restlet.data.Response restletResponse)
throws IOException {
// this.response.clear();
for (final Parameter header : getResponseHeaders()) {
this.response.add(header.getName(), header.getValue());
}
// Set the status
this.response.setCode(getStatusCode());
this.response.setText(getReasonPhrase());
// Is this really required
if (restletResponse.getEntity() == null) {
this.response.setContentLength(0);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!