How-To add HTTP header properties in RunTime

How-To add HTTP header properties in RunTime

In some cases, there is a need to add a specific HTTP header to the transmitted request. For example, in case you need to add a specific Token into the transmitted request. In order to do that you can use our HttpRequestCustomizer Interface. This guide will show how to use this bean for version 4.3.8, and the Backend will be REST.

This feature is only available for CICS and REST backends

Step 1:

Create a Class that will implement the HttpRequestCustomizer Interface, e.g. the following class

For CICS you need to use HttpRequestCustomizer<HttpRequestBase>

In the customize method you need to set the desired behavior you want, in our example, we are adding to the HTTP request a Header caller “Header-In” it values is located in the arg1 map under “header-in”.

Step 2:

To your Configuration class add the following Bean:

The returned value is the Class created in Step 1.

For CICS the bean should look like the following:

Step 3:

Let’s make this work.

In your Service Impl you need to do make the following changes

Extract the ActionUtil inside the do Action to a local variable out of it e.g:

call1 = xmlSdkRpcSession.doAction(ActionUtil.getRpcAction(Call1.class), call1);

Will be converted to:

RpcAction rpcAction = ActionUtil.getRpcAction(Call1.class); call1 = xmlSdkRpcSession.doAction(rpcAction, call1);

Create a Map and populate it with the desired properties, e.g:

Map<String, String> properties = new HashMap<>(); properties.put("header-in", "Hello World!");

Lastly, add the properties to the RpcAction

properties.put("header-in", "Hello World!");

The Code will need to look similar to the following snippet:

 

The result from the changes in this guide would be that the transmitted entity will include the following header:

2020-05-10 11:53:31.616 INFO 31138 --- [ main] o.o.i.r.support.RpcConnectionDelegator : Opened new session 2020-05-10 11:53:31.732 DEBUG 31138 --- [ main] o.o.p.r.t.HttpLoggingInterceptor : --> GET http://localhost:3000/testGet http/1.1 2020-05-10 11:53:31.732 DEBUG 31138 --- [ main] o.o.p.r.t.HttpLoggingInterceptor : accept: application/xml 2020-05-10 11:53:31.732 DEBUG 31138 --- [ main] o.o.p.r.t.HttpLoggingInterceptor : Header-In: Hello World!