how to dynamically produce a Header

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to dynamically produce a Header

christian.jacob@innogy.com
Hi there,

I have to read data from a remote host with the http component. The provider of that remote host had sent to me a security token that I have to embed as a query parameter into the request. Of course, I don't want to write that security token into my program, nor do I want to write it in a properties file. So I read a little bit about Jasyp in Camel and the Camel Properties component. All very nice. I must use the header Exchange.HTTP_QUERY because I have to provide proxy informations into the http request.

So, a working example looks like this:
from ("direct:startToRead")
.routeId("startToRead")
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.setHeader(Exchange.HTTP_QUERY, constant(
"securityToken={{token}}"
+ "&start=201612312300"
+ "&end=201701312300"))
.log("start to read")
.toD("${body}")

The encrypted token is written in a properties file, and it is resolved as desired.

As you can see, the request also contains a start and an end timestamp. These timestamps have to be calculated dynamically before. When I try to do so, the http request is garbled because the {{token}} part is not resolved. This is the error message:
org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://the.remote.host?securityToken=%7B%7Btoken%7D%7D&periodStart=201612312300&periodEnd=201701312300 with statusCode: 401

I tried several other ways to set this header dynamically:
  -  a Processor that sets the header Exchange.HTTP_REQUEST
  -  let the Processor write it into a custom header and use its value in an invocation of .setHeader
  -  let a Provider construct the String

All of them failed.

Has anybody an idea how to get out of this trap? My only idea is to invoke Jasypt decryption in my Processor when setting up my dynamic String, but I don't believe that this is a good solution.

Kind regards,
Christian Jacob

Innogy SE
Retail IT
Integration and Digital Solutions (AFS-IGI)
Rellinghauser Str. 37
45128 Essen
T intern: 70-20581
T extern: +49 (0)201 12 20582
T mobil: +49 (0)1622843981
Fax: +49 (0)201 12 24796
mailto: [hidden email]

----------------------------------------------------------------
innogy SE Vorsitzender des Aufsichtsrates: Dr. Werner Brandt
Vorstand: Peter Terium (Vorsitzender), Dr. Hans Buenting,
Dr. Bernhard Guenther, Martin Herrmann, Hildegard Mueller, Uwe Tigges
Sitz der Gesellschaft: Essen, Eingetragen beim Amtsgericht Essen,
Handelsregister-Nr. HRB 27091, USt-IdNr. DE304171711
Reply | Threaded
Open this post in threaded view
|

AW: how to dynamically produce a Header

christian.jacob@innogy.com
Hi all,

In the meantime, I found a solution: I don't remember exactly the reason why during my researches I had switched to use the header Exchange.HTTP_REQUEST. At least in my situation, it isn't necessary. I now just expressed the whole URI for the http request including our proxy settings in the body with the placeholder for the security token instead of using this header, and everything worked find.

See you,
Christian

-----Urspr√ľngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]]
Gesendet: Dienstag, 5. Dezember 2017 17:53
An: [hidden email]
Betreff: how to dynamically produce a Header

Hi there,

I have to read data from a remote host with the http component. The provider of that remote host had sent to me a security token that I have to embed as a query parameter into the request. Of course, I don't want to write that security token into my program, nor do I want to write it in a properties file. So I read a little bit about Jasyp in Camel and the Camel Properties component. All very nice. I must use the header Exchange.HTTP_QUERY because I have to provide proxy informations into the http request.

So, a working example looks like this:
from ("direct:startToRead")
.routeId("startToRead")
.setHeader(Exchange.HTTP_METHOD, constant("GET")) .setHeader(Exchange.HTTP_QUERY, constant( "securityToken={{token}}"
+ "&start=201612312300"
+ "&end=201701312300"))
.log("start to read")
.toD("${body}")

The encrypted token is written in a properties file, and it is resolved as desired.

As you can see, the request also contains a start and an end timestamp. These timestamps have to be calculated dynamically before. When I try to do so, the http request is garbled because the {{token}} part is not resolved. This is the error message:
org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://the.remote.host?securityToken=%7B%7Btoken%7D%7D&periodStart=201612312300&periodEnd=201701312300 with statusCode: 401

I tried several other ways to set this header dynamically:
  -  a Processor that sets the header Exchange.HTTP_REQUEST
  -  let the Processor write it into a custom header and use its value in an invocation of .setHeader
  -  let a Provider construct the String

All of them failed.

Has anybody an idea how to get out of this trap? My only idea is to invoke Jasypt decryption in my Processor when setting up my dynamic String, but I don't believe that this is a good solution.

Kind regards,
Christian Jacob

Innogy SE
Retail IT
Integration and Digital Solutions (AFS-IGI) Rellinghauser Str. 37
45128 Essen
T intern: 70-20581
T extern: +49 (0)201 12 20582
T mobil: +49 (0)1622843981
Fax: +49 (0)201 12 24796
mailto: [hidden email]

----------------------------------------------------------------
innogy SE Vorsitzender des Aufsichtsrates: Dr. Werner Brandt
Vorstand: Peter Terium (Vorsitzender), Dr. Hans Buenting, Dr. Bernhard Guenther, Martin Herrmann, Hildegard Mueller, Uwe Tigges Sitz der Gesellschaft: Essen, Eingetragen beim Amtsgericht Essen, Handelsregister-Nr. HRB 27091, USt-IdNr. DE304171711
----------------------------------------------------------------
innogy SE Vorsitzender des Aufsichtsrates: Dr. Werner Brandt
Vorstand: Peter Terium (Vorsitzender), Dr. Hans Buenting,
Dr. Bernhard Guenther, Martin Herrmann, Hildegard Mueller, Uwe Tigges
Sitz der Gesellschaft: Essen, Eingetragen beim Amtsgericht Essen,
Handelsregister-Nr. HRB 27091, USt-IdNr. DE304171711