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


Java HttpResponse.setStatusCode方法代码示例

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


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

示例1: handle

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
    RequestLine line = request.getRequestLine();
    Uri uri = Uri.parse(line.getUri());
    DatabaseDataEntity entity;
    if (uri != null) {
        String database = uri.getQueryParameter("database");
        String tableName = uri.getQueryParameter("table");
        entity = getDataResponse(database, tableName);
        if (entity != null) {
            response.setStatusCode(200);
            response.setEntity(new StringEntity(ParserJson.getSafeJsonStr(entity), "utf-8"));
            return;
        }
    }
    entity = new DatabaseDataEntity();
    entity.setDataList(new ArrayList<Map<String, String>>());
    entity.setCode(BaseEntity.FAILURE_CODE);
    response.setStatusCode(200);
    response.setEntity(new StringEntity(ParserJson.getSafeJsonStr(entity), "utf-8"));
}
 
开发者ID:facetome,项目名称:smart_plan,代码行数:22,代码来源:DatabaseDataRequestHandler.java

示例2: handle

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
    Log.d("plan", "DatabaseTableRequestHandler");
    DatabaseEntity entity;
    String uri = request.getRequestLine().getUri();
    String key =  Uri.parse(uri).getQueryParameter("database_name");
    if (!TextUtils.isEmpty(key)) {
        entity = getTableResponse(key.trim());
    }  else {
        entity = new DatabaseEntity();
        entity.setCode(BaseEntity.FAILURE_CODE);
        entity.setDataList(new ArrayList<SimpleNameEntity>());
    }
    String result = ParserJson.getSafeJsonStr(entity);
    response.setStatusCode(200);
    response.setEntity(new StringEntity(result, "utf-8"));
}
 
开发者ID:facetome,项目名称:smart_plan,代码行数:18,代码来源:DatabaseTableRequestHandler.java

示例3: handleException

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Handles the given exception and generates an HTTP response to be sent
 * back to the client to inform about the exceptional condition encountered
 * in the course of the request processing.
 *
 * @param ex the exception.
 * @param response the HTTP response.
 */
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    String message = ex.getMessage();
    if (message == null) {
        message = ex.toString();
    }
    byte[] msg = EncodingUtils.getAsciiBytes(message);
    ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:HttpService.java

示例4: handle

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
    //处于线程之中.
    Log.d("plan", "DatabaseQueryRequestHanlder");
    response.setEntity(new StringEntity(getDataResponse(), "utf-8"));
    response.setStatusCode(200);
}
 
开发者ID:facetome,项目名称:smart_plan,代码行数:8,代码来源:DatabaseQueryRequestHanlder.java

示例5: handle

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
    Log.d("plan", "DataAndTableRequestHandler");
    DataAndTableEntity entity = getDatabaseAndTable();
    if (entity == null) {
        entity = new DataAndTableEntity();
        entity.setCode(BaseEntity.FAILURE_CODE);
        entity.setDataList(new ArrayList<Map<String, List<SimpleNameEntity>>>());
    }
    response.setStatusCode(200);
    response.setEntity(new StringEntity(ParserJson.getSafeJsonStr(entity), "utf-8"));
}
 
开发者ID:facetome,项目名称:smart_plan,代码行数:13,代码来源:DataAndTableRequestHandler.java

示例6: handle

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public final void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
    if (!this.allowedVerbs.contains(request.getRequestLine().getMethod().toUpperCase())) {
        response.setStatusCode(http403.responseCode);
        response.setEntity(http403.entity);
    } else {
        Tuple<String, Map<String, String>> pathAndQueryTuple = PathHelper.splitPathAndQuery(request.getRequestLine().getUri().substring(this.prefix.length()));
        String path = pathAndQueryTuple.o1;

        Map<String, String> query = pathAndQueryTuple.o2;

        if (this.isAuthorized(path, query)) {
            try {
                Response res = getResponse(path, query);
                response.setStatusCode(res.responseCode);
                response.setHeaders(res.headers);
                response.setEntity(res.entity);
            } catch (Exception ex) {
                response.setStatusCode(http500.responseCode);
                response.setEntity(http500.entity);
                ex.printStackTrace();
            }
        } else {
            response.setStatusCode(http403.responseCode);
            response.setEntity(http403.entity);
        }
    }
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:29,代码来源:PhotatoHandler.java

示例7: getDefaultBotSession

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private DefaultBotSession getDefaultBotSession() throws IOException {
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(
            new ProtocolVersion("HTTP", 1, 1), 200, ""));
    response.setStatusCode(200);
    response.setEntity(new StringEntity("{}"));

    HttpClient mockHttpClient = Mockito.mock(HttpClient.class);
    Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
            .thenReturn(response);
    DefaultBotSession session = new DefaultBotSession();
    session.setCallback(new FakeLongPollingBot());
    session.setOptions(new DefaultBotOptions());
    return session;
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:15,代码来源:TestDefaultBotSession.java

示例8: handle

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {

    response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
    response.addHeader("Location", PropagationHandler.MAPPING);
}
 
开发者ID:opentracing-contrib,项目名称:java-apache-httpclient,代码行数:8,代码来源:TracingHttpClientBuilderTest.java

示例9: test

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Test
public void test() throws ExecutionException, InterruptedException {


    HttpHost target = new HttpHost("localhost");
    BasicConnPool connpool = new BasicConnPool();
    connpool.setMaxTotal(200);
    connpool.setDefaultMaxPerRoute(10);
    connpool.setMaxPerRoute(target, 20);
    Future<BasicPoolEntry> future = connpool.lease(target, null);
    BasicPoolEntry poolEntry = future.get();
    HttpClientConnection conn = poolEntry.getConnection();

    HttpProcessor httpproc = HttpProcessorBuilder.create()
            .add(new ResponseDate())
            .add(new ResponseServer("MyServer-HTTP/1.1"))
            .add(new ResponseContent())
            .add(new ResponseConnControl())
            .build();

    HttpRequestHandler myRequestHandler = new HttpRequestHandler() {

        public void handle(
                HttpRequest request,
                HttpResponse response,
                HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            response.setEntity(
                    new StringEntity("some important message",
                            ContentType.TEXT_PLAIN));
        }

    };

    UriHttpRequestHandlerMapper handlerMapper = new UriHttpRequestHandlerMapper();
    handlerMapper.register("/service/*", myRequestHandler);
    HttpService httpService = new HttpService(httpproc, handlerMapper);
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:39,代码来源:TestHttpCore.java

示例10: doService

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * The default implementation of this method attempts to resolve an
 * {@link HttpRequestHandler} for the request URI of the given request
 * and, if found, executes its
 * {@link HttpRequestHandler#handle(HttpRequest, HttpResponse, HttpContext)}
 * method.
 * <p>
 * Super-classes can override this method in order to provide a custom
 * implementation of the request processing logic.
 *
 * @param request the HTTP request.
 * @param response the HTTP response.
 * @param context the execution context.
 * @throws IOException in case of an I/O error.
 * @throws HttpException in case of HTTP protocol violation or a processing
 *   problem.
 */
protected void doService(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    HttpRequestHandler handler = null;
    if (this.handlerResolver != null) {
        String requestURI = request.getRequestLine().getUri();
        handler = this.handlerResolver.lookup(requestURI);
    }
    if (handler != null) {
        handler.handle(request, response, context);
    } else {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:HttpService.java


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