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


Java Response.StatusType方法代码示例

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


在下文中一共展示了Response.StatusType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: _getDescription

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private String _getDescription(String message) {
	Response.StatusType statusType = getStatusType();

	String statusCode = String.valueOf(statusType.getStatusCode());

	String defaultMessage = String.join(
		" ", "HTTP", statusCode, statusType.getReasonPhrase());

	if (defaultMessage.equals(message)) {
		return null;
	}

	return message;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:15,代码来源:WebApplicationExceptionConverter.java

示例4: shouldSuccessfullyExecuteGetRequest

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void shouldSuccessfullyExecuteGetRequest() {
    final RestClientMetadata metadataMock = mock(RestClientMetadata.class);
    final RestRequest restRequestMock = mock(RestRequest.class);
    final Client clientMock = mock(Client.class);
    final WebTarget webTargetMock = mock(WebTarget.class);
    final Invocation.Builder builderMock = mock(Invocation.Builder.class);
    final Response responseMock = mock(Response.class);
    final Response.StatusType statusTypeMock = mock(Response.StatusType.class);
    final String reasonPhrase = "reason";

    when(statusTypeMock.getReasonPhrase()).thenReturn(reasonPhrase);
    when(responseMock.getStatusInfo()).thenReturn(statusTypeMock);
    when(builderMock.get()).thenReturn(responseMock);
    when(webTargetMock.request(anyString())).thenReturn(builderMock);
    when(clientMock.target(anyString())).thenReturn(webTargetMock);
    when(restClientMock.getClient()).thenReturn(clientMock);
    when(restClientMock.getRestClientMetadata()).thenReturn(metadataMock);

    when(restRequestMock.getMethodType()).thenReturn(MethodType.GET);
    when(restRequestMock.getPath()).thenReturn("/test/{test}");
    when(restRequestMock.getPathParams()).thenReturn(ImmutableMap.builder()
            .put("test", "works")
            .build());
    when(restRequestMock.getQueryParams()).thenReturn(ImmutableMap.builder()
            .put("query", "test")
            .build());
    when(metadataMock.getUrl()).thenReturn("http://localhost:8080");

    final RestResponse response = restManager.executeRequest(restRequestMock);

    assertThat(response.getMessage()).isEqualTo(reasonPhrase);

    verify(responseMock).close();
    verify(clientMock).target(eq("http://localhost:8080/test/works?query=test"));
}
 
开发者ID:WojciechZankowski,项目名称:iextrading4j,代码行数:37,代码来源:RestManagerTest.java

示例5: 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

示例6: 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

示例7: getStatusInfo

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Response.StatusType getStatusInfo() {
  return rawResponse.getStatusInfo();
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:5,代码来源:BuiltGenericResponse.java

示例8: apply

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public ClientResponse apply(final ClientRequest clientRequest) throws ProcessingException {
    final HttpUriRequest request = this.toUriHttpRequest(clientRequest);
    final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(clientRequest.getHeaders(), request);

    try {
        final CloseableHttpResponse response;
        response = client.execute(new HttpHost(request.getURI().getHost(), request.getURI().getPort(), request.getURI().getScheme()), request, new BasicHttpContext(context));
        HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, clientRequest.getHeaders(), this.getClass().getName());

        final Response.StatusType status = response.getStatusLine().getReasonPhrase() == null
                ? Statuses.from(response.getStatusLine().getStatusCode())
                : Statuses.from(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());

        final ClientResponse responseContext = new ClientResponse(status, clientRequest);
        final List<URI> redirectLocations = context.getRedirectLocations();
        if(redirectLocations != null && !redirectLocations.isEmpty()) {
            responseContext.setResolvedRequestUri(redirectLocations.get(redirectLocations.size() - 1));
        }

        final Header[] respHeaders = response.getAllHeaders();
        final MultivaluedMap<String, String> headers = responseContext.getHeaders();
        for(final Header header : respHeaders) {
            final String headerName = header.getName();
            List<String> list = headers.get(headerName);
            if(list == null) {
                list = new ArrayList<>();
            }
            list.add(header.getValue());
            headers.put(headerName, list);
        }

        final HttpEntity entity = response.getEntity();

        if(entity != null) {
            if(headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
                headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
            }

            final Header contentEncoding = entity.getContentEncoding();
            if(headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) {
                headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue());
            }
        }
        responseContext.setEntityStream(this.toInputStream(response));
        return responseContext;
    }
    catch(final Exception e) {
        throw new ProcessingException(e);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:52,代码来源:HttpComponentsConnector.java

示例9: StatusExpectation

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
StatusExpectation(Response.StatusType status) {
  this.status = status;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:4,代码来源:StatusExpectation.java

示例10: getStatusType

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
protected Response.StatusType getStatusType() {
	return BAD_REQUEST;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:5,代码来源:BadRequestExceptionConverter.java

示例11: expectStatus

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
protected <T> T expectStatus(Response.StatusType status, Invocation i, Class<T> c) {
  return readEntity(expect(new StatusExpectation(status), i), new GenericType<T>(c));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:4,代码来源:BaseClientUtils.java

示例12: getStatusType

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
protected Response.StatusType getStatusType() {
	return NOT_FOUND;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:5,代码来源:NotFoundExceptionConverter.java

示例13: getStatusType

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
protected Response.StatusType getStatusType() {
	return METHOD_NOT_ALLOWED;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:5,代码来源:NotAllowedExceptionConverter.java

示例14: getStatusType

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
protected Response.StatusType getStatusType() {
	return UNSUPPORTED_MEDIA_TYPE;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:5,代码来源:NotSupportedExceptionConverter.java

示例15: getStatusType

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
protected Response.StatusType getStatusType() {
	return SERVICE_UNAVAILABLE;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:5,代码来源:ServiceUnavailableExceptionConverter.java


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