Skip to Content
0

REST Adapter Custom Module

Jun 21, 2017 at 02:01 PM

129

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Sanjeev Shekhar Singh Jun 22, 2017 at 12:48 AM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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

0
Anupam Ghosh Jun 29, 2017 at 12:34 PM
0

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


rest.png (23.3 kB)
Share
10 |10000 characters needed characters left characters exceeded