# Reformat component issue in java

**URL:** <https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062>\
**Category:** CloverDX Platform\
**Created:** [April 28, 2012, 12:00am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062 "2012-04-28T00:00:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![poctavian](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@poctavian](https://forum.cloverdx.com/u/poctavian)\
**Post date:** [April 28, 2012, 12:00am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/1 "2012-04-28T00:00:00Z")

</div>

Hi,

I converted my reformat component to java since my task involves encrypting a string to HmacSHA256 and I’m having difficulties with it. What I did was I first created a java file in JCreator then tested it and it succesfully encrypts my string then encode it to base64. What I did then was I copy pasted the code from JCreator to clover in the reformat component. However, when I run the graph I get an error.

unreported exception java.security.SignatureException; must be caught or declared to be thrown  
hashed = signedReq.sign(stringToSign,key);

Here’s what I have in my reformat component:

public String sign(String stringToSign, String key) throws SignatureException  
{  
byte signature;  
try  
{  
Mac mac = Mac.getInstance(“HmacSHA256”);  
mac.init(new SecretKeySpec(key.getBytes(), “HmacSHA256”));  
signature = Base64.encodeBase64(mac.doFinal(stringToSign.getBytes(“UTF-8”)));  
}  
catch (Exception e)  
{  
throw new SignatureException("Failed to generate signature: " + e.getMessage(), e);  
}  
}

protected final int transformDelegate() throws org.jetel.exception.ComponentNotReadyException, org.jetel.exception.TransformException  
{  
String stringToSign;  
String key = “Key”;  
String hashed;  
String ts;  
String urlEncoded;

CTL\_REFORMAT0\_26042012\_14\_36\_40\_0 signedReq = new CTL\_REFORMAT0\_26042012\_14\_36\_40\_0();  
ts = signedReq.getFormattedTimestamp();  
stringToSign = signedReq.calculatedString() + ts.replace(“:”,“%3A”).replace(“.”,“%2E”);  
hashed = signedReq.sign(stringToSign,key);  
urlEncoded = hashed.replace(“+”,“%2B”).replace(“\*”, “%2A”).replace(“~”, “%7E”).replace(“/”,“%2F”).replace(“=”,“%3D”);  
getOutputRecord(0).getField(0).setValue(org.jetel.ctl.extensions.StringLib.concat(this.\_\_ctl\_function\_call\_context[0],“Signature:”,urlEncoded));

return 0;  
}

Is protected final int transformDelegate() in the reformat component equivalent to my main() method? Thanks.

---

<div class="post-metadata">

**Author:** ![jurban](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jurban](https://forum.cloverdx.com/u/jurban)\
**Post date:** [April 30, 2012, 8:45am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/2 "2012-04-30T08:45:57Z")

</div>

Hi,

your issue can be broken down into 2 parts:

1. I believe you’re extending the CTLRecordTransform class as the base for your transformation. That class is internally used by our CTL to Java compiler, it’s not intended to be used elsewhere. You should extend the DataRecordTransform class and implement the transform() method - this will be your “main”.

2. The specific cause of the error you’re seeing is that the sign() method throws SignatureException, and you don’t catch the exception at the location where you’re calling the method (I’m guessing that your original main had a “throws Exception” clause). You should catch the SignatureException and either re-throw it by wrapping it in a TransformException, or handle the error in some other way (e.g. send some record to a different output port for error logging).

Combining the 2 hints above should help - extend DataRecordTransform and catch the SignatureException.

Best regards,  
Jaro

---

<div class="post-metadata">

**Author:** ![poctavian](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@poctavian](https://forum.cloverdx.com/u/poctavian)\
**Post date:** [May 1, 2012, 1:46am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/3 "2012-05-01T01:46:24Z")

</div>

Hi Jaro,

Thanks for the response. I’m new to all this and I really appreciate your help.

I did the changes you asked me to do and I still have a few more questions about how to make my code work in the reformat component since I’m still getting some errors that I can’t figure out.

First, I used to have public final class CTL\_REFORMAT0\_01052012\_09\_15\_57\_0 extends org.jetel.component.CTLRecordTransform {} then I changed it to public final class CTL\_REFORMAT0\_01052012\_09\_15\_57\_0 extends org.jetel.component.DataRecordTransform {}  
but I’m getting an error that says “CTL\_REFORMAT0\_01052012\_09\_15\_57\_0 is not abstract and does not override abstract method transform(org.jetel.data.DataRecord,org.jetel.data.DataRecord) in org.jetel.component.DataRecordTransform”. So I changed it to public abstract class CTL\_REFORMAT0\_01052012\_09\_15\_57\_0 extends org.jetel.component.DataRecordTransform {}, I’m not even sure if I should be doing that. Also, you mentioned that I should implement the transform() method and that would act as my main method. Does that mean that I should change protected final int transformDelegate() throws org.jetel.exception.ComponentNotReadyException, org.jetel.exception.TransformException to public void transform() throws org.jetel.exception.ComponentNotReadyException, org.jetel.exception.TransformException? One more thing, should my class be something like “public final class CTL\_REFORMAT0\_01052012\_09\_15\_57\_0 extends org.jetel.component.DataRecordTransform implements transform{}”?

I don’t know if it’ll help but I can send you a copy of the java file that I’m trying to implement in the reformat component.

Thanks.

---

<div class="post-metadata">

**Author:** ![poctavian](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@poctavian](https://forum.cloverdx.com/u/poctavian)\
**Post date:** [May 1, 2012, 2:11am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/4 "2012-05-01T02:11:24Z")

</div>

Hi,

Attached is the copy of the java codes that I’m trying to implement in the reformat component.

Thanks.

- [CalculateSignature.java](https://cdn.cloverdx.com/forum/15901%5F2021f0b2842e6b867127120f8791ef84/CalculateSignature.java)

---

<div class="post-metadata">

**Author:** ![poctavian](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@poctavian](https://forum.cloverdx.com/u/poctavian)\
**Post date:** [May 2, 2012, 5:03am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/5 "2012-05-02T05:03:36Z")

</div>

Hi Jaro,

I went through your instructions again and I got it working. Thanks.

---

<div class="post-metadata">

**Author:** ![rafaelwinston23](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@rafaelwinston23](https://forum.cloverdx.com/u/rafaelwinston23)\
**Post date:** [May 7, 2012, 3:25am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/6 "2012-05-07T03:25:45Z")

</div>

thanks for sharing…

---

<div class="post-metadata">

**Author:** ![rovarellasbt](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rovarellasbt](https://forum.cloverdx.com/u/rovarellasbt)\
**Post date:** [August 11, 2016, 6:46pm UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/7 "2016-08-11T18:46:18Z")

</div>

Hello, I had a similar problem but I can’t find any information regarding which Clover classes should be used and not.

Where I can find this information (internal classes vs API classes)?

Thank you for your attention

> Hi,
> 
> your issue can be broken down into 2 parts:
> 
> 1. I believe you’re extending the CTLRecordTransform class as the base for your transformation. That class is internally used by our CTL to Java compiler, it’s not intended to be used elsewhere. You should extend the DataRecordTransform class and implement the transform() method - this will be your “main”.
> 
> 2. The specific cause of the error you’re seeing is that the sign() method throws SignatureException, and you don’t catch the exception at the location where you’re calling the method (I’m guessing that your original main had a “throws Exception” clause). You should catch the SignatureException and either re-throw it by wrapping it in a TransformException, or handle the error in some other way (e.g. send some record to a different output port for error logging).
> 
> Combining the 2 hints above should help - extend DataRecordTransform and catch the SignatureException.
> 
> Best regards,  
> Jaro
> 
> “jurban”

---

<div class="post-metadata">

**Author:** ![imriskal](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@imriskal](https://forum.cloverdx.com/u/imriskal)\
**Post date:** [August 15, 2016, 8:58am UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/8 "2016-08-15T08:58:56Z")

</div>

The most frequently used classes available are described in [CustomJavaComponent documentation](http://doc.cloveretl.com/documentation/UserGuide/index.jsp?topic=/com.cloveretl.gui.docs/docs/genericcomponent.html).

---

<div class="post-metadata">

**Author:** ![rovarellasbt](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rovarellasbt](https://forum.cloverdx.com/u/rovarellasbt)\
**Post date:** [August 22, 2016, 4:41pm UTC](https://forum.cloverdx.com/t/reformat-component-issue-in-java/1062/9 "2016-08-22T16:41:33Z")

</div>

Thank your your support!
