All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.social.partnercenter.connect.AddHeaderRequestInterceptor Maven / Gradle / Ivy

Go to download

A provider extension for Spring Social to enable connectivity with Microsoft and an API binding for Microsoft's Partner Center API.

There is a newer version: 10.11.0
Show newest version
package org.springframework.social.partnercenter.connect;

import java.io.IOException;

import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.social.support.HttpRequestDecorator;

public class AddHeaderRequestInterceptor implements ClientHttpRequestInterceptor {
	private final String headerName;

	private final String headerValue;

	/**
	 * Creates an instance of the interceptor, that inserts a header with given name and value.
	 * @param headerName The name of the header
	 * @param headerValue The value of the header.
	 */
	public AddHeaderRequestInterceptor(String headerName, String headerValue) {
		this.headerValue = headerValue;
		this.headerName = headerName;
	}

	@Override
	public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
		HttpRequest protectedResourceRequest = new HttpRequestDecorator(request);
		protectedResourceRequest.getHeaders().set(headerName, headerValue);
		return execution.execute(protectedResourceRequest, body);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy