I'd like to run some code from an apache commons jar, specifically the sha256Hex function form org.apache.commons.codec.digest.DigestUtils. I have downloaded the appropriate jar file (commons-codec-1.10.jar) and put it in the userlib directory of my project. Next I set up a java action that contains the following code (see below). However, I still get an error in mendix runtime that it can't find the function in the jar-file:
java.lang.NoSuchMethodError: org.apache.commons.codec.digest.DigestUtils.sha256Hex
Update:
Problem was caused by the fact that I also had a commons-codec-1.3 from the CommunityCommons-project in my userlib directory. I removed that one and it works now, but I was wondering if the problem won't return if I update the CommunityCommons in my app. Anyone has any advise on that?
Java action:
import org.apache.commons.codec.digest.DigestUtils;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
public class HashProper extends CustomJavaAction<java.lang.String>
{
private java.lang.String Password;
public HashProper(IContext context, java.lang.String Password)
{
super(context);
this.Password = Password;
}
@Override
public java.lang.String executeAction() throws Exception
{
// BEGIN USER CODE
String sha256Hex = DigestUtils.sha256Hex(this.Password);
return sha256Hex;
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@Override
public java.lang.String toString()
{
return "HashProper";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}