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


Java Response.getStatusInfo方法代码示例

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


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

示例1: testLinksJson

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Test that the expected response is sent back.
 */
@Test
public void testLinksJson() throws Exception {
    final Response response = target().path("items")
            .queryParam("offset", 10)
            .queryParam("limit", 10)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(Response.class);

    final Response.StatusType statusInfo = response.getStatusInfo();
    assertEquals("Should have succeeded", 200, statusInfo.getStatusCode());

    final String content = response.readEntity(String.class);
    final List<Object> linkHeaders = response.getHeaders().get("Link");

    assertEquals("Should have two link headers", 2, linkHeaders.size());
    assertThat("Content should contain next link",
            content,
            containsString("http://localhost:" + getPort() + "/items?offset=20&limit=10"));
}
 
开发者ID:aruld,项目名称:dropwizard-pagination,代码行数:23,代码来源:LinkWebAppTest.java

示例2: testLinksXml

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Test that the expected response is sent back.
 */
@Test
public void testLinksXml() throws Exception {
    final Response response = target().path("items")
            .queryParam("offset", 10)
            .queryParam("limit", 10)
            .request(MediaType.APPLICATION_XML_TYPE)
            .get(Response.class);

    final Response.StatusType statusInfo = response.getStatusInfo();
    assertEquals("Should have succeeded", 200, statusInfo.getStatusCode());

    final String content = response.readEntity(String.class);
    final List<Object> linkHeaders = response.getHeaders().get("Link");

    assertEquals("Should have two link headers", 2, linkHeaders.size());
    assertThat("Content should contain next link",
            content,
            containsString("http://localhost:" + getPort() + "/items?offset=20&amp;limit=10"));
}
 
开发者ID:aruld,项目名称:dropwizard-pagination,代码行数:23,代码来源:LinkWebAppTest.java

示例3: toResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Response toResponse(@NonNull Exception exception) {
	ResponseBuilder builder;
	StatusType statusInfo;
	if (exception instanceof WebApplicationException) {
		Response response = ((WebApplicationException) exception).getResponse();
		builder = Response.fromResponse(response);
		statusInfo = response.getStatusInfo();
	} else {
		builder = Response.serverError();
		statusInfo = Status.INTERNAL_SERVER_ERROR;
	}

	SimpleExceptionJson simpleExceptionJson = new SimpleExceptionJson(statusInfo.getReasonPhrase(),
			statusInfo.getStatusCode(), exception.getMessage());
	builder.entity(simpleExceptionJson);
	builder.type("application/problem+json");

	if (statusInfo.getFamily() == Family.CLIENT_ERROR) {
		log.debug("Got client Exception", exception);
	} else {
		log.error("Sending error to client", exception);
	}

	return builder.build();
}
 
开发者ID:Mercateo,项目名称:rest-jersey-utils,代码行数:27,代码来源:RFCExceptionMapper.java

示例4: parseLastBuildJson

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
protected JsonNode parseLastBuildJson(String authHeader, String urlText) {
    Client client = WebClientHelpers.createClientWihtoutHostVerification();
    try {
        Response response = client.target(urlText).
                request().
                header("Authorization", authHeader).
                post(Entity.text(null), Response.class);

        int status = response.getStatus();
        String message = null;
        Response.StatusType statusInfo = response.getStatusInfo();
        if (statusInfo != null) {
            message = statusInfo.getReasonPhrase();
        }
        LOG.info("Got response code from Jenkins: " + status + " message: " + message + " from URL: " + urlText);
        if (status <= 200 || status >= 300) {
            LOG.error("Failed to trigger job " + urlText + ". Status: " + status + " message: " + message);
        } else {
            String json = response.readEntity(String.class);
            if (Strings.isNotBlank(json)) {
                ObjectMapper objectMapper = new ObjectMapper();
                try {
                    return objectMapper.reader().readTree(json);
                } catch (IOException e) {
                    LOG.warn("Failed to parse JSON: " + e, e);
                }
            }
        }
    } finally {
        closeQuietly(client);
    }
    return null;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:34,代码来源:CreateBuildConfigStep.java

示例5: setContent

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public void setContent(final IRI identifier, final InputStream stream,
        final Map<String, String> metadata) {
    requireNonNull(identifier, NON_NULL_IDENTIFIER);
    final Response res = httpClient.target(identifier.getIRIString()).request().put(entity(stream,
                ofNullable(metadata.get(CONTENT_TYPE)).map(MediaType::valueOf)
                    .orElse(APPLICATION_OCTET_STREAM_TYPE)));
    LOGGER.info("HTTP PUT request to {} returned {}", identifier, res.getStatusInfo());
    final Boolean ok = res.getStatusInfo().getFamily().equals(SUCCESSFUL);
    res.close();
    if (!ok) {
        throw new RuntimeTrellisException("HTTP PUT request to " + identifier + " failed with a " +
                res.getStatusInfo());
    }
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:16,代码来源:HttpBasedBinaryService.java

示例6: purgeContent

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public void purgeContent(final IRI identifier) {
    requireNonNull(identifier, NON_NULL_IDENTIFIER);
    final Response res = httpClient.target(identifier.getIRIString()).request().delete();
    LOGGER.info("HTTP DELETE request to {} returned {}", identifier, res.getStatusInfo());
    final Boolean ok = res.getStatusInfo().getFamily().equals(SUCCESSFUL);
    res.close();
    if (!ok) {
        throw new RuntimeTrellisException("HTTP DELETE request to " + identifier + " failed with a " +
                res.getStatusInfo());

    }
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:14,代码来源:HttpBasedBinaryService.java

示例7: getEntity

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private static <T> T getEntity(String url, String api, Class<T> entityClass) {
    Response response = null;
    try {
        Client client = ClientBuilder.newBuilder().build();
        response = client.target(url + API_ID_PRM + api).request().get();
        return response.readEntity(entityClass);
    } catch (Exception exp) {
        throw new RestClientException(ERROR_WHILE_GATHERING_INFORMATION + ", error: " +
                (response != null? response.getStatusInfo(): exp.getMessage()));
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
 
开发者ID:Vedenin,项目名称:RestAndSpringMVC-CodingChallenge,代码行数:16,代码来源:OpenExchangeRestClient.java

示例8: toResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Response toResponse(WebApplicationException exception) {

  LOGGER.error("WebApplicationException:", exception);
  LOGGER.debug("Constructing Error Response for: [{}]", exception.toString());
  ErrorResponse errorResponse = new ErrorResponse();

  Response exceptionResponse = exception.getResponse();
  Response.StatusType statusInfo = exceptionResponse.getStatusInfo();

  errorResponse.setCode(statusInfo.getStatusCode());
  errorResponse.setStatus(statusInfo.getReasonPhrase());
  errorResponse.setMessage(exception.getMessage());

  Response.ResponseBuilder responseBuilder = Response.status(statusInfo)
      .entity(errorResponse)
      .type(MediaType.APPLICATION_JSON);

  MultivaluedMap<String, Object> headers = exceptionResponse.getHeaders();
  if (headers.size() > 0) {
    LOGGER.debug("Adding headers:");
    for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
      String headerKey = entry.getKey();
      List<Object> headerValues = entry.getValue();
      LOGGER.debug("  {} -> {}", headerKey, headerValues);
      if (headerValues.size() == 1) {
        responseBuilder.header(headerKey, headerValues.get(0));
      } else {
        responseBuilder.header(headerKey, headerValues);
      }
    }
  }

  return responseBuilder.build();
}
 
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:36,代码来源:WebApplicationExceptionMapper.java

示例9: triggerJenkinsWebHook

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Triggers the given jenkins job via its URL.
 *
 * @param authHeader
 * @param jobUrl     the URL to the jenkins job
 * @param triggerUrl can be null or empty and the default triggerUrl will be used
 */
protected void triggerJenkinsWebHook(String token, String authHeader, String jobUrl, String triggerUrl, boolean post) {
    if (Strings.isNullOrBlank(triggerUrl)) {
        //triggerUrl = URLUtils.pathJoin(jobUrl, "/build?token=" + token);
        triggerUrl = URLUtils.pathJoin(jobUrl, "/build?delay=0");
    }
    // lets check if this build is already running in which case do nothing
    String lastBuild = URLUtils.pathJoin(jobUrl, "/lastBuild/api/json");
    JsonNode lastBuildJson = parseLastBuildJson(authHeader, lastBuild);
    JsonNode building = null;
    if (lastBuildJson != null && lastBuildJson.isObject()) {
        building = lastBuildJson.get("building");
        if (building != null && building.isBoolean()) {
            if (building.booleanValue()) {
                LOG.info("Build is already running so lets not trigger another one!");
                return;
            }
        }
    }
    LOG.info("Got last build JSON: " + lastBuildJson + " building: " + building);

    LOG.info("Triggering Jenkins build: " + triggerUrl);

    Client client = WebClientHelpers.createClientWihtoutHostVerification();
    try {
        Response response = client.target(triggerUrl).
                request().
                header("Authorization", authHeader).
                post(Entity.text(null), Response.class);

        int status = response.getStatus();
        String message = null;
        Response.StatusType statusInfo = response.getStatusInfo();
        if (statusInfo != null) {
            message = statusInfo.getReasonPhrase();
        }
        String extra = "";
        if (status == 302) {
            extra = " Location: " + response.getLocation();
        }
        LOG.info("Got response code from Jenkins: " + status + " message: " + message + " from URL: " + triggerUrl + extra);
        if (status <= 200 || status > 302) {
            LOG.error("Failed to trigger job " + triggerUrl + ". Status: " + status + " message: " + message);
        }
    } finally {
        closeQuietly(client);
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:55,代码来源:CreateBuildConfigStep.java


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