Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
hiba1
Contributor
Contributor

tjava

Hi ,

i have this script i want to use it in tjava component , how can i do this !!!

<cfset dtGMT = DateAdd("s", GetTimeZoneInfo().UTCTotalOffset, now() ) />

<cfset timestamp = Int((dtGMT.getTime() / 1000)/60)>

<cfset signature = Hash("# apiKey# # password# # timestamp# ", "SHA-256")>

any help please !

Labels (3)
4 Replies
Anonymous
Not applicable

Hello,

It seems you are showing ColdFusion code. https://helpx.adobe.com/coldfusion/developing-applications/using-web-elements-and-ex[…]nd-java-eleme...

What are you trying to achieve? Do you want to extract the Java logic from this ColdFusion page?

Best regards

Sabrina

hiba1
Contributor
Contributor
Author

yes ...

i got the the code in java,

 

import java.io.UnsupportedEncodingException;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

import java.security.Timestamp;

import java.util.Date;

String apiKey = "test";

String secret = "test";

Date date= new java.util.Date();

Long timestamp = (date.getTime() / 1000);

String signature = null;

try {

  String toBeHashed = apiKey + secret + timestamp;

  MessageDigest md = MessageDigest.getInstance("SHA-512");

  byte[] bytes = md.digest(toBeHashed.getBytes("UTF-8"));

  StringBuilder sb = new StringBuilder();

  for(int i=0; i< bytes.length ;i++){

    sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));

  }

  signature = sb.toString();

} catch (NoSuchAlgorithmException e) {

  e.printStackTrace();

} catch (UnsupportedEncodingException e) {

  e.printStackTrace();

}

String authHeaderValue = "EAN APIKey=" + apiKey + ",Signature=" + signature + ",timestamp=" + timestamp;

 

 

 

 

then i want to call the variable "signature" in the header of "tRestClient" (for authentification"

 

but i got error

 

0693p00000Ac0bjAAB.png0693p00000Ac0beAAB.png

Anonymous
Not applicable

Hello

Move the import xxxx code to Advanced settings panel of tJava component.

In addition, there are two issues in your job design.

1 Use OncomponentOK or OnsubjobOK connector from tJava to tRestClient.

2 You should initialize the global variable before it is used, eg: in the end of tJava,

globalMap.put("signature",signature );

 

Regards

Shong

hiba1
Contributor
Contributor
Author

Hi @Shicong Hong​ 

thanks for reply

 

Still can't get the variable in tRestClient.

the variable "sig" is a dynamic variable ..for every call to the routine "sig" will have a new value

 

0693p00000Ac7QnAAJ.png0693p00000Ac7QiAAJ.png