Java Code Examples for org.springframework.http.HttpMethod#PATCH

The following examples show how to use org.springframework.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: FormContentFilterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
		request.setContent("foo=bar".getBytes("ISO-8859-1"));
		request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.filterChain = new MockFilterChain();
		this.filter.doFilter(request, this.response, this.filterChain);
		if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
			assertNotSame(request, this.filterChain.getRequest());
		}
		else {
			assertSame(request, this.filterChain.getRequest());
		}
	}
}
 
Example 2
Source File: AbstractAsyncHttpRequestFactoryTestCase.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			request.getBody().write(32);
		}
		Future<ClientHttpResponse> futureResponse = request.executeAsync();
		response = futureResponse.get();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 3
Source File: AbstractHttpRequestFactoryTestCase.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			try {
				request.getBody().write(32);
			}
			catch (UnsupportedOperationException ex) {
				// probably a streaming request - let's simply ignore it
			}
		}
		response = request.execute();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 4
Source File: AbstractHttpRequestFactoryTestCase.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			try {
				request.getBody().write(32);
			}
			catch (UnsupportedOperationException ex) {
				// probably a streaming request - let's simply ignore it
			}
		}
		response = request.execute();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 5
Source File: AbstractAsyncHttpRequestFactoryTestCase.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			request.getBody().write(32);
		}
		Future<ClientHttpResponse> futureResponse = request.executeAsync();
		response = futureResponse.get();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 6
Source File: FormContentFilterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
		request.setContent("foo=bar".getBytes("ISO-8859-1"));
		request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.filterChain = new MockFilterChain();
		this.filter.doFilter(request, this.response, this.filterChain);
		if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
			assertNotSame(request, this.filterChain.getRequest());
		}
		else {
			assertSame(request, this.filterChain.getRequest());
		}
	}
}
 
Example 7
Source File: AbstractAsyncHttpRequestFactoryTestCase.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			request.getBody().write(32);
		}
		Future<ClientHttpResponse> futureResponse = request.executeAsync();
		response = futureResponse.get();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 8
Source File: AbstractHttpRequestFactoryTestCase.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
	ClientHttpResponse response = null;
	try {
		ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/methods/" + path), method);
		if (method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH) {
			// requires a body
			try {
				request.getBody().write(32);
			}
			catch (UnsupportedOperationException ex) {
				// probably a streaming request - let's simply ignore it
			}
		}
		response = request.execute();
		assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
		assertEquals("Invalid method", path.toUpperCase(Locale.ENGLISH), request.getMethod().name());
	}
	finally {
		if (response != null) {
			response.close();
		}
	}
}
 
Example 9
Source File: WingtipsClientHttpRequestInterceptorTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() throws IOException {
    resetTracing();

    initialSpanNameFromStrategy = new AtomicReference<>("span-name-from-strategy-" + UUID.randomUUID().toString());
    strategyInitialSpanNameMethodCalled = new AtomicBoolean(false);
    strategyRequestTaggingMethodCalled = new AtomicBoolean(false);
    strategyResponseTaggingAndFinalSpanNameMethodCalled = new AtomicBoolean(false);
    strategyInitialSpanNameArgs = new AtomicReference<>(null);
    strategyRequestTaggingArgs = new AtomicReference<>(null);
    strategyResponseTaggingArgs = new AtomicReference<>(null);
    tagAndNamingStrategy = new ArgCapturingHttpTagAndSpanNamingStrategy(
        initialSpanNameFromStrategy, strategyInitialSpanNameMethodCalled, strategyRequestTaggingMethodCalled,
        strategyResponseTaggingAndFinalSpanNameMethodCalled, strategyInitialSpanNameArgs,
        strategyRequestTaggingArgs, strategyResponseTaggingArgs
    );
    tagAndNamingAdapterMock = mock(HttpTagAndSpanNamingAdapter.class);

    spanRecorder = new SpanRecorder();
    Tracer.getInstance().addSpanLifecycleListener(spanRecorder);

    method = HttpMethod.PATCH;
    uri = URI.create("http://localhost:4242/" + UUID.randomUUID().toString());
    headersMock = mock(HttpHeaders.class);
    requestMock = mock(HttpRequest.class);
    doReturn(headersMock).when(requestMock).getHeaders();
    doReturn(method).when(requestMock).getMethod();
    doReturn(uri).when(requestMock).getURI();

    body = UUID.randomUUID().toString().getBytes();

    responseMock = mock(ClientHttpResponse.class);

    executionMock = mock(ClientHttpRequestExecution.class);
    doAnswer(invocation -> {
        tracingStateAtTimeOfExecution = TracingState.getCurrentThreadTracingState();
        return responseMock;
    }).when(executionMock).execute(any(HttpRequest.class), any(byte[].class));
}
 
Example 10
Source File: FrameworkServlet.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Override the parent class implementation in order to intercept PATCH requests.
 */
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	HttpMethod httpMethod = HttpMethod.resolve(request.getMethod());
	if (httpMethod == HttpMethod.PATCH || httpMethod == null) {
		processRequest(request, response);
	}
	else {
		super.service(request, response);
	}
}
 
Example 11
Source File: FrameworkServlet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Override the parent class implementation in order to intercept PATCH requests.
 */
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	HttpMethod httpMethod = HttpMethod.resolve(request.getMethod());
	if (HttpMethod.PATCH == httpMethod || httpMethod == null) {
		processRequest(request, response);
	}
	else {
		super.service(request, response);
	}
}
 
Example 12
Source File: FrameworkServlet.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Override the parent class implementation in order to intercept PATCH requests.
 */
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	HttpMethod httpMethod = HttpMethod.resolve(request.getMethod());
	if (httpMethod == HttpMethod.PATCH || httpMethod == null) {
		processRequest(request, response);
	}
	else {
		super.service(request, response);
	}
}
 
Example 13
Source File: HttpRequestWrapperWithModifiableHeadersTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    uri = URI.create("http://localhost:4242/" + UUID.randomUUID().toString());
    method = HttpMethod.PATCH;
    requestMock = mock(HttpRequest.class);
    doReturn(uri).when(requestMock).getURI();
    doReturn(method).when(requestMock).getMethod();
}
 
Example 14
Source File: ApiProxyController.java    From demo-spring-webflux-api-gateway with Apache License 2.0 4 votes vote down vote up
private boolean requireHttpBody(HttpMethod method)
{
	    return HttpMethod.POST == method || HttpMethod.PUT == method || 
	    		   HttpMethod.PATCH == method || HttpMethod.TRACE == method ;
}
 
Example 15
Source File: WingtipsAsyncClientHttpRequestInterceptorTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeMethod() throws IOException {
    resetTracing();

    initialSpanNameFromStrategy = new AtomicReference<>("span-name-from-strategy-" + UUID.randomUUID().toString());
    strategyInitialSpanNameMethodCalled = new AtomicBoolean(false);
    strategyRequestTaggingMethodCalled = new AtomicBoolean(false);
    strategyResponseTaggingAndFinalSpanNameMethodCalled = new AtomicBoolean(false);
    strategyInitialSpanNameArgs = new AtomicReference<>(null);
    strategyRequestTaggingArgs = new AtomicReference<>(null);
    strategyResponseTaggingArgs = new AtomicReference<>(null);
    tagAndNamingStrategy = new ArgCapturingHttpTagAndSpanNamingStrategy(
        initialSpanNameFromStrategy, strategyInitialSpanNameMethodCalled, strategyRequestTaggingMethodCalled,
        strategyResponseTaggingAndFinalSpanNameMethodCalled, strategyInitialSpanNameArgs,
        strategyRequestTaggingArgs, strategyResponseTaggingArgs
    );
    tagAndNamingAdapterMock = mock(HttpTagAndSpanNamingAdapter.class);

    spanRecorder = new SpanRecorder();
    Tracer.getInstance().addSpanLifecycleListener(spanRecorder);

    method = HttpMethod.PATCH;
    uri = URI.create("http://localhost:4242/" + UUID.randomUUID().toString());
    headersMock = mock(HttpHeaders.class);
    requestMock = mock(HttpRequest.class);
    doReturn(headersMock).when(requestMock).getHeaders();
    doReturn(method).when(requestMock).getMethod();
    doReturn(uri).when(requestMock).getURI();

    body = UUID.randomUUID().toString().getBytes();
    executionMock = mock(AsyncClientHttpRequestExecution.class);
    doAnswer(invocation -> {
        tracingStateAtTimeOfExecution = TracingState.getCurrentThreadTracingState();
        executionResponseFuture = new SettableListenableFuture<>();
        return executionResponseFuture;
    }).when(executionMock).executeAsync(any(HttpRequest.class), any(byte[].class));

    normalCompletionResponse = mock(ClientHttpResponse.class);
    normalResponseCode = 200; //Normal
    doReturn(normalResponseCode).when(normalCompletionResponse).getRawStatusCode();
}
 
Example 16
Source File: MockMvcRequestBuilders.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder patch(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.PATCH, uri);
}
 
Example 17
Source File: MockMvcRequestBuilders.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVars zero or more URI variables
 */
public static MockHttpServletRequestBuilder patch(String urlTemplate, Object... uriVars) {
	return new MockHttpServletRequestBuilder(HttpMethod.PATCH, urlTemplate, uriVars);
}
 
Example 18
Source File: MockMvcRequestBuilders.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder patch(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.PATCH, uri);
}
 
Example 19
Source File: MockMvcRequestBuilders.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 */
public static MockHttpServletRequestBuilder patch(String urlTemplate, Object... urlVariables) {
	return new MockHttpServletRequestBuilder(HttpMethod.PATCH, urlTemplate, urlVariables);
}
 
Example 20
Source File: MockMvcRequestBuilders.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
 * @param uri the URL
 * @since 4.0.3
 */
public static MockHttpServletRequestBuilder patch(URI uri) {
	return new MockHttpServletRequestBuilder(HttpMethod.PATCH, uri);
}