cancel
Showing results for 
Search instead for 
Did you mean: 

REST Adapter Custom Module

Former Member
0 Kudos

Hi All,

I am working on a requirement where I need to Authenticate the Auth token being received in the HTTP header.

At this point I am assuming that I would need a Custom Adapter Module to get this requirement where I will have to access the HTTP header and then call the authentication service. The issue is that I am not able to find a function that will get me the HTTP header value. If you guys can help out that would be great.

Alternative would be a way to pass the header value as a part of the message payload, if this is possible then we can also do this using a Java mapping.

Any suggestions???

Thanks

Nikhil

Accepted Solutions (1)

Accepted Solutions (1)

former_member194786
Active Contributor
0 Kudos

Hi Nikhil,

Assuming you are working on PO(BPM) and have REST adapter for connection, you can orchestrate the solution to get the HTTP headers using Dynamic configuration. Check this blog for more details on reading HTTP headers in dynamic configuration:

https://blogs.sap.com/2014/12/18/pi-rest-adapter-using-dynamic-attributes/

Regards,

Sanjeev

Former Member
0 Kudos

Hi Sanjeev,

Thanks for the help. this way i should be able to access the HTTP header value in the mapping.

My question now would be how to raise a HTTP 401 error if this header is invalid.

Thanks

Nikhil

Answers (1)

Answers (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nikhil,

I guess you are receiving JSON payload and using REST sender adapter. Then you can always use the option

"Retrieve the value from a Custom HTTP Header by specifying the Header Field". This allows you to store the value in an custom attribute and again read the same using UDF. You can check this option in this link. Change this option(custom attribute) in image to Custom HTTP header.

Then use an UDF to read the "mode" variable as "attribute"

public String getASMA (String namespace,String attribute,Container container) throws StreamTransformationException{

 Map<String, Object> all = container.getInputHeader().getAll(); 

DynamicConfiguration dynConf = (DynamicConfiguration)all.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute); 

String value = dynConf.get(key); 

return value;
}

Regards

Anupam