axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Florian Roks <florian.r...@wilken.de>
Subject Bug: byte-Arrays (byte[]) as Parameter in JAXWS-Webservice
Date Thu, 27 Aug 2009 12:38:42 GMT
Hi,

When using byte[] as a parameter in a JAXWS-Style Webservice - example 
method-definition follows:

   @WebMethod(action = "addDocument")
   public void addDocument(
           @WebParam(name="docId") String docId,
           @WebParam(name="documentData") byte[] documentData) throws 
DocumentServiceFault;

The array received by the client has the length 0.

I traced the problem back to 
org.apache.axis2.datasource.jaxb.JAXBDSContext's unmarshalArray(final 
XMLStreamReader reader, final Unmarshaller u, Class type)-Method, which 
tries to convert every Array-Object to a String-Array using the jaxb 
(version 2.1.7) unmarshaller.

This fails with byte-Arrays and returns a zero-byte String-Arrays, which 
leads to a call in the service, that has a zero-length byte-array, 
independent of what the client really sent.

I did a quick hack to make it work by changing the method to:

private static Object unmarshalArray(final XMLStreamReader reader, final 
Unmarshaller u, final Class type) throws Exception {
   try {
     if (DEBUG_ENABLED) {
       log.debug("Invoking unmarshalArray");
     }
     Object jaxb = AccessController.doPrivileged(new PrivilegedAction() {
       public Object run() {
         try {
           if(type == byte[].class)
             return u.unmarshal(reader, byte[].class);
           return u.unmarshal(reader, String[].class);
         } catch (OMException e) {
           throw e;
         } catch (Throwable t) {
           throw new OMException(t);
         }
       }
     });

     Object typeObj = getTypeEnabledObject(jaxb);

     // Now convert String Array in to the required Type Array.
     if (typeObj instanceof String[]) {
       String[] strArray = (String[]) typeObj;
       Object obj = XSDListUtils.fromStringArray(strArray, type);
       QName qName =
         XMLRootElementUtil.getXmlRootElementQNameFromObject(jaxb);
       jaxb = new JAXBElement(qName, type, obj);
     } else {
       QName qName =
         XMLRootElementUtil.getXmlRootElementQNameFromObject(jaxb);
       jaxb = new JAXBElement(qName, type, typeObj);
     }

     return jaxb;
   } catch (OMException e) {
     throw e;
   } catch (Throwable t) {
     throw new OMException(t);
   }
}


I hope this issue gets fixed somehow in future versions (Tested on Axis2 
1.5).

Greetings,
Florian

Mime
View raw message