Java Code Examples for io.netty.handler.codec.http.HttpMethod#PATCH

The following examples show how to use io.netty.handler.codec.http.HttpMethod#PATCH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestContentDeserializationExceptionTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void should_honor_constructor_params() {
    //given
    String message = UUID.randomUUID().toString();
    Throwable cause = new Exception("kaboom");
    RequestInfo<?> requestInfo = new RequestInfoImpl<>("/some/uri/path", HttpMethod.PATCH, null, null, null, null, null, null, null, false, true, false);
    TypeReference<?> typeReferenceMock = mock(TypeReference.class);

    //when
    RequestContentDeserializationException ex = new RequestContentDeserializationException(message, cause, requestInfo, typeReferenceMock);

    //then
    assertThat(ex.getMessage(), is(message));
    assertThat(ex.getCause(), is(cause));
    assertThat(ex.httpMethod, is(requestInfo.getMethod().name()));
    assertThat(ex.requestPath, is(requestInfo.getPath()));
    assertThat(ex.desiredObjectType, is(typeReferenceMock));
}
 
Example 2
Source File: ThriftUnmarshaller.java    From xio with Apache License 2.0 6 votes vote down vote up
private static HttpMethod build(Http1Method method) {
  if (method != null) {
    switch (method) {
      case CONNECT:
        return HttpMethod.CONNECT;
      case DELETE:
        return HttpMethod.DELETE;
      case GET:
        return HttpMethod.GET;
      case HEAD:
        return HttpMethod.HEAD;
      case OPTIONS:
        return HttpMethod.OPTIONS;
      case PATCH:
        return HttpMethod.PATCH;
      case POST:
        return HttpMethod.POST;
      case PUT:
        return HttpMethod.PUT;
      case TRACE:
        return HttpMethod.TRACE;
    }
  }
  return null;
}
 
Example 3
Source File: SignalFxEndpointMetricsHandlerTest.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    metricMetadataMock = mock(MetricMetadata.class);
    metricRegistryMock = mock(MetricRegistry.class);
    requestTimerBuilderMock = mock(MetricBuilder.class);
    dimensionConfiguratorMock = mock(MetricDimensionConfigurator.class);

    handler = new SignalFxEndpointMetricsHandler(
        metricMetadataMock, metricRegistryMock, requestTimerBuilderMock, dimensionConfiguratorMock
    );

    requestInfoMock = mock(RequestInfo.class);
    responseInfoMock = mock(ResponseInfo.class);
    httpStateMock = mock(HttpProcessingState.class);
    endpointMock = mock(Endpoint.class);

    requestStartTime = Instant.now().minus(42, ChronoUnit.MILLIS);
    httpMethod = HttpMethod.PATCH;
    matchingPathTemplate = "/" + UUID.randomUUID().toString();
    doReturn(requestStartTime).when(httpStateMock).getRequestStartTime();
    doReturn(endpointMock).when(httpStateMock).getEndpointForExecution();
    doReturn(httpMethod).when(requestInfoMock).getMethod();
    doReturn(matchingPathTemplate).when(httpStateMock).getMatchingPathTemplate();

    timerBuilderTaggerMock = mock(BuilderTagger.class);
    doReturn(timerBuilderTaggerMock).when(metricMetadataMock).forBuilder(requestTimerBuilderMock);

    doReturn(timerBuilderTaggerMock).when(dimensionConfiguratorMock).setupMetricWithDimensions(
        eq(timerBuilderTaggerMock), eq(requestInfoMock), eq(responseInfoMock), eq(httpStateMock), anyInt(),
        anyInt(), anyLong(), any(), anyString(), anyString(), anyString()
    );

    timerMock = mock(Timer.class);
    doReturn(timerMock).when(timerBuilderTaggerMock).createOrGet(metricRegistryMock);
}
 
Example 4
Source File: RiposteHandlerInternalUtilTest.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    implSpy = spy(new RiposteHandlerInternalUtil());
    stateSpy = spy(new HttpProcessingState());
    nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, "/some/uri");

    resetTracingAndMdc();
}
 
Example 5
Source File: BackstopperRiposteFrameworkErrorHandlerListenerTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldHandleRequestContentDeserializationException() {
    RequestInfo requestInfo = new RequestInfoImpl(null, HttpMethod.PATCH, null, null, null, null, null, null, null, false, true, false);
    verifyExceptionHandled(new RequestContentDeserializationException("intentional boom", null, requestInfo, new TypeReference<Object>() { }), singletonError(
            testProjectApiErrors.getMalformedRequestApiError()));
}
 
Example 6
Source File: RequestInfoImplTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@Test
public void uber_constructor_works_for_valid_values() {
    // given
    String uri = "/some/uri/path/%24foobar%26?notused=blah";
    HttpMethod method = HttpMethod.PATCH;
    Charset contentCharset = CharsetUtil.US_ASCII;
    HttpHeaders headers = new DefaultHttpHeaders().add("header1", "val1").add(HttpHeaders.Names.CONTENT_TYPE, "text/text charset=" + contentCharset.displayName());
    QueryStringDecoder queryParams = new QueryStringDecoder(uri + "?foo=bar&secondparam=secondvalue");
    Set<Cookie> cookies = new HashSet<>(Arrays.asList(new DefaultCookie("cookie1", "val1"), new DefaultCookie("cookie2", "val2")));
    Map<String, String> pathParams = Arrays.stream(new String[][] {{"pathParam1", "val1"}, {"pathParam2", "val2"}}).collect(Collectors.toMap(pair -> pair[0], pair -> pair[1]));
    String content = UUID.randomUUID().toString();
    byte[] contentBytes = content.getBytes();
    LastHttpContent chunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(contentBytes));
    chunk.trailingHeaders().add("trailingHeader1", "trailingVal1");
    List<HttpContent> contentChunks = Collections.singletonList(chunk);
    HttpVersion protocolVersion = HttpVersion.HTTP_1_1;
    boolean keepAlive = true;
    boolean fullRequest = true;
    boolean isMultipart = false;

    // when
    RequestInfoImpl<?> requestInfo = new RequestInfoImpl<>(uri, method, headers, chunk.trailingHeaders(), queryParams, cookies, pathParams, contentChunks, protocolVersion, keepAlive, fullRequest, isMultipart);

    // then
    assertThat("getUri should return passed in value", requestInfo.getUri(), is(uri));
    assertThat("getPath did not decode as expected", requestInfo.getPath(), is("/some/uri/path/$foobar&"));
    assertThat(requestInfo.getMethod(), is(method));
    assertThat(requestInfo.getHeaders(), is(headers));
    assertThat(requestInfo.getTrailingHeaders(), is(chunk.trailingHeaders()));
    assertThat(requestInfo.getQueryParams(), is(queryParams));
    assertThat(requestInfo.getCookies(), is(cookies));
    assertThat(requestInfo.pathTemplate, nullValue());
    assertThat(requestInfo.pathParams, is(pathParams));
    assertThat(requestInfo.getRawContentBytes(), is(contentBytes));
    assertThat(requestInfo.getRawContent(), is(content));
    assertThat(requestInfo.content, nullValue());
    assertThat(requestInfo.getContentCharset(), is(contentCharset));
    assertThat(requestInfo.getProtocolVersion(), is(protocolVersion));
    assertThat(requestInfo.isKeepAliveRequested(), is(keepAlive));
    assertThat(requestInfo.isCompleteRequestWithAllChunks, is(fullRequest));
    assertThat(requestInfo.isMultipart, is(isMultipart));
}
 
Example 7
Source File: RequestInfoImplTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@Test
public void netty_helper_constructor_populates_request_info_appropriately() {
    // given
    String uri = "/some/uri/path/%24foobar%26?foo=bar&secondparam=secondvalue";
    Map<String, List<String>> expectedQueryParamMap = new HashMap<>();
    expectedQueryParamMap.put("foo", Arrays.asList("bar"));
    expectedQueryParamMap.put("secondparam", Arrays.asList("secondvalue"));
    HttpMethod method = HttpMethod.PATCH;
    String cookieName = UUID.randomUUID().toString();
    String cookieValue = UUID.randomUUID().toString();
    String content = UUID.randomUUID().toString();
    byte[] contentBytes = content.getBytes();
    Charset contentCharset = CharsetUtil.UTF_8;
    ByteBuf contentByteBuf = Unpooled.copiedBuffer(contentBytes);
    HttpHeaders headers = new DefaultHttpHeaders()
            .add("header1", "val1")
            .add(HttpHeaders.Names.CONTENT_TYPE, contentCharset)
            .add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
            .add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookieName, cookieValue));
    HttpHeaders trailingHeaders = new DefaultHttpHeaders().add("trailingHeader1", "trailingVal1");
    HttpVersion protocolVersion = HttpVersion.HTTP_1_1;

    FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
    doReturn(uri).when(nettyRequestMock).uri();
    doReturn(method).when(nettyRequestMock).method();
    doReturn(headers).when(nettyRequestMock).headers();
    doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();
    doReturn(contentByteBuf).when(nettyRequestMock).content();
    doReturn(protocolVersion).when(nettyRequestMock).protocolVersion();

    // when
    RequestInfoImpl<?> requestInfo = new RequestInfoImpl<>(nettyRequestMock);

    // then
    assertThat("getUri was not the same value sent in", requestInfo.getUri(), is(uri));
    assertThat("getPath did not decode as expected", requestInfo.getPath(), is("/some/uri/path/$foobar&"));
    assertThat(requestInfo.getMethod(), is(method));
    assertThat(requestInfo.getHeaders(), is(headers));
    assertThat(requestInfo.getTrailingHeaders(), is(trailingHeaders));
    assertThat(requestInfo.getQueryParams(), notNullValue());
    assertThat(requestInfo.getQueryParams().parameters(), is(expectedQueryParamMap));
    assertThat(requestInfo.getCookies(), is(Sets.newHashSet(new DefaultCookie(cookieName, cookieValue))));
    assertThat(requestInfo.pathTemplate, nullValue());
    assertThat(requestInfo.pathParams.isEmpty(), is(true));
    assertThat(requestInfo.getRawContentBytes(), is(contentBytes));
    assertThat(requestInfo.getRawContent(), is(content));
    assertThat(requestInfo.content, nullValue());
    assertThat(requestInfo.getContentCharset(), is(contentCharset));
    assertThat(requestInfo.getProtocolVersion(), is(protocolVersion));
    assertThat(requestInfo.isKeepAliveRequested(), is(true));
}
 
Example 8
Source File: Route.java    From Discord4J with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Route patch(String uri) {
    return new Route(HttpMethod.PATCH, uri);
}
 
Example 9
Source File: HttpRequestUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isWriteFromBrowserWithoutOrigin(HttpRequest request) {
  HttpMethod method = request.method();

  return StringUtil.isEmpty(getOrigin(request)) && isRegularBrowser(request) && (method == HttpMethod.POST || method == HttpMethod.PATCH || method == HttpMethod.PUT || method == HttpMethod.DELETE);
}