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


Java RequestInfo.setupContentDeserializer方法代碼示例

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


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

示例1: doChannelRead

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof LastHttpContent) {
        HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
        Endpoint<?> endpoint = state.getEndpointForExecution();
        RequestInfo reqInfo = state.getRequestInfo();
        // Don't bother trying to deserialize until we have an endpoint and the request content has fully arrived
        if (endpoint != null && reqInfo.isCompleteRequestWithAllChunks()) {
            // Setup the content deserializer if desired
            TypeReference<?> contentTypeRef = endpoint.requestContentType();
            if (contentTypeRef != null) {
                // A non-null TypeReference is available, so deserialization is possible. Retrieve the appropriate
                //      deserializer and setup the RequestInfo so that it can lazily deserialize when requested.
                ObjectMapper deserializer = endpoint.customRequestContentDeserializer(reqInfo);
                if (deserializer == null)
                    deserializer = defaultRequestContentDeserializer;

                //noinspection unchecked
                reqInfo.setupContentDeserializer(deserializer, contentTypeRef);
            }
        }
    }

    return PipelineContinuationBehavior.CONTINUE;
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:26,代碼來源:RequestContentDeserializerHandler.java

示例2: setupContentDeserializer_and_getContent_handle_non_class_Type

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void setupContentDeserializer_and_getContent_handle_non_class_Type() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
    assertThat(requestInfo.getRawContentBytes(), nullValue());
    Type notAClassType = new Type() {
        @Override
        public String getTypeName() {
            return "FooType";
        }
    };
    TypeReference<TestContentObject> typeRefMock = mock(TypeReference.class);
    doReturn(notAClassType).when(typeRefMock).getType();

    // when
    requestInfo.setupContentDeserializer(new ObjectMapper(), typeRefMock);

    // then
    assertThat(requestInfo.getContent(), nullValue());
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:21,代碼來源:RequestInfoImplTest.java

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

示例4: setupContentDeserializer_and_getContent_sets_content_to_null_if_deserializer_is_null

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_deserializer_is_null() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();

    // when
    requestInfo.setupContentDeserializer(null, new TypeReference<TestContentObject>() {});

    // then
    assertThat(requestInfo.getContent(), nullValue());
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:12,代碼來源:RequestInfoImplTest.java

示例5: setupContentDeserializer_and_getContent_sets_content_to_null_if_type_ref_is_null

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_type_ref_is_null() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();

    // when
    requestInfo.setupContentDeserializer(new ObjectMapper(), null);

    // then
    assertThat(requestInfo.getContent(), nullValue());
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:12,代碼來源:RequestInfoImplTest.java

示例6: setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_is_null

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_is_null() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
    assertThat(requestInfo.getRawContent(), nullValue());

    // when
    requestInfo.setupContentDeserializer(new ObjectMapper(), new TypeReference<TestContentObject>() {});

    // then
    assertThat(requestInfo.getContent(), nullValue());
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:13,代碼來源:RequestInfoImplTest.java

示例7: setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
    assertThat(requestInfo.getRawContentBytes(), nullValue());

    // when
    requestInfo.setupContentDeserializer(new ObjectMapper(), new TypeReference<TestContentObject>() {});

    // then
    assertThat(requestInfo.getContent(), nullValue());
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:13,代碼來源:RequestInfoImplTest.java

示例8: getContent_returns_raw_string_if_content_type_is_CharSequence

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void getContent_returns_raw_string_if_content_type_is_CharSequence() throws IOException {
    // given
    RequestInfo<CharSequence> requestInfoSpy = spy((RequestInfo<CharSequence>) RequestInfoImpl.dummyInstanceForUnknownRequests());
    String rawContentString = UUID.randomUUID().toString();
    doReturn(rawContentString).when(requestInfoSpy).getRawContent();

    // when
    requestInfoSpy.setupContentDeserializer(new ObjectMapper(), new TypeReference<CharSequence>() {});

    // then
    assertThat(requestInfoSpy.getContent(), is(rawContentString));
    verify(requestInfoSpy).getRawContent();
    verify(requestInfoSpy, never()).getRawContentBytes();
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:16,代碼來源:RequestInfoImplTest.java

示例9: getContent_returns_raw_string_if_content_type_is_String

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void getContent_returns_raw_string_if_content_type_is_String() throws IOException {
    // given
    RequestInfo<String> requestInfoSpy = spy((RequestInfo<String>) RequestInfoImpl.dummyInstanceForUnknownRequests());
    String rawContentString = UUID.randomUUID().toString();
    doReturn(rawContentString).when(requestInfoSpy).getRawContent();

    // when
    requestInfoSpy.setupContentDeserializer(new ObjectMapper(), new TypeReference<String>() {});

    // then
    assertThat(requestInfoSpy.getContent(), is(rawContentString));
    verify(requestInfoSpy).getRawContent();
    verify(requestInfoSpy, never()).getRawContentBytes();
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:16,代碼來源:RequestInfoImplTest.java

示例10: getContent_throws_RequestContentDeserializationException_if_an_error_occurs_during_deserialization

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
@Test
public void getContent_throws_RequestContentDeserializationException_if_an_error_occurs_during_deserialization() throws IOException {
    // given
    RequestInfo<TestContentObject> requestInfoSpy = spy((RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests());
    ObjectMapper objectMapperSpy = spy(new ObjectMapper());
    byte[] rawBytes = new byte[]{};
    doReturn(rawBytes).when(requestInfoSpy).getRawContentBytes();
    RuntimeException expectedRootCause = new RuntimeException("splat");
    doThrow(expectedRootCause).when(objectMapperSpy).readValue(any(byte[].class), any(TypeReference.class));
    HttpMethod method = HttpMethod.CONNECT;
    String path = UUID.randomUUID().toString();
    TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {};
    doReturn(method).when(requestInfoSpy).getMethod();
    doReturn(path).when(requestInfoSpy).getPath();

    // when
    requestInfoSpy.setupContentDeserializer(objectMapperSpy, typeRef);
    Throwable actualEx = catchThrowable(() -> requestInfoSpy.getContent());

    // then
    assertThat(actualEx, notNullValue());
    assertThat(actualEx, instanceOf(RequestContentDeserializationException.class));
    RequestContentDeserializationException rcde = (RequestContentDeserializationException)actualEx;
    assertThat(rcde.desiredObjectType, sameInstance(typeRef));
    assertThat(rcde.httpMethod, is(String.valueOf(method)));
    assertThat(rcde.requestPath, is(path));
    assertThat(actualEx.getCause(), is(expectedRootCause));
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:29,代碼來源:RequestInfoImplTest.java


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