I have the following approach for getting instance of my endpoint. I want to add a header to it. How do I do that? Please modify my code following, to include the header bit. Thanks.
public class RemoteServiceEndpointReference {
private static final boolean USING_LOCAL_SERVER = false;
private static final String LOCAL_SERVER_PATH = “…”;
private static RemoteService service;
public static RemoteService getRemoteServiceEndpoint() {
if (null != service) {
return service;
}
RemoteService.Builder builder = new RemoteService.Builder(
AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(),
null
);
forLocalServer(builder);
service = builder.build();
return service;
}
private static void forLocalServer(AbstractGoogleJsonClient.Builder builder) {
if (USING_LOCAL_SERVER) {
builder.setRootUrl(LOCAL_SERVER_PATH)
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
request.setDisableGZipContent(true);
}
});
}
}
}
You should be able to do something like this:
@Override
public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
HttpHeaders yourHeaders = new HttpHeaders();
header.set("yourHeader", value);
// ...
request.setDisableGZipContent(true);
request.setRequestHeaders(yourHeaders); // setting the headers
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With