Here is my code from my service endpoint for getting the DataHandler:
/**
     * Gets a byte array from a <code>DataHandler</code>.
     * 
     * @param dataHandler
     *            Contains the content from which the byte array is created.
     * @return byte array.
     */
    private byte[] getByteArray(DataHandler dataHandler) {
        byte[] bytes = null;
        try {
            if (dataHandler.getContent() == null) {
                throw new ValidationException("DataHandler content is
null.");
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("DataHandler content type: " +
dataHandler.getContentType());
                LOGGER.debug("DataHandler content Class name: " +
dataHandler.getContent().getClass().getSimpleName());
                if (dataHandler.getContent() instanceof
org.apache.cxf.attachment.DelegatingInputStream) {
                    LOGGER.debug("DataHandler content type is
org.apache.cxf.attachment.DelegatingInputStream.");
                }
                if (dataHandler.getContent() instanceof
org.apache.cxf.io.DelegatingInputStream) {
                    LOGGER.debug("DataHandler content type is
org.apache.cxf.io.DelegatingInputStream.");
                }
            }

            int offset = 0;
            int numRead = 0;
            if (dataHandler.getContent() instanceof InputStream) {
                LOGGER.debug("DataHandler content type is InputStream.");

                InputStream inputStream = (InputStream)
dataHandler.getContent();
                if (inputStream == null) {
                    throw new ValidationException("DataHandler InputStream
is null.");
                }

                long length = inputStream.available();
                LOGGER.debug("The length of inputStream.available(): " +
length);

                validateByteArrayLength(length);

                bytes = new byte[(int) length];
                while (offset < bytes.length && (numRead =
inputStream.read(bytes, offset, bytes.length - offset)) >= 0) {
                    offset += numRead;
                }
                inputStream.close();

                if (offset < bytes.length) {
                    throw new IOException("Could not completely read input
stream.");
                }
            } else if (dataHandler.getContent() instanceof byte[]) {
                LOGGER.debug("DataHandler content type is byte[].");
                // If a byte array was passed
                bytes = (byte[]) dataHandler.getContent();
            } else {
                String msg = "Expected instance of InputStream or byte array
but received "
                        +
dataHandler.getContent().getClass().getSimpleName();
                LOGGER.error(msg);
                throw new ValidationException(msg);
            }

        } catch (IOException e) {
            throw new ValidationException("Error getting byte array from
content: " + e);
        }
        return bytes;
    }



/**
     * Validates the byte array length. Throws validation exception if input
stream is too large (greater than integer
     * maximum length or is empty).
     * 
     * @param length
     *            of byte array.
     * @throws IOException
     *             Throws IOException if the input stream is empty.
     */
    private void validateByteArrayLength(long length) throws IOException {
        String msg;
        if (length > Integer.MAX_VALUE) {
            msg = "Input stream is too large to create byte array: " +
length;
            LOGGER.error(msg);
            throw new ValidationException(msg);
        } else if (length < 1) {
            msg = "Input stream is empty. Length: " + length;
            LOGGER.error(msg);
            throw new IOException(msg);
        }
        LOGGER.debug("Input stream is a valid length: " + length);
    }


Here is the message:
15609 [main] WARN com.foo.soa.frmwk.codes.CodeXmlLoader -
CodeXmlLoader.loadAll loaded objects:3
Feb 11, 2011 10:47:25 AM org.apache.cxf.phase.PhaseInterceptorChain
doDefaultLogging
WARNING: Interceptor for
{http://foo.com/services/dms}WebDocMgmtAccessServiceService#{http://foo.com/services/dms}submitDocument
has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not write attachments.
        at
org.apache.cxf.interceptor.AttachmentOutInterceptor$AttachmentOutEndingInterceptor.handleMessage(AttachmentOutInterceptor.java:98)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
        at $Proxy74.submitDocument(Unknown Source)
        at
com.foo.ws.clientproxy.WSWebDocMgmtAccessServiceProxy.invokeWebService(WSWebDocMgmtAccessServiceProxy.java:75)
        at
com.foo.ws.proxy.base.WsProxyServiceTemplate.getResponseObject(WsProxyServiceTemplate.java:89)
        at
com.foo.ws.clientproxy.WSWebDocMgmtAccessServiceProxyTest.testWsToobject(WSWebDocMgmtAccessServiceProxyTest.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
        at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
        at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
        at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
        at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for
MIME type application/octet-stream
        at 
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
        at javax.activation.DataHandler.writeTo(DataHandler.java:302)
        at
org.apache.cxf.attachment.AttachmentSerializer.writeAttachments(AttachmentSerializer.java:234)
        at
org.apache.cxf.interceptor.AttachmentOutInterceptor$AttachmentOutEndingInterceptor.handleMessage(AttachmentOutInterceptor.java:96)
        ... 43 more
javax.xml.ws.WebServiceException: Could not write attachments.
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
        at $Proxy74.submitDocument(Unknown Source)
        at
com.foo.ws.clientproxy.WSWebDocMgmtAccessServiceProxy.invokeWebService(WSWebDocMgmtAccessServiceProxy.java:75)
        at
com.foo.ws.proxy.base.WsProxyServiceTemplate.getResponseObject(WsProxyServiceTemplate.java:89)
        at
com.foo.ws.clientproxy.WSWebDocMgmtAccessServiceProxyTest.testWsToobject(WSWebDocMgmtAccessServiceProxyTest.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
        at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
        at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
        at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
        at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for
MIME type application/octet-stream
        at 
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
        at javax.activation.DataHandler.writeTo(DataHandler.java:302)
 trx null
        at
org.apache.cxf.attachment.AttachmentSerializer.writeAttachments(AttachmentSerializer.java:234)
        at
org.apache.cxf.interceptor.AttachmentOutInterceptor$AttachmentOutEndingInterceptor.handleMessage(AttachmentOutInterceptor.java:96)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
        ... 37 more

Hope this helps....my associate also sent me this:
- One of the debug statements was to find out if it was using
org.apache.cxf.io or org.apache.cxf.attachment.DelegatingInputStream.
- I'm trying to cast this to an InputStream and I think this is not
working...
- If I set an io.DelegatingInputStream with data (as in the JUnit test) it
works.
- The attachment one isn't working.

Thanks...hope the additional information helps...jay
-- 
View this message in context: 
http://cxf.547215.n5.nabble.com/DataHandler-MTOM-as-inline-vs-attachment-tp3382153p3382174.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to