Try
JavaCast("byte", "#sigData.signature#")
Or
sigData.signature.toByteArray()
Brook
-----Original Message-----
From: Phil Stone [mailto:[email protected]]
Sent: April-28-11 2:28 PM
To: cf-talk
Subject: javacast to byte[] not working
Hello,
In a cfc, I'm calling a Java method which returns, among other things, a
primitive byte array (i.e. sigObject.getSignature(), below, returns a
byte[]). I'm putting this byte array,along with the other things, into a CF
struct, and returning that struct:
<cffunction name="sign" output="false" access="remote"
returntype="struct">
<cfargument name="text_to_sign" type="string"
required="true" default="">
<cfargument name="signer" type="string" required="true"
default="">
<cfset j_document = JavaCast("String", "#text_to_sign#")>
<cfset j_signer = JavaCast("String", "#signer#")>
<cfset sigObject =
createObject( "java", "foo.bar" )
.init(j_signer, 0, 0) >
<cfset null = sigObject.sign(j_document, j_signer)>
<cfset sigData=StructNew()>
<cfset
sigData.requestedSigner=sigObject.getRequestedSigner()>
<cfset sigData.documentId=sigObject.getDocumentId()>
<cfset sigData.documentType=sigObject.getDocumentType()>
<cfset sigData.recordId=sigObject.getRecordId()>
<cfset sigData.signer=sigObject.getSigner()>
<cfset sigData.signedDate=sigObject.getSigningDate()>
<cfset sigData.digestType=sigObject.getDigestType()>
<cfset sigData.signature=sigObject.getSignature()>
<cfset sigData.issigned=sigObject.isSigned()>
<cfreturn sigData />
</cffunction>
All is well here. I stuff the returned struct into a session variable. On a
subsequent action, I pass that struct back to the following method; in this
method, I try to javacast the byte array stored in the struct to make
another Java call with it:
<cffunction name="validate" output="false" access="remote"
returntype="boolean">
<cfargument name="sigData" type="struct" required="true">
<cfargument name="text_to_validate" type="string"
required="true" default="">
<cfargument name="requestedSigner" type="string"
required="true" default="">
<cfset j_documentId = JavaCast("int",
"#sigData.documentId#") >
<cfset j_documentType = JavaCast("int",
"#sigData.documentType#") >
<cfset j_recordId = JavaCast("int", "#sigData.recordId#") >
<cfset j_requestedSigner = JavaCast("String",
"#requestedSigner#") >
<cfset j_signed = JavaCast("boolean", "#sigData.issigned#")
>
<cfset j_signer = JavaCast("String", "#sigData.signer#") >
<cfset j_signingDate = JavaCast("long",
"#sigData.signedDate#") >
<cfset j_digestType = JavaCast("String",
"#sigData.digestType#") >
<!--- HERE IS THE RELEVANT LINE: --->
<cfset j_signature = JavaCast("byte[]",
"#sigData.signature#") >
<!--- --->
<cfset j_text_to_validate = JavaCast("String",
"#text_to_validate#")>
<cfset sigObject =
createObject( "java", "foo.bar" )
.init(j_documentId, j_documentType,
j_recordId, j_requestedSigner, j_signed,
j_signer, j_signingDate,
j_digestType, j_signature) >
<cfset isValid = sigObject.isValid(j_text_to_validate)>
<cfreturn isValid>
</cffunction>
I get this error:
JavaCast type byte[] must be one of the following types: byte, char, short,
int, long, float, double, boolean, string, bigdecimal, their corresponding
array representation (eg : int[]), or null.
First of all, why is the error message complaining that "type byte[] must be
one of the following" and one of the following (by clear inference) is
"byte[]"?
Secondly, why is the javacast failing? I'm clearly passing a valid byte
array to javacast.
Any ideas would be greatly appreciated.
Phil
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:344038
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm