當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。