本文整理汇总了Java中org.glassfish.grizzly.http.server.Response.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setStatus方法的具体用法?Java Response.setStatus怎么用?Java Response.setStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.http.server.Response
的用法示例。
在下文中一共展示了Response.setStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send404
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void send404(Response response) {
response.setStatus(HttpStatus.NOT_FOUND_404);
response.setContentType("image/png");
try (InputStream is = this.getClass().getResourceAsStream("/404.png");
OutputStream os = response.getOutputStream();) {
byte[] b = new byte[1024];
while (is.read(b) >= 0) {
os.write(b);
}
} catch (IOException e) {
logger.error(e);
}
}
示例2: send403
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void send403(Response response) {
response.setStatus(HttpStatus.FORBIDDEN_403);
response.setContentType("image/png");
try (InputStream is = this.getClass().getResourceAsStream("/403.png");
OutputStream os = response.getOutputStream();) {
byte[] b = new byte[1024];
while (is.read(b) >= 0) {
os.write(b);
}
} catch (IOException e) {
logger.error(e);
}
}
示例3: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response)
throws Exception {
final String query = request.getQueryString();
String path = request.getPathInfo();
if (path == null) path = "/";
log.info("Checking path \"%s\" against %d redirects", path, redirects.size());
for (Redirect redirect: redirects) {
final String location = redirect.apply(path, query);
if (location != null) {
response.setStatus(redirect.status);
response.setHeader(Header.Location, location);
response.finish();
return;
}
}
response.setStatus(NOT_FOUND_404);
response.finish();
}
示例4: setResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Writes data to response.
*
* @param response
* @param text
* @param status
* @param contentType
*/
protected void setResponse(final Response response, final String data, final int status,
final String contentType) {
response.setContentType(contentType);
response.setCharacterEncoding("utf-8");
response.setStatus(status);
final byte[] bytes = data.getBytes();
try {
response.setContentLength(bytes.length);
response.getWriter().write(data);
} catch (final IOException e) {
LOG.error("\n", e);
}
response.finish();
}
示例5: setResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Writes data to response.
*
* @param response
* @param text
* @param status
* @param contentType
*/
protected void setResponse(final Response response, final String data, final int status,
final String contentType) {
response.setContentType(contentType);
response.setCharacterEncoding("utf-8");
response.setStatus(status);
final byte[] bytes = data.getBytes();
try {
response.setContentLength(bytes.length);
response.getWriter().write(data);
} catch (final IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
response.finish();
}
示例6: login
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@POST
@Produces("application/json")
@ApiOperation(value = "login", produces = "application/json")
@PermitAll
public Session login(LoginRequest session, @Context final Response response) {
log.debug("logging in: " + session.getEmail());
response.setStatus(HttpStatus.CREATED_201);
return authorizationService.login(session.getEmail(), session.getPassword());
}
示例7: logout
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@DELETE
@Path("{token}")
@Produces("application/json")
@RolesAllowed("user")
@ApiOperation(value = "logout", produces = "application/json")
// @Context SecurityContext security
public void logout(@PathParam("token") String token, @Context final Response response) {
authorizationService.logout(token);
response.setStatus(HttpStatus.NO_CONTENT_204);
}
示例8: create
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@POST
@Produces("application/json")
@RolesAllowed("user")
@ApiOperation(value = "create", produces = "application/json")
public League create(League league, @Context final Response response) {
log.info("creating league: " + league.getName());
League createdLeague = leagueService.createLeague(league);
response.setStatus(HttpStatus.CREATED_201);
return createdLeague;
}
示例9: create
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@POST
@Produces("application/json")
@PermitAll
@ApiOperation(value = "create", produces = "application/json")
public User create(User user, @Context final Response response) {
log.info("creating user: " + user.getEmail() + " " + user.getName());
response.setStatus(HttpStatus.CREATED_201);
return createUserService.createUser(user);
}
示例10: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
response.setContentType("application/osm");
String uri = request.getDecodedRequestURI();
int suffixIndex = uri.lastIndexOf('.');
String fileType = uri.substring(suffixIndex);
OutputStream outStream = response.getOutputStream();
try {
String[] coords = uri.substring(1, suffixIndex).split("[,;]");
double minLat = Double.parseDouble(coords[0]);
double minLon = Double.parseDouble(coords[1]);
double maxLat = Double.parseDouble(coords[2]);
double maxLon = Double.parseDouble(coords[3]);
if (minLat >= maxLat || minLon >= maxLon || minLat < -90 || maxLat > 90 || minLon < -180 || maxLon > 180) {
throw new IllegalArgumentException();
}
/* Respond to head requests to let the client know the server is alive and the request is valid. */
if (request.getMethod() == Method.HEAD) {
response.setStatus(HttpStatus.OK_200);
return;
}
/* TODO filter out buildings on the server side. */
boolean buildings = coords.length > 4 && "buildings".equalsIgnoreCase(coords[4]);
OSMEntitySink sink = OSMEntitySink.forStream(uri, outStream);
TileOSMSource tileSource = new TileOSMSource(osm);
tileSource.setBoundingBox(minLat, minLon, maxLat, maxLon);
tileSource.copyTo(sink);
response.setStatus(HttpStatus.OK_200);
} catch (Exception ex) {
response.setStatus(HttpStatus.BAD_REQUEST_400);
outStream.write("URI format: /min_lat,min_lon,max_lat,max_lon[.pbf|.vex] (all coords in decimal degrees)\n".getBytes());
ex.printStackTrace();
} finally {
outStream.close();
}
}
示例11: serveSingleJpeg
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Serves the latest image (if any) once.
* @param request
* @param response
*/
private void serveSingleJpeg(Request request, Response response) throws IOException {
final eu.hgross.blaubot.blaubotcam.server.model.ImageMessage lastImageMessage = camDevice.getLastImageMessage();
response.setHeader("Server", HTTP_HEADER_SERVER_FIELD);
if (lastImageMessage == null) {
response.setStatus(HttpStatus.NO_CONTENT_204);
return;
}
response.setContentType(ContentType.newContentType("image/jpeg"));
response.getOutputStream().write(lastImageMessage.getJpegData());
}
示例12: create
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Creates a new saved query.
*
* @param sessionid The sessionid in which user is working
* @param savedQuery Saved query object
* @param response Injected response context object
* @return {@link org.apache.lens.api.query.save.ResourceModifiedResponse} ResourceModifiedResponse object
* @throws LensException
* @throws IOException
*/
@POST
@Path(("/savedqueries"))
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public ResourceModifiedResponse create(
@QueryParam("sessionid") LensSessionHandle sessionid,
SavedQuery savedQuery,
@Context final Response response)
throws LensException, IOException {
long id = savedQueryService.save(sessionid, savedQuery);
response.setStatus(HttpServletResponse.SC_CREATED);
response.flush();
return new ResourceModifiedResponse(id, "saved_query", CREATED);
}
示例13: update
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
/**
* Updates the saved query {id} with the new payload.
*
* @param sessionid The sessionid in which user is working
* @param savedQuery Saved query object
* @param response Injected response context object
* @return {@link org.apache.lens.api.query.save.ResourceModifiedResponse} ResourceModifiedResponse object
* @throws LensException
* @throws IOException
*/
@PUT
@Path("/savedqueries/{id}")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public ResourceModifiedResponse update(
@QueryParam("sessionid") LensSessionHandle sessionid,
@PathParam("id") long id,
SavedQuery savedQuery,
@Context final Response response) throws LensException, IOException {
savedQueryService.update(sessionid, id, savedQuery);
response.setStatus(HttpServletResponse.SC_CREATED);
response.flush();
return new ResourceModifiedResponse(id, "saved_query", UPDATED);
}
示例14: handleResponse
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
private void handleResponse(Response grizzlyResponseHandle, Integer status, String contentType, String body) throws IOException {
grizzlyResponseHandle.setStatus(status);
if (contentType!=null && body!=null) {
grizzlyResponseHandle.setContentType(contentType);
grizzlyResponseHandle.setContentLength(body.getBytes().length);
grizzlyResponseHandle.setCharacterEncoding("UTF-8");
grizzlyResponseHandle.getWriter().write(body);
}
}
示例15: handleError
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
protected static void handleError(Throwable e, Response response, HttpStatus status) throws IOException
{
String configJson = e.getMessage()==null?ExceptionUtils.getStackTrace(e):e.getMessage();
response.setContentLength(configJson.length());
response.getWriter().write(configJson);
response.setStatus(status==null?HttpStatus.INTERNAL_SERVER_ERROR_500:status);
if(status==null)e.printStackTrace();
}