Codota Logo
RequestContentValidationHandler
Code IndexAdd Codota to your IDE (free)

How to use
RequestContentValidationHandler
in
com.nike.riposte.server.handler

Best Java code snippets using com.nike.riposte.server.handler.RequestContentValidationHandler (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: Nike-Inc/riposte

@Test(expected = IllegalArgumentException.class)
public void constructor_throws_IllegalArgumentException_if_passed_null() {
  // expect
  new RequestContentValidationHandler(null);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_nothing_if_msg_is_not_LastHttpContent() throws Exception {
  // given
  HttpContent notLastContentMsg = mock(HttpContent.class);
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, notLastContentMsg);
  // then
  verifyZeroInteractions(requestInfoMock);
  verifyZeroInteractions(endpointMock);
  verifyZeroInteractions(stateMock);
  verifyZeroInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: com.nike.riposte/riposte-core

    () -> executeValidation(requestInfo, endpoint, ctx),
    ASYNC_VALIDATION_EXECUTOR)
);
executeValidation(requestInfo, endpoint, ctx);
origin: Nike-Inc/riposte

    () -> executeValidation(requestInfo, endpoint, ctx),
    ASYNC_VALIDATION_EXECUTOR)
);
executeValidation(requestInfo, endpoint, ctx);
origin: Nike-Inc/riposte

@Test
public void constructor_uses_passed_in_arg() {
  // given
  RequestContentValidationHandler theHandler = new RequestContentValidationHandler(requestValidatorMock);
  // when
  RequestValidator validatorUsed = (RequestValidator) Whitebox.getInternalState(theHandler, "validationService");
  // expect
  assertThat(validatorUsed).isEqualTo(requestValidatorMock);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_nothing_if_endpoint_is_null() throws Exception {
  // given
  doReturn(null).when(stateMock).getEndpointForExecution();
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verifyNoMoreInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Before
public void beforeMethod() {
  requestValidatorMock = mock(RequestValidator.class);
  stateMock = mock(HttpProcessingState.class);
  ctxMock = mock(ChannelHandlerContext.class);
  channelMock = mock(Channel.class);
  stateAttrMock = mock(Attribute.class);
  endpointMock = mock(Endpoint.class);
  requestInfoMock = mock(RequestInfo.class);
  doReturn(channelMock).when(ctxMock).channel();
  doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
  doReturn(stateMock).when(stateAttrMock).get();
  doReturn(endpointMock).when(stateMock).getEndpointForExecution();
  doReturn(requestInfoMock).when(stateMock).getRequestInfo();
  doReturn(true).when(endpointMock).isValidateRequestContent(any());
  doReturn(content).when(requestInfoMock).getContent();
  doReturn(true).when(requestInfoMock).isCompleteRequestWithAllChunks();
  doReturn(true).when(requestInfoMock).isContentDeserializerSetup();
  doReturn(content.length()).when(requestInfoMock).getRawContentLengthInBytes();
  handler = new RequestContentValidationHandler(requestValidatorMock);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_nothing_if_request_isCompleteRequestWithAllChunks_returns_false() throws Exception {
  // given
  doReturn(false).when(requestInfoMock).isCompleteRequestWithAllChunks();
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verifyNoMoreInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: com.nike.riposte/riposte-core

p.addLast(REQUEST_CONTENT_VALIDATION_HANDLER_NAME, new RequestContentValidationHandler(validationService));
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_nothing_if_endpoint_does_not_want_to_validate() throws Exception {
  // given
  doReturn(false).when(endpointMock).isValidateRequestContent(any());
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verifyNoMoreInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

p.addLast(REQUEST_CONTENT_VALIDATION_HANDLER_NAME, new RequestContentValidationHandler(validationService));
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_nothing_if_content_is_null_and_require_content_is_false() throws Exception {
  // given
  doReturn(null).when(requestInfoMock).getContent();
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verifyNoMoreInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_nothing_if_request_isContentDeserializerSetup_returns_false() throws Exception {
  // given
  doReturn(false).when(requestInfoMock).isContentDeserializerSetup();
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verifyNoMoreInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_calls_request_getContent_method_if_endpoint_wants_validation() throws Exception {
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verify(requestInfoMock).getContent();
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_delegates_to_async_processing_when_requested_by_endpoint() throws Exception {
  // given
  doReturn(true).when(endpointMock).shouldValidateAsynchronously(requestInfoMock);
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verify(stateMock).addPreEndpointExecutionWorkChainSegment(any(Function.class));
  verifyZeroInteractions(requestValidatorMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_not_call_request_getContent_method_if_endpoint_does_not_want_validation() throws Exception {
  // given
  doReturn(false).when(endpointMock).isValidateRequestContent(any());
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verify(requestInfoMock, never()).getContent();
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_validates_without_validationGroups_if_validationGroups_is_null() throws Exception {
  // given
  doReturn(null).when(endpointMock).validationGroups(any());
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verify(requestValidatorMock).validateRequestContent(requestInfoMock);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_not_call_request_getContent_method_if_endpoint_is_null() throws Exception {
  // given
  doReturn(null).when(stateMock).getEndpointForExecution();
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verify(requestInfoMock, never()).getContent();
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_validates_with_validationGroups_if_validationGroups_is_not_null() throws Exception {
  // given
  Class<?>[] validationGroups = new Class[]{};
  doReturn(validationGroups).when(endpointMock).validationGroups(any());
  // when
  PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
  // then
  verify(requestValidatorMock).validateRequestContent(requestInfoMock, validationGroups);
  assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

  @Test
  public void doChannelRead_executes_validation_synchronously_when_requested_by_endpoint() throws Exception {
    // given
    doReturn(false).when(endpointMock).shouldValidateAsynchronously(requestInfoMock);

    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);

    // then
    verify(stateMock, never()).addPreEndpointExecutionWorkChainSegment(any(Function.class));
    verify(requestValidatorMock).validateRequestContent(requestInfoMock);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
  }
}
com.nike.riposte.server.handlerRequestContentValidationHandler

Javadoc

Looks at the current channel state's HttpProcessingState#getEndpointForExecution() and HttpProcessingState#getRequestInfo() to see if (1) the endpoint wants the incoming request content validated, and (2) the incoming request's RequestInfo#getContent() is populated. If both those things are true then #validationService will be run on the request's content, which will throw an appropriate exception with validation violation details. If #validationService is null then no validation will be performed.

NOTE: Both the payload deserialization and validation may be done asynchronously if Endpoint#shouldValidateAsynchronously(RequestInfo) returns true. If asynchronous processing is requested then the deserialization and validation will be done via CompletableFuture running in a separate Executor. That future is added to HttpProcessingState#addPreEndpointExecutionWorkChainSegment(Function) so that the endpoint handler can make sure the future completes successfully before the endpoint execution happens. If the future throws an exception then the endpoint should not be executed.

This must come after com.nike.riposte.server.handler.RequestContentDeserializerHandler in the pipeline to make sure that the com.nike.riposte.server.http.RequestInfo#getContent() has had a chance to be populated.

Most used methods

  • <init>
  • executeValidation
  • doChannelRead

Popular in Java

  • Making http post requests using okhttp
  • findViewById (Activity)
  • putExtra (Intent)
  • notifyDataSetChanged (ArrayAdapter)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Locale (java.util)
    A Locale object represents a specific geographical, political, or cultural region. An operation that
  • TreeSet (java.util)
    A NavigableSet implementation based on a TreeMap. The elements are ordered using their Comparable, o
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now