You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Daniel Kulp <dk...@apache.org> on 2008/07/01 22:35:50 UTC

Re: org.apache.cxf.jaxws.interceptors.SwAOutInterceptor | Unreachable Code

On Jun 24, 2008, at 4:44 PM, Manolescu, Radu (IT) wrote:

> I have entered the Jira.
>
> Adding support for byte[] is a little more tricky, in my  
> understanding,
> because we cannot know (in a general case) what the content of the
> byte[] represents.

For code first, that certainly is an issue.   But if this is a "wsdl  
first" thing, we should be able to look at the mime:content extensor  
in the wsdl to figure out what the "type" is for the named part.  
(providing there is only a single mime:content extensor there).

Dan



> In our case, because we know that the byte[] contains
> XML, I did the following:
>
> //{ Start new code //
>            } else if (o instanceof byte[]) {
>                Source source = new StreamSource(new
> ByteArrayInputStream((byte[])o));
>                dh = new DataHandler(createDataSource(source, ct));
> //} End new code //
>            } else if (dh == null) {
>                throw new Fault(new
> org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED",
>
> LOG, o.getClass()));
>
> I've put this code in a modified copy of SwAOutInterceptor; I have
> removed SwAOutInterceptor from the chain and added our copy instead.
>
> This seems to work for us, but does not solve the problem in general.
>
> To solve the problem in general, I suppose you could:
> -- add a method to SwAOutInterceptor
> public DataHandler getDataHandler(Object o)
> {
> 	throw new RuntimeException("Extend this class and override this
> method");
> }
> -- handle the byte[] as follows:
> //{ Start new code //
>            } else if (o instanceof byte[]) {
>                dh = getDataHandler(o);
> //} End new code //
> This way, the base class (SwAOutInterceptor) is still unable to handle
> byte[] properly, but at least it provides a mechanism that allows the
> user to plug in the appropriate handling of that type.
> It's quite inelegant, though.
>
>
> Radu Manolescu
> Morgan Stanley | Technology
> 2000 Westchester Ave, 1st Floor | Purchase, NY  10577
> Phone: +1 914 225-5871
> Mobile: +1 203 648-6964
> Radu.Manolescu@MorganStanley.com
>
> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org]
> Sent: Monday, June 23, 2008 9:14 PM
> To: users@cxf.apache.org
> Cc: Saveliff, James (IT)
> Subject: Re: org.apache.cxf.jaxws.interceptors.SwAOutInterceptor |
> Unreachable Code
>
>
> Yea, that looks like dead code to me as well.
>
> Feel free to log a JIRA with a patch.   It would be great if you want
> to add byte[] support as well.   :-)
>
> Dan
>
>
> On Jun 23, 2008, at 4:56 PM, Manolescu, Radu (IT) wrote:
>
>> 1. In my opinion, the code at
>> org.apache.cxf.jaxws.interceptors.SwAOutInterceptor:197 is
>> unreachable.
>> 2. Why does this interceptor support only Source/Image/DataHandler? I
>> have a byte[] as a SOAP attachment, and this throws an exception at
>> line 195.
>>
>> How can we handle a byte[] as a SOAP attachment using CXF SwA?
>>
>>
>> Examine the code fragment below to see that line 197 is unreachable:
>> On line 148, dh=null.
>> Then we test the object o for its data type, in a series of if/elseif
>> clauses.
>> There are two possibilities for the object o:
>> 1. o instanceof Source / Image / DataHandler 2. all other situations
>>
>> In situation 1, execution will enter the blocks after lines 151, or
>> 155, or 182, then continue from line 202.
>> In situation 2, execution will not enter any of the blocks after  
>> lines
>
>> 151, or 155, or 182. As a result, dh is still null when we reach line
>> 194, and a Fault is thrown.
>> Either way, execution cannot reach line 197.
>>
>> package org.apache.cxf.jaxws.interceptors;
>> public class SwAOutInterceptor extends AbstractSoapInterceptor {
>>           DataHandler dh = null; // LINE 148
>>           if (o instanceof Source) { // LINE 151
>>               dh = new DataHandler(createDataSource((Source)o, ct));
>>
>>           } else if (o instanceof Image) { // LINE 155
>>               dh = new DataHandler(new
>> ByteArrayDataSource(bos.toByteArray(), ct));
>>           } else if (o instanceof DataHandler) { // LINE 182
>>               dh = (DataHandler) o;
>>           } else if (dh == null) { // LINE 194
>>               throw new Fault(...);
>>           } else if (dh.getDataSource() instanceof URLDataSource) {
>> // <========== LINE 197: UNREACHABLE
>>               URLDataSource ds = (URLDataSource)dh.getDataSource();
>>               dh = new DataHandler(ds.getURL());
>>               ct = ds.getContentType();
>>           } // LINE 201
>>
>>
>>
>> Radu Manolescu
>> Morgan Stanley | Technology
>> 2000 Westchester Ave, 1st Floor | Purchase, NY  10577
>> Phone: +1 914 225-5871
>> Mobile: +1 203 648-6964
>> Radu.Manolescu@MorganStanley.com
>> --------------------------------------------------------
>>
>> NOTICE: If received in error, please destroy and notify sender.
>> Sender does not intend to waive confidentiality or privilege. Use of
>> this email is prohibited when received in error.
>
> ---
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender.  
> Sender does not intend to waive confidentiality or privilege. Use of  
> this email is prohibited when received in error.

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog