當前位置: 首頁>>代碼示例>>Java>>正文


Java StatusType類代碼示例

本文整理匯總了Java中javax.ws.rs.core.Response.StatusType的典型用法代碼示例。如果您正苦於以下問題:Java StatusType類的具體用法?Java StatusType怎麽用?Java StatusType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StatusType類屬於javax.ws.rs.core.Response包,在下文中一共展示了StatusType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getStatusType

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
@Test
public void getStatusType() {
  new Expectations() {
    {
      clientResponse.statusCode();
      result = 123;
      clientResponse.statusMessage();
      result = "test";
    }
  };

  StatusType type = response.getStatusType();
  Assert.assertSame(type, response.getStatusType());
  Assert.assertEquals(123, type.getStatusCode());
  Assert.assertEquals("test", type.getReasonPhrase());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:TestVertxClientResponseToHttpServletResponse.java

示例2: toResponse

import javax.ws.rs.core.Response.StatusType; //導入依賴的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

示例3: davPropFind

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
protected javax.ws.rs.core.Response davPropFind(Long id, UriInfo uriInfo, String depth, Providers providers) throws AuthenticationException, AuthorisationException,
ServiceException {
	final Response folder = new Response(new HRef(uriInfo.getRequestUri()), null, null, null, new PropStat(new Prop(new DisplayName("My Collection"),
			new CreationDate(new Date()), new GetLastModified(new Date()), COLLECTION), new Status((StatusType) OK)));
	if (depth.equals(DEPTH_0) || id == null) {
		return javax.ws.rs.core.Response.status(MULTI_STATUS).entity(new MultiStatus(folder)).build();
	}
	final Collection<Response> responses = new LinkedList<Response>(singletonList(folder));
	Iterator<FileOutVO> it = WebUtil.getServiceLocator().getFileService().getFiles(getAuth(), getFileModule(), id, null, null, null).iterator();
	if (it != null) {
		while (it.hasNext()) {
			FileOutVO out = it.next();
			// responses.add(buildResponse(f, uriInfo.getAbsolutePathBuilder().path(format("%s", c.getMatchCode())).build(), providers));
			FilePathSplitter filePath = new FilePathSplitter(out.getFileName());
			String extension = filePath.getExtension();
			if (isTempFile(extension) || isEditableFile(extension)) {
				responses.add(buildResponse(out, uriInfo.getAbsolutePathBuilder().path(getDavFileName(out)).build(), providers));
			}
		}
	}
	return javax.ws.rs.core.Response.status(MULTI_STATUS).entity(new MultiStatus(responses.toArray(new Response[0]))).build();
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:23,代碼來源:FileDavResourceBase.java

示例4: httpErrorContent

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
/**
 * Creates an ErrorContent for a HTTP {@link ErrorSource#CLIENT_ERROR client}- or
 * {@link ErrorSource#SERVER_ERROR server} error.
 *
 * @param position the content position
 * @param response the HTTP response. This must either by a client-error response or a server-error response.
 * @param startedTs the timestamp when fetching the content has started.
 * @return ErrorContent
 * @throws IllegalArgumentException if the response is not a client- or server error response.
 */
public static ErrorContent httpErrorContent(final String source,
                                            final Position position,
                                            final Response response,
                                            final long startedTs) {
    final StatusType statusInfo = response.getStatusInfo();
    final Family family = statusInfo.getFamily();

    checkArgument(HTTP_ERRORS.contains(family),
            "Response is not a HTTP client or server error");

    final ErrorSource errorSource = family == CLIENT_ERROR
            ? ErrorSource.CLIENT_ERROR
            : ErrorSource.SERVER_ERROR;

    return new ErrorContent(source, position, statusInfo.getReasonPhrase(), errorSource, startedTs);
}
 
開發者ID:otto-de,項目名稱:rx-composer,代碼行數:27,代碼來源:ErrorContent.java

示例5: status

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
static void status(final StatusType statusInfo, final Family expectedFamily,
                   final Status... expectedStatuses) {
    requireNonNull(statusInfo, "null statusInfo");
    final Family actualFamily = statusInfo.getFamily();
    final int statusCode = statusInfo.getStatusCode();
    final String reasonPhrase = statusInfo.getReasonPhrase();
    logger.debug("-> response.status: {} {}", statusCode, reasonPhrase);
    if (expectedFamily != null) {
        assertEquals(actualFamily, expectedFamily);
    }
    if (expectedStatuses != null && expectedStatuses.length > 0) {
        assertTrue(
                Stream.of(expectedStatuses).map(Status::getStatusCode)
                .filter(v -> v == statusCode)
                .findAny()
                .isPresent()
        );
    }
}
 
開發者ID:jinahya,項目名稱:kt-ucloud-storage-client,代碼行數:20,代碼來源:StorageClientWsRsITs.java

示例6: createResponseWriter_writeResponse_Always_ShouldDelegateResponseToHandler

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void createResponseWriter_writeResponse_Always_ShouldDelegateResponseToHandler() throws IOException {
	SnsRecordAndLambdaContext reqAndContext = mock(SnsRecordAndLambdaContext.class);
	SNS sns = new SNS();
	sns.setTopicArn(":t");
	SNSRecord snsRecord = new SNSRecord();
	snsRecord.setSns(sns);
	when(reqAndContext.getSnsRecord()).thenReturn(snsRecord);

	StatusType statusType = mock(StatusType.class);
	Map<String, List<String>> headers = mock(Map.class);
	ByteArrayOutputStream entityOutputStream = mock(ByteArrayOutputStream.class);
	snsHandler.createResponseWriter(reqAndContext).writeResponse(statusType, headers, entityOutputStream);
	verify(snsHandler).handleReponse(reqAndContext, statusType, headers, entityOutputStream);
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:17,代碼來源:SnsRequestHandlerTest.java

示例7: createResponseWriter

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
@Override
public SimpleResponseWriter<SimpleContainerResponse> createResponseWriter(JRestlessContainerRequest containerRequest) {
	return new SimpleResponseWriter<SimpleContainerResponse>() {

		private SimpleContainerResponse response = onRequestFailure(null, null, null);

		@Override
		public OutputStream getEntityOutputStream() {
			return new ByteArrayOutputStream();
		}

		@Override
		public void writeResponse(StatusType statusType, Map<String, List<String>> headers,
				OutputStream entityOutputStream) throws IOException {
			response = new SimpleContainerResponse(statusType, entityOutputStream.toString(), headers);
		}

		@Override
		public SimpleContainerResponse getResponse() {
			return response;
		}
	};
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:24,代碼來源:SimpleRequestHandlerIntTest.java

示例8: makeErrorResponse

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
/**
 * Builds error response from exception.
 *
 * @param status  the response status
 * @param druidQuery  failed Druid Query if available or null
 * @param cause  exception
 * @param writer  The Writer to use for writing errors
 *
 * @return Response
 */
public static Response makeErrorResponse(
        StatusType status,
        DruidQuery<?> druidQuery,
        Throwable cause,
        ObjectWriter writer
) {
    String reason = null;
    String description = null;

    // do not return JAX-RS processing exception, only the cause
    if (cause instanceof ProcessingException && cause.getCause() != null) {
        cause = cause.getCause();
    }

    if (cause != null) {
        reason = cause.getClass().getName();
        description = String.valueOf(cause.getMessage());
    }

    return makeErrorResponse(status.getStatusCode(), reason, description, druidQuery, writer);
}
 
開發者ID:yahoo,項目名稱:fili,代碼行數:32,代碼來源:RequestHandlerUtils.java

示例9: insertAppointment

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
public URI insertAppointment(AppointmentType resource) {
    Response response = client.target(connection)
            .path("/rest/api/appointments")
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .post(xml(resource));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }

    return response.getLocation();
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:18,代碼來源:RESTfulClientLevel3Service.java

示例10: updateIssueWithoutCharset

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
public void updateIssueWithoutCharset(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(xml(resource));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例11: updateIssue

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
public void updateIssue(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
                    // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例12: updateIssueAsJson

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
public void updateIssueAsJson(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_JSON)));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例13: updateIssueIfLast

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
public boolean updateIssueIfLast(int issueId, ResourcesType resource, String md5) {
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.putSingle("If-Match", md5);

    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            .headers(headers)
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));

    response.close();

    if (response.getStatus() != HTTP_OK && response.getStatus() != HTTP_NOT_MODIFIED) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }

    return response.getStatus() == HTTP_OK;
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:23,代碼來源:RestClientService.java

示例14: toResponseBadApiCall

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
@Nonnull
private static Response toResponseBadApiCall(
        @Nonnull final Logger log,
        @Nonnull final StatusType status,
        @Nonnull final Throwable exception) {
    assert log != null;
    assert status != null;
    assert exception != null;

    final ExceptionDTO exceptionDTO = new ExceptionDTO(exception, UTCTime.now());
    log.info(createLogMessage("toResponseBadApiCall: Bad API call", exception, exceptionDTO, status));

    // Explicitly set media type, to overwrite media content type.
    return status(status).entity(exceptionDTO).
            type(MediaType.APPLICATION_JSON_TYPE).
            build();
}
 
開發者ID:tomtom-international,項目名稱:speedtools,代碼行數:18,代碼來源:GeneralExceptionMapper.java

示例15: createLogMessage

import javax.ws.rs.core.Response.StatusType; //導入依賴的package包/類
@Nonnull
private static String createLogMessage(
        @Nonnull final String prefix,
        @Nonnull final Throwable exception,
        @Nonnull final ExceptionDTO exceptionDTO,
        @Nonnull final StatusType status) {
    assert prefix != null;
    assert exception != null;
    assert exceptionDTO != null;
    assert status != null;
    if (verboseMode) {
        return String.format(LOG_MESSAGE_TEMPLATE_VERBOSE, prefix, exceptionDTO.getReference(), status,
                status.getStatusCode(), exception.getMessage(), exceptionDTO.getTime());
    } else {
        return String.format(LOG_MESSAGE_TEMPLATE_COMPACT, status, status.getStatusCode(), exception.getMessage());
    }
}
 
開發者ID:tomtom-international,項目名稱:speedtools,代碼行數:18,代碼來源:GeneralExceptionMapper.java


注:本文中的javax.ws.rs.core.Response.StatusType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。