1

I am using approach, described in this question to add my specific header to HTTP get request. But I can't understand how I need to change my code to make interceptor to do his job. Currently I am using something like this:

@RestService
ImwizardClient imwizardClient;

//some code

return  imwizardClient.getAllCategories();

where getAllCategories() is method, which makes get request. The request works correctly, but it doesn't add my custom header. So what do I need to change?

Community
  • 1
  • 1
Mykhailo Granik
  • 368
  • 8
  • 23

1 Answers1

1

Is your Interceptor defined for your RestService class as documented here?

@Rest(interceptors = { HttpBasicAuthenticatorInterceptor.class })
public interface ImwizardClient {
 // ... snipped
}

Alternatively, the workaround posted in this thread seems to work reliably. Just define a custom MessageConverter for your RestService class.

public class GsonWithHeadersConverter extends GsonHttpMessageConverter {

@Override
    protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        setHeaders(outputMessage); //My method to put the additional headers :)
        super.writeInternal(o, outputMessage);
    }

}

Nachi
  • 4,218
  • 2
  • 37
  • 58