Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

ian tabangay
Hi. I was testing the Upload CSV in
https://demo.hotwaxmedia.com/partymgr/control/addressMatchMap to check on an
error and got this instead:

---- exception report
----------------------------------------------------------
Service invocation error
Exception: org.ofbiz.service.GenericServiceException
Message: Service target threw an unexpected exception
(java.nio.HeapByteBuffer)
---- stack trace
---------------------------------------------------------------
org.ofbiz.service.GenericServiceException: Service target threw an
unexpected exception (java.nio.HeapByteBuffer)
org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:108)
org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:54)
org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:384)
org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:213)
org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:149)
org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:334)
org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:454)
org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:281)
org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:198)
org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:78)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:255)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:595)
java.lang.ClassCastException: java.nio.HeapByteBuffer
org.ofbiz.party.party.PartyServices.importAddressMatchMapCsv(PartyServices.java:1635)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:96)
.... [snip] ....

Ian
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Jacques Le Roux
Administrator
The error I get in Ecmlipse debugger says
ClassCastException: Cannot cast java.nio.HeapByteBuffer (id=6002) to byte[]
Same problem on both Linux( Ubuntu 8.04)/Windows (XpSp3)

Seems related to
http://markmail.org/message/tdvztevawd2hc5mv

No time to look further yet. Maybe Al has an idea ?

Jacques

From: "ian tabangay" <[hidden email]>

> Hi. I was testing the Upload CSV in
> https://demo.hotwaxmedia.com/partymgr/control/addressMatchMap to check on an
> error and got this instead:
>
> ---- exception report
> ----------------------------------------------------------
> Service invocation error
> Exception: org.ofbiz.service.GenericServiceException
> Message: Service target threw an unexpected exception
> (java.nio.HeapByteBuffer)
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.service.GenericServiceException: Service target threw an
> unexpected exception (java.nio.HeapByteBuffer)
> org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:108)
> org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:54)
> org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:384)
> org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:213)
> org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:149)
> org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:334)
> org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:454)
> org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:281)
> org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:198)
> org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:78)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:255)
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
> java.lang.Thread.run(Thread.java:595)
> java.lang.ClassCastException: java.nio.HeapByteBuffer
> org.ofbiz.party.party.PartyServices.importAddressMatchMapCsv(PartyServices.java:1635)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> java.lang.reflect.Method.invoke(Method.java:585)
> org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:96)
> .... [snip] ....
>
> Ian
>
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

ian tabangay
I found the problem. Uploaded file (key as "uploadedFile") should be type
casted as ByteBuffer instead of byte[].

Ian

On Tue, Sep 30, 2008 at 4:03 AM, Jacques Le Roux <
[hidden email]> wrote:

> The error I get in Ecmlipse debugger says ClassCastException: Cannot cast
> java.nio.HeapByteBuffer (id=6002) to byte[]
> Same problem on both Linux( Ubuntu 8.04)/Windows (XpSp3)
>
> Seems related to
> http://markmail.org/message/tdvztevawd2hc5mv
>
> No time to look further yet. Maybe Al has an idea ?
>
> Jacques
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Jacques Le Roux
Administrator
Fixed in 700443. I had to encode using file.encoding system property

I'm still unsure for what this is exactly used, anyone an idea (this would help me to translate ;o) ?
BTW I don't like much the way javascript is used there : when you clic in the file name field it automatically opens the file search
dialog box. IMO this is redundant with the button at right of field and does not allow to retrieve previous file names entered and
memorized by the browser.


Jacques

From: "ian tabangay" <[hidden email]>

>I found the problem. Uploaded file (key as "uploadedFile") should be type
> casted as ByteBuffer instead of byte[].
>
> Ian
>
> On Tue, Sep 30, 2008 at 4:03 AM, Jacques Le Roux <
> [hidden email]> wrote:
>
>> The error I get in Ecmlipse debugger says ClassCastException: Cannot cast
>> java.nio.HeapByteBuffer (id=6002) to byte[]
>> Same problem on both Linux( Ubuntu 8.04)/Windows (XpSp3)
>>
>> Seems related to
>> http://markmail.org/message/tdvztevawd2hc5mv
>>
>> No time to look further yet. Maybe Al has an idea ?
>>
>> Jacques
>

Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Bilgin Ibryam
On Tue, 2008-09-30 at 15:17 +0200, Jacques Le Roux wrote:
> BTW I don't like much the way javascript is used there : when you clic
> in the file name field it automatically opens the file search
> dialog box.

Me neither.
Bilgin

Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException:java.nio.HeapByteBuffe

Jacques Le Roux
Administrator
Thanks Bilgin,

I will change that

Jacques

From: "Bilgin Ibryam" <[hidden email]>
> On Tue, 2008-09-30 at 15:17 +0200, Jacques Le Roux wrote:
>> BTW I don't like much the way javascript is used there : when you clic
>> in the file name field it automatically opens the file search
>> dialog box.
>
> Me neither.
> Bilgin
>
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException:java.nio.HeapByteBuffe

Jacques Le Roux
Administrator
I was presumptuous. This does depend of the browser.

FF3 : show an input field with a button, clicking in field is the same as clicking the button
IE7 and Opera 9.02 :  show an input field with a button, clicking in field does nothing and anyway both do not keep an history of
selected files so it's useless.
Chrome and Safari (hey, it works on Windows too now) : show only a button, and an information on the selected file name at right

So far the best impementations seems to be Chrome and Safari

I found this (I used to test) http://www.quirksmode.org/dom/inputfile.html
And I gave up...

Actually, my memory misleaded me. I was remembering how works "Working with data files" in Webtools.
It's another way of dealing with file upload. I guess in the Adress Match Map case it's ok how it's done now.

Jacques

From: "Jacques Le Roux" <[hidden email]>

> Thanks Bilgin,
>
> I will change that
>
> Jacques
>
> From: "Bilgin Ibryam" <[hidden email]>
>> On Tue, 2008-09-30 at 15:17 +0200, Jacques Le Roux wrote:
>>> BTW I don't like much the way javascript is used there : when you clic
>>> in the file name field it automatically opens the file search dialog box.
>>
>> Me neither.
>> Bilgin
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException:java.nio.HeapByteBuffe

BJ Freeman
unless I missed something on this thread,
you can use the html upload also that is what I use.
you have a field and a button.
         <form name="ImportSupplierInventory"method="post"
enctype="multipart/form-data"
action="<@ofbizUrl>ImportSupplierInventoryxls</@ofbizUrl>"
style="margin: 0;">
           <tr>
             <td colspan="5" align="center">
               <input type="file" name="ImportSupplierInventoryFile"
size="14" value="Productsimports.xls" class="inputBox"/>
               <input type="submit" value="${uiLabelMap.CommonUpload}
supplierinventory.xls" class="smallSubmit"/>
               <div
class="tabletext">${uiLabelMap.ImportSupplierInventory1}</span>
             </td>
           </tr>
         </form>


Jacques Le Roux wrote:

> I was presumptuous. This does depend of the browser.
>
> FF3 : show an input field with a button, clicking in field is the same
> as clicking the button
> IE7 and Opera 9.02 :  show an input field with a button, clicking in
> field does nothing and anyway both do not keep an history of selected
> files so it's useless.
> Chrome and Safari (hey, it works on Windows too now) : show only a
> button, and an information on the selected file name at right
>
> So far the best impementations seems to be Chrome and Safari
>
> I found this (I used to test) http://www.quirksmode.org/dom/inputfile.html
> And I gave up...
>
> Actually, my memory misleaded me. I was remembering how works "Working
> with data files" in Webtools. It's another way of dealing with file
> upload. I guess in the Adress Match Map case it's ok how it's done now.
>
> Jacques
>
> From: "Jacques Le Roux" <[hidden email]>
>> Thanks Bilgin,
>>
>> I will change that
>>
>> Jacques
>>
>> From: "Bilgin Ibryam" <[hidden email]>
>>> On Tue, 2008-09-30 at 15:17 +0200, Jacques Le Roux wrote:
>>>> BTW I don't like much the way javascript is used there : when you clic
>>>> in the file name field it automatically opens the file search dialog
>>>> box.
>>>
>>> Me neither.
>>> Bilgin
>>>
>>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException:java.nio.HeapByteBuffe

Jacques Le Roux
Administrator
Yes it's the same. See importAddressMatchMapCsv in addressMatchMap.ftl
Actually there is no specific javascript there too

Jacques

From: <[hidden email]>

> unless I missed something on this thread,
> you can use the html upload also that is what I use.
> you have a field and a button.
>         <form name="ImportSupplierInventory"method="post"
> enctype="multipart/form-data"
> action="<@ofbizUrl>ImportSupplierInventoryxls</@ofbizUrl>"
> style="margin: 0;">
>           <tr>
>             <td colspan="5" align="center">
>               <input type="file" name="ImportSupplierInventoryFile"
> size="14" value="Productsimports.xls" class="inputBox"/>
>               <input type="submit" value="${uiLabelMap.CommonUpload}
> supplierinventory.xls" class="smallSubmit"/>
>               <div
> class="tabletext">${uiLabelMap.ImportSupplierInventory1}</span>
>             </td>
>           </tr>
>         </form>
>
>
> Jacques Le Roux wrote:
>> I was presumptuous. This does depend of the browser.
>>
>> FF3 : show an input field with a button, clicking in field is the same
>> as clicking the button
>> IE7 and Opera 9.02 :  show an input field with a button, clicking in
>> field does nothing and anyway both do not keep an history of selected
>> files so it's useless.
>> Chrome and Safari (hey, it works on Windows too now) : show only a
>> button, and an information on the selected file name at right
>>
>> So far the best impementations seems to be Chrome and Safari
>>
>> I found this (I used to test) http://www.quirksmode.org/dom/inputfile.html
>> And I gave up...
>>
>> Actually, my memory misleaded me. I was remembering how works "Working
>> with data files" in Webtools. It's another way of dealing with file
>> upload. I guess in the Adress Match Map case it's ok how it's done now.
>>
>> Jacques
>>
>> From: "Jacques Le Roux" <[hidden email]>
>>> Thanks Bilgin,
>>>
>>> I will change that
>>>
>>> Jacques
>>>
>>> From: "Bilgin Ibryam" <[hidden email]>
>>>> On Tue, 2008-09-30 at 15:17 +0200, Jacques Le Roux wrote:
>>>>> BTW I don't like much the way javascript is used there : when you clic
>>>>> in the file name field it automatically opens the file search dialog
>>>>> box.
>>>>
>>>> Me neither.
>>>> Bilgin
>>>>
>>>
>>
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Nandani
In reply to this post by ian tabangay
Hello All,


Similar problem occurred while creating Product Promo, when we upload file for Promo Code Emails then  ERROR: java.lang.ClassCastException: java.nio.HeapByteBuffer occurs.
This file contains list of EmailIds.

This error can be resolved by using following code snippet in file "PromoServices.java" and function 'importPromoCodeEmailsFromFile".
Promo Code Emails
Reason of error :  byte[] wrapper = (byte[]) context.get("uploadedFile"); (Line number : 239)

This line can be replaced by :
ByteBuffer bytebufferwrapper = (ByteBuffer) context.get("uploadedFile");
   
        if (bytebufferwrapper == null) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource,
                    "ProductPromoCodeImportUploadedFileNotValid", locale));
        }

        byte[] wrapper =  bytebufferwrapper.array();


Hope , then this error will not occur and file can be uploaded successfully.

Please revert back in case anything wrong or missing.

Regards
Nandani
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Jacques Le Roux
Administrator
Sounds good, but you should rather contribute following
https://cwiki.apache.org/confluence/display/OFBADMIN/OFBiz+Contributors+Best+Practices
Explain there what you tried to do (with steps and elements) and what happened. And attach a patch

It will be then easier to us (commiters) to review and test and if correct to commit in trunk and maybe releases branches

Thanks

Jacques

From: "Nandani" <[hidden email]>

> Hello All,
>
>
> Similar problem occurred while creating Product Promo, when we upload file
> for Promo Code Emails then  ERROR: java.lang.ClassCastException:
> java.nio.HeapByteBuffer occurs.
> This file contains list of EmailIds.
>
> This error can be resolved by using following code snippet in file
> "PromoServices.java" and function 'importPromoCodeEmailsFromFile".
> Promo Code Emails
> Reason of error :  byte[] wrapper = (byte[]) context.get("uploadedFile");
> (Line number : 239)
>
> This line can be replaced by :
> ByteBuffer bytebufferwrapper = (ByteBuffer) context.get("uploadedFile");
>
>        if (bytebufferwrapper == null) {
>            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource,
>                    "ProductPromoCodeImportUploadedFileNotValid", locale));
>        }
>
>        byte[] wrapper =  bytebufferwrapper.array();
>
>
> Hope , then this error will not occur and file can be uploaded successfully.
>
> Please revert back in case anything wrong or missing.
>
> Regards
> Nandani
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Upload-CSV-throws-java-lang-ClassCastException-java-nio-HeapByteBuffe-tp155781p4632767.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe

Nandani
Hello Jacques ,

Thanks for your precious Guidance.I have created Jira Issue : OFBIZ-4919 and have attached screenshot and required Patch.

Regards
Nandani Aggarwal.

On Sat, Jun 2, 2012 at 3:48 PM, Jacques Le Roux [via OFBiz] <[hidden email]> wrote:
Sounds good, but you should rather contribute following
https://cwiki.apache.org/confluence/display/OFBADMIN/OFBiz+Contributors+Best+Practices
Explain there what you tried to do (with steps and elements) and what happened. And attach a patch

It will be then easier to us (commiters) to review and test and if correct to commit in trunk and maybe releases branches

Thanks

Jacques

From: "Nandani" <[hidden email]>

> Hello All,
>
>
> Similar problem occurred while creating Product Promo, when we upload file
> for Promo Code Emails then  ERROR: java.lang.ClassCastException:
> java.nio.HeapByteBuffer occurs.
> This file contains list of EmailIds.
>
> This error can be resolved by using following code snippet in file
> "PromoServices.java" and function 'importPromoCodeEmailsFromFile".
> Promo Code Emails
> Reason of error :  byte[] wrapper = (byte[]) context.get("uploadedFile");
> (Line number : 239)
>
> This line can be replaced by :
> ByteBuffer bytebufferwrapper = (ByteBuffer) context.get("uploadedFile");
>
>        if (bytebufferwrapper == null) {
>            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource,
>                    "ProductPromoCodeImportUploadedFileNotValid", locale));
>        }
>
>        byte[] wrapper =  bytebufferwrapper.array();
>
>
> Hope , then this error will not occur and file can be uploaded successfully.
>
> Please revert back in case anything wrong or missing.
>
> Regards
> Nandani
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Upload-CSV-throws-java-lang-ClassCastException-java-nio-HeapByteBuffe-tp155781p4632767.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.



To unsubscribe from Upload CSV throws java.lang.ClassCastException: java.nio.HeapByteBuffe, click here.
NAML