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


Java Response.setCode方法代码示例

本文整理汇总了Java中org.simpleframework.http.Response.setCode方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setCode方法的具体用法?Java Response.setCode怎么用?Java Response.setCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.simpleframework.http.Response的用法示例。


在下文中一共展示了Response.setCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
@Override
public void handle(Request request, Response response) {
    PrintStream body = null;
    try {
        body = response.getPrintStream();

        // Validate the request credentials
        Credentials credentials = Decoder.decode(request, this.requestConfiguration);
        validate(credentials);

        // And we're done
        response.setCode(ClientResponse.Status.OK.getStatusCode());

    } catch (Exception e) {
        e.printStackTrace();
        response.setCode(ClientResponse.Status.INTERNAL_SERVER_ERROR.getStatusCode());

    } finally {
        // The response body has to be explicitly closed in order for this method to return a response
        if (body != null) {
            body.close();
        }
    }
}
 
开发者ID:bazaarvoice,项目名称:jersey-hmac-auth,代码行数:25,代码来源:ValidatingHttpServer.java

示例2: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
/**
 * Handle the incoming request on the tracker service.
 *
 * <p>
 * This makes sure the request is made to the tracker's announce URL, and
 * delegates handling of the request to the <em>process()</em> method after
 * preparing the response object.
 * </p>
 *
 * @param request The incoming HTTP request.
 * @param response The response object.
 */
public void handle(Request request, Response response) {
	// Reject non-announce requests
	if (!Tracker.ANNOUNCE_URL.equals(request.getPath().toString())) {
		response.setCode(404);
		response.setText("Not Found");
		return;
	}

	OutputStream body = null;
	try {
		body = response.getOutputStream();
		this.process(request, response, body);
		body.flush();
	} catch (IOException ioe) {
		logger.warn("Error while writing response: {}!", ioe.getMessage());
	} finally {
		IOUtils.closeQuietly(body);
	}
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:32,代码来源:TrackerService.java

示例3: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
@Override
public void handle(Request req, Response response) {
    try {
        String msg = "unknown path";
        int code = 200;
        String path = req.getPath().getPath();
        if (path.equals(WatsAgentCommand.request.getPath())) {
            msg = "Requesting users ";
            StandaloneAgentRequest agentRequest = getRequest(req.getInputStream());
            if (agentRequest == null) {
                msg = "Invalid StandaloneAgentRequest.";
                code = 406;
            } else if (agentRequest.getJobId() != null && agentRequest.getUsers() > 0) {
                // launch the harness with the specified details.
                agentStarter.startTest(agentRequest);
            } else {
                msg = "invalid request.";
                code = 400;
            }
        }
        long time = System.currentTimeMillis();
        response.setCode(code);
        response.set("Content-Type", "text/plain");
        response.set("Server", "TAnk Agent/1.0");
        response.setDate("Date", time);
        response.setDate("Last-Modified", time);

        PrintStream body = response.getPrintStream();
        body.println(msg);
        body.close();
    } catch (Exception e) {
        LOG.error("error sending response");
        response.setCode(500);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:36,代码来源:CommandListener.java

示例4: 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.setCode(status.getCode());
	response.setText(status.getDescription());
	logger.warn("Could not process announce request ({}) !",
		error.getReason());

	WritableByteChannel channel = Channels.newChannel(body);
	channel.write(error.getData());
}
 
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:20,代码来源:TrackerService.java

示例5: setResponseFields

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void setResponseFields(Response resp, ResponseParams rp) {
    final long time = System.currentTimeMillis();
    String contentType = getContentType(rp.staticFile, rp.message);
    resp.setContentType(contentType);
    resp.setValue("Server", "Mock");
    resp.setDate("Date", time);
    resp.setDate("Last-Modified", time);
    resp.setCode(rp.responseCode);
    for (Map.Entry<String, String> header : rp.headers.entrySet()) {
        resp.setValue(header.getKey(), header.getValue());
    }
}
 
开发者ID:byoutline,项目名称:MockServer,代码行数:13,代码来源:ResponseHandler.java

示例6: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
@Override
public void handle(Request req, Response response) {
    try {
        String msg = "unknown path";
        String path = req.getPath().getPath();
        if (path.equals(WatsAgentCommand.start.getPath()) || path.equals(WatsAgentCommand.run.getPath())) {
            msg = "Starting Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            startTest();
        } else if (path.startsWith(WatsAgentCommand.stop.getPath())) {
            msg = "Stopping Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.stop);
        } else if (path.startsWith(WatsAgentCommand.kill.getPath())) {
            msg = "Killing Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            System.exit(0);
        } else if (path.startsWith(WatsAgentCommand.pause.getPath())) {
            msg = "Pausing Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.pause);
        } else if (path.startsWith(WatsAgentCommand.pause_ramp.getPath())) {
            msg = "Pausing Ramp for Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.pause_ramp);
        } else if (path.startsWith(WatsAgentCommand.resume_ramp.getPath())) {
            msg = "Pausing Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.resume_ramp);
        } else if (path.startsWith(WatsAgentCommand.status.getPath())) {
            msg = APITestHarness.getInstance().getStats().toString();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.resume_ramp);
        }
        LOG.info(msg);
        PrintStream body = response.getPrintStream();

        long time = System.currentTimeMillis();

        response.set("Content-Type", "text/plain");
        response.set("Server", "Intuit Tank Agent/1.0");
        response.setDate("Date", time);
        response.setDate("Last-Modified", time);

        body.println(msg);
        body.close();
    } catch (IOException e) {
        LOG.error("");
        response.setCode(500);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:45,代码来源:CommandListener.java


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