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


Java RequestInfo.getContent方法代碼示例

本文整理匯總了Java中com.nike.riposte.server.http.RequestInfo.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestInfo.getContent方法的具體用法?Java RequestInfo.getContent怎麽用?Java RequestInfo.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.nike.riposte.server.http.RequestInfo的用法示例。


在下文中一共展示了RequestInfo.getContent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Override
public CompletableFuture<ResponseInfo<String>> execute(RequestInfo<SerializableObject> request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx) {
    if (request.getContent() == null) {
        throw new IllegalStateException(
            "getContent() should return a non-null value for deserializable content. getRawContent(): " + request.getRawContent());
    }

    verifyIncomingPayloadByteHash(request, true);

    try {
        SerializableObject widget = request.getContent();
        String widgetAsString = objectMapper.writeValueAsString(widget);
        if (!widgetAsString.equals(request.getRawContent())) {
            throw new IllegalArgumentException("Expected serialized widget to match getRawContent(), but it didn't. serialized widget string: " +
                                               widgetAsString + ", getRawContent(): " + request.getRawContent());
        }
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }

    return CompletableFuture.completedFuture(ResponseInfo.newBuilder(responseMessage()).build());
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:23,代碼來源:VerifyPayloadHandlingComponentTest.java

示例2: getContent_returns_object_deserialized_from_raw_bytes_if_content_type_is_not_CharSequence_or_String

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void getContent_returns_object_deserialized_from_raw_bytes_if_content_type_is_not_CharSequence_or_String() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfoSpy = spy((RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests());
    ObjectMapper objectMapper = new ObjectMapper();
    TestContentObject expectedTco = new TestContentObject(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    byte[] rawBytes = objectMapper.writeValueAsString(expectedTco).getBytes(CharsetUtil.UTF_8);
    doReturn(rawBytes).when(requestInfoSpy).getRawContentBytes();
    ObjectMapper objectMapperSpy = spy(objectMapper);
    TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {};

    // when
    requestInfoSpy.setupContentDeserializer(objectMapperSpy, typeRef);
    TestContentObject result = requestInfoSpy.getContent();

    // then
    assertThat(result, notNullValue());
    assertThat(result.foo, is(expectedTco.foo));
    assertThat(result.bar, is(expectedTco.bar));
    verify(requestInfoSpy).getRawContentBytes();
    verify(requestInfoSpy, never()).getRawContent();
    verify(objectMapperSpy).readValue(rawBytes, typeRef);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:24,代碼來源:RequestInfoImplTest.java

示例3: authenticate

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
private ResponseInfo<IamRoleAuthResponse> authenticate(RequestInfo<IamRoleCredentials> request) {
    final IamRoleCredentials credentials = request.getContent();

    log.info("{}: {}, IAM Auth Event: the IAM principal {} with ip: {} is attempting to authenticate in region {}",
            HEADER_X_CERBERUS_CLIENT,
            getClientVersion(request),
            String.format(AwsIamRoleArnParser.AWS_IAM_ROLE_ARN_TEMPLATE,
                    credentials.getAccountId(),
                    credentials.getRoleName()),
            getXForwardedClientIp(request),
            credentials.getRegion());

    return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build();
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:15,代碼來源:AuthenticateIamRole.java

示例4: authenticate

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
private ResponseInfo<IamRoleAuthResponse> authenticate(RequestInfo<IamPrincipalCredentials> request) {
    final IamPrincipalCredentials credentials = request.getContent();

    log.info("{}: {}, IAM Auth Event: the IAM principal {} with ip: {} in attempting to authenticate in region {}",
            HEADER_X_CERBERUS_CLIENT,
            getClientVersion(request),
            credentials.getIamPrincipalArn(),
            getXForwardedClientIp(request),
            credentials.getRegion());

    return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build();
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:13,代碼來源:AuthenticateIamPrincipal.java

示例5: execute

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
 * Resource endpoint that gives an example of how to use the error handling system (hooked up to Backstopper via
 * {@link BackstopperRiposteConfigGuiceModule} Guice module) to handle all the errors in your application, both
 * for object validation via JSR 303 annotations and manually thrown errors.
 *
 * @param request
 *     The incoming request. {@link RequestInfo#getContent()} contains the request body with the arguments that
 *     the client can pass (some are required, others are not - see the JSR 303 validation annotations on the
 *     {@link ErrorHandlingEndpointArgs} class to see which are which).
 */
@Override
public CompletableFuture<ResponseInfo<ErrorHandlingEndpointArgs>> execute(
    RequestInfo<ErrorHandlingEndpointArgs> request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx
) {
    // If we reach here then the request content has already been run through the JSR 303 validator.
    ErrorHandlingEndpointArgs content = request.getContent();

    // We do need to check for null however.
    if (content == null)
        throw new ApiException(SampleCoreApiError.MISSING_EXPECTED_CONTENT);

    // Manually check the throwManualError query param (normally you'd do this with JSR 303 annotations on the
    //      object, but this shows how you can manually throw exceptions to be picked up by the error handling
    //      system).
    if (Boolean.TRUE.equals(content.throwManualError)) {
        throw ApiException.newBuilder()
                          .withExceptionMessage("Manual error throw was requested")
                          .withApiErrors(new ApiErrorWithMetadata(
                              ProjectApiError.EXAMPLE_ERROR_MANUALLY_THROWN,
                              MapBuilder.builder("dynamic_metadata", (Object)System.currentTimeMillis()).build()
                          ))
                          .build();
    }

    // Since we're not doing anything time consuming we don't need to execute anything on another thread and we
    //      can just return an already-completed CompletableFuture.
    return CompletableFuture.completedFuture(
        ResponseInfo.newBuilder(content).withHttpStatusCode(HttpResponseStatus.CREATED.code()).build()
    );
}
 
開發者ID:Nike-Inc,項目名稱:riposte-microservice-template,代碼行數:41,代碼來源:ExampleEndpoint.java


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