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

The following examples show how to use org.springframework.http.HttpMethod#PATCH . These examples are extracted from open source projects. 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
@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
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
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
@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 5
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
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 7
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
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 Project: spring-analysis-note   File: FrameworkServlet.java    License: 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 10
@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 11
Source Project: java-technology-stack   File: FrameworkServlet.java    License: 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 12
/**
 * 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 13
@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 14
private boolean requireHttpBody(HttpMethod method)
{
	    return HttpMethod.POST == method || HttpMethod.PUT == method || 
	    		   HttpMethod.PATCH == method || HttpMethod.TRACE == method ;
}
 
Example 15
@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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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
/**
 * 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);
}