I have a service with which I would like to upload and download files. The
uploading part goes great - I make the upload call like so:

        UploadFileType uft = new UploadFileType();
        uft.setFileName("somefilename.zip");
        uft.setData(new DataHandler(new
FileDataSource("/var/tmp/somefilename.zip")));
        service.uploadFile(uft);

then on the server I do:

                FileOutputStream fos = new FileOutputStream(new 
File("/var/tmp/" +
file.getFileName()));
                ByteArrayInputStream bis = (ByteArrayInputStream)
file.getData().getContent();

                byte[] buffer = new byte[2048];
                int bytesRead = bis.read(buffer);
                while (bytesRead >= 0) {
                        fos.write(buffer, 0, bytesRead);
                        bytesRead = bis.read(buffer);
                }
                ...

and the file is uploaded. I though that if I just copy / paste and switch
server code to client code and vice versa the download part would work too.
It does indeed work until I try to do:

        bis = (ByteArrayInputStream) file.getData().getContent();

At that line a ClassCastException is thrown for the DelegatingInputStream on
which I can find nothing. How do I handle this?

The exception that is thrown:

java.lang.ClassCastException:
org.apache.cxf.attachment.DelegatingInputStream
        at
com.tripolis.api.prototype.client.PrototypeServiceTest.testFileDownload(PrototypeServiceTest.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:232)
        at junit.framework.TestSuite.run(TestSuite.java:227)
        at
org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
        at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


-- 
View this message in context: 
http://www.nabble.com/Problem-with-attachment-retrieval-MTOM-%28CXF-2.0.4%29-tp15352705p15352705.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to