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


Java Response.setStatus方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:17,代码来源:RedirectFilter.java

示例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);
    }
}
 
开发者ID:mba811,项目名称:loli.io,代码行数:17,代码来源:RedirectFilter.java

示例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();
}
 
开发者ID:usrz,项目名称:java-libs-httpd,代码行数:22,代码来源:RedirectHandler.java

示例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();
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:25,代码来源:FeedbackHttpHandler.java

示例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();
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:25,代码来源:AbstractFoxHttpHandler.java

示例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());
}
 
开发者ID:wakingrufus,项目名称:elo-api,代码行数:10,代码来源:SessionResource.java

示例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);
}
 
开发者ID:wakingrufus,项目名称:elo-api,代码行数:11,代码来源:SessionResource.java

示例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;
}
 
开发者ID:wakingrufus,项目名称:elo-api,代码行数:11,代码来源:LeagueResource.java

示例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);
}
 
开发者ID:wakingrufus,项目名称:elo-api,代码行数:10,代码来源:UserResource.java

示例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();
    }
}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:39,代码来源:VanillaExtract.java

示例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());
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:16,代码来源:IPCamServer.java

示例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);

}
 
开发者ID:apache,项目名称:lens,代码行数:25,代码来源:SavedQueryResource.java

示例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);
}
 
开发者ID:apache,项目名称:lens,代码行数:24,代码来源:SavedQueryResource.java

示例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);
    }
}
 
开发者ID:jembi,项目名称:openhim-mediator-engine-java,代码行数:10,代码来源:MediatorRootActor.java

示例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();
}
 
开发者ID:sumeetchhetri,项目名称:gatf,代码行数:9,代码来源:GatfConfigToolMojo.java


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