Spring HTTP Remoting – pass custom HTTP header elements

If you are using Spring HTTP Remoting to communicate between your applications, sometimes you might want to pass certain custom HTTP header elements in the requests. Following approach would help you to solve this problem:

Extend SimpleHttpInvokerRequestExecutor

Extend SimpleHttpInvokerRequestExecutor with a custom implementation. In this implemenetation over-ride prepareConnection() method to set additional HTTP header elements:

public class MyHttpInvokerRequestExecutor extends SimpleHttpInvokerRequestExecutor {

@Override
protected void prepareConnection(HttpURLConnection con, int contentLength) throws IOException {

con.addRequestProperty(“header-element-key”, “header-element-value”);
super.prepareConnection(con, contentLength);
}
}

Inject in to HttpInvokerProxyFactoryBean

Now besides all othe regular fields to HttpInvokerProxyFactoryBean, inject this new MyHttpInvokerRequestExecutor

class=”org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean”>

:
:
class=”com.tier1app.remoting.httpinvoker.MyHttpInvokerRequestExecutor” />

Now “header-element-key” will be passed in and each & every HTTP requests. Enjoy 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: