Author: jleroux
Date: Wed Dec 14 09:19:05 2011 New Revision: 1214125 URL: http://svn.apache.org/viewvc?rev=1214125&view=rev Log: "Applied fix from trunk for revision: 1214124" ------------------------------------------------------------------------ r1214124 | jleroux | 2011-12-14 10:18:04 +0100 (mer., 14 déc. 2011) | 11 lines A patch from Wai https://issues.apache.org/jira/browse/OFBIZ-4620 "fail uploading audio/video files to database" When uploading binary files (eg. image/audio/video) to the database, ofbiz throws a type casting exception because it is trying to type cast HeapByteBuffer to byte[]. I think the problem stems from configuring ofbiz to use java.nio.ByteBuffer and its subclass java.nio.HeapByteBuffer to contain uploaded binary data but no accommodation is made in the code to work with this type of object. To test this, you need to set content.properties/content.upload.always.local.file=false an use partymgr/control/viewprofile?partyId=admin and upload an image file. java.nio.HeapByteBuffer comes from java's rt.jar (make sure your classpath includes this) ------------------------------------------------------------------------ Modified: ofbiz/branches/release11.04/ (props changed) ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/JdbcValueHandler.java Propchange: ofbiz/branches/release11.04/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Dec 14 09:19:05 2011 @@ -2,4 +2,4 @@ /ofbiz/branches/dojo1.4:951708-952957 /ofbiz/branches/jquery:952958-1044489 /ofbiz/branches/multitenant20100310:921280-927264 -/ofbiz/trunk:1100197,1100880,1104423,1131144,1131396,1132496,1132749,1133353,1134990,1135199,1135686,1135929,1137201,1137433,1137435,1138463,1138485,1139346,1139385,1139504,1139521,1140358,1140362,1140375,1140469,1144537,1144791,1153073,1153768,1158124,1158126,1158608,1159080,1163036,1163093,1163533,1165130,1166591,1167116,1167314,1167480,1167501,1167510,1167517,1167606,1172213,1172243,1174964,1175130,1175135,1175143,1177128,1178175,1178199,1180398,1181878,1182259,1182310,1182731,1182858,1183651,1184906,1184996,1184999,1185179,1187515,1187528,1187933,1187944,1188042,1188564,1189592,1189601,1190134,1194958,1196778,1199276,1199450,1200207,1201110,1201125,1201941,1203350,1203776,1206507,1206690,1208335,1209250,1209362,1210193,1210211,1212147 +/ofbiz/trunk:1100197,1100880,1104423,1131144,1131396,1132496,1132749,1133353,1134990,1135199,1135686,1135929,1137201,1137433,1137435,1138463,1138485,1139346,1139385,1139504,1139521,1140358,1140362,1140375,1140469,1144537,1144791,1153073,1153768,1158124,1158126,1158608,1159080,1163036,1163093,1163533,1165130,1166591,1167116,1167314,1167480,1167501,1167510,1167517,1167606,1172213,1172243,1174964,1175130,1175135,1175143,1177128,1178175,1178199,1180398,1181878,1182259,1182310,1182731,1182858,1183651,1184906,1184996,1184999,1185179,1187515,1187528,1187933,1187944,1188042,1188564,1189592,1189601,1190134,1194958,1196778,1199276,1199450,1200207,1201110,1201125,1201941,1203350,1203776,1206507,1206690,1208335,1209250,1209362,1210193,1210211,1212147,1214124 Modified: ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/JdbcValueHandler.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/JdbcValueHandler.java?rev=1214125&r1=1214124&r2=1214125&view=diff ============================================================================== --- ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/JdbcValueHandler.java (original) +++ ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/JdbcValueHandler.java Wed Dec 14 09:19:05 2011 @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Reader; +import java.nio.ByteBuffer; import java.sql.Blob; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -324,16 +325,20 @@ public abstract class JdbcValueHandler<T } @Override protected void castAndSetValue(PreparedStatement ps, int parameterIndex, Object obj) throws SQLException { - try { - // FIXME: This is here for backwards compatibility. Client code - // that uses a Blob java-type for a byte array should use a - // byte[] java-type instead. - byte[] bytes = (byte[]) obj; - Debug.logWarning("Blob java-type used for byte array. Use byte[] java-type instead.", module); - ps.setBytes(parameterIndex, bytes); - return; - } catch (ClassCastException e) {} - ps.setBlob(parameterIndex, (Blob) obj); + // FIXME: This is here for backwards compatibility. Client code + // that uses a Blob java-type for a byte array should use a + // byte[] java-type instead. + if (obj instanceof Blob) { + ps.setBlob(parameterIndex, (Blob)obj); + } else if (obj instanceof byte[]) { + ps.setBytes(parameterIndex, (byte[]) obj); + } else if (obj instanceof ByteBuffer) { + ps.setBytes(parameterIndex, ((ByteBuffer)obj).array()); + } else { + Debug.logError("JdbcValueHandler.castAndSetValue(): Unexpected type found. type=" + obj.getClass().getName(), module); + throw new IllegalArgumentException(obj.getClass().getName()); + } + return; } @Override public Object getValue(ResultSet rs, int columnIndex) throws SQLException { |
Free forum by Nabble | Edit this page |