[ 
https://issues.apache.org/jira/browse/AXIS2-3538?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12606030#action_12606030
 ] 

Rod Dodl commented on AXIS2-3538:
---------------------------------

This defect is in org.apache.axis2.databinding.utils.BeanUtil. 
deserialize(Class beanClass, OMElement beanElement, ObjectSupplier 
objectSupplier, String arrayLocalName)

When this method determines that the object to be deserialized is a byte array, 
it takes beanElement.getFirstElement(). (See code below)

if (beanClass.isArray()) {
   ArrayList valueList = new ArrayList();
   Class arrayClassType = beanClass.getComponentType();
   if ("byte".equals(arrayClassType.getName())) {
      return Base64.decode(beanElement.getFirstElement().getText());
   } else {
. . . . . 

The problem with this is that the first element is not always the byte array 
that needs to be processed. 

This can be corrected by changing the code as follows. This will look for the 
correct element containing the byte array based on the parameters submitted to 
the method.

if (beanClass.isArray()) {
  ArrayList valueList = new ArrayList();
  Class arrayClassType = beanClass.getComponentType();
  if ("byte".equals(arrayClassType.getName())) {
    Iterator parts = beanElement.getChildElements();
    OMElement omElement = null;
    while (parts.hasNext()) {
        Object objValue = parts.next();
        if (objValue instanceof OMElement) {
            omElement = (OMElement)objValue;
            if (arrayLocalName.equals(omElement.getLocalName())) {
                break;
            }
        }
    }
    return Base64.decode(omElement.getText());
  } else {

This code makes sure that the correct OM element is Base64 decoded.

This works for our local project team across different test cases. I would like 
to contribute this fix back to the Axis2 project, but I can't seem to find a 
clear description of the process for submitting a patch. I have subversion 
loaded, and I have the code updated locally. If someone can point me to a 
document on where to go from here (how to document the fix, do I need to create 
a new JUnit test case or can I modify/expand an existing one, how does the 
updated code get associated with this defect, etc.) I would appreciate it.

Thanks,
Rod Dodl.



> RPCServiceClient response handling incorrect when there are multi byte[] 
> object in the return bean
> --------------------------------------------------------------------------------------------------
>
>                 Key: AXIS2-3538
>                 URL: https://issues.apache.org/jira/browse/AXIS2-3538
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Bug
>          Components: adb, rpc
>    Affects Versions: 1.3
>         Environment: WinXP, JDK 1.5
> Spring+Axis2 1.3
>            Reporter: Qiuming Bao
>            Priority: Critical
>         Attachments: pojoguidespring.zip, WeatherSpringService.aar
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> I'm using the axis2 with Spring integrated. POJO Spring  bean as service is 
> working.
> But the object returned/retrieved on the client side ( with RPCServiceClient) 
> is incorrect. 
> In the return object, there are several byte[] attributes. 
> On the client, the return object's byte[] attributes will be set with the 
> value of the first byte[] attribute. 
>  
> Following is the modified WeatherSpringService code based on axis2 bundled 
> sample. 
> /** Weather.java */
> package sample.spring.bean;
> public class Weather{
>     float temperature;
>     String forecast;
>     boolean rain;
>     float howMuchRain;
>     byte[] b1;
>     byte[] b2;
>     byte[] b3;
>     
>     public void setTemperature(float temp){
>         temperature = temp;
>     }
>     public float getTemperature(){
>         return temperature;
>     }
>     
>     public void setForecast(String fore){
>         forecast = fore;
>     }
>     public String getForecast(){
>         return forecast;
>     }
>     
>     public void setRain(boolean r){
>         rain = r;
>     }
>     public boolean getRain(){
>         return rain;
>     }
>     
>     public void setHowMuchRain(float howMuch){
>         howMuchRain = howMuch;
>     }
>     public float getHowMuchRain(){
>         return howMuchRain;
>     }
>     
>     public void setB1(byte[] b) { 
>       this.b1 = b;
>     }
>     public byte[] getB1() { 
>       return b1;
>     }
>     public void setB2(byte[] b) { 
>       this.b2 = b;
>     }
>     public byte[] getB2() { 
>       return b2;
>     }
>     public void setB3(byte[] b) { 
>       this.b3 = b;
>     }
>     public byte[] getB3() { 
>       return b3;
>     }
> }
> /** WeatherSpringRPCClient .java */
> package client;
> import javax.xml.namespace.QName;
> import org.apache.axis2.AxisFault;
> import org.apache.axis2.addressing.EndpointReference;
> import org.apache.axis2.client.Options;
> import org.apache.axis2.rpc.client.RPCServiceClient;
> import sample.spring.bean.Weather;
> public class WeatherSpringRPCClient {
>     public static void main(String[] args1) throws AxisFault {
>         RPCServiceClient serviceClient = new RPCServiceClient();
>         Options options = serviceClient.getOptions();
>         EndpointReference targetEPR 
>                 = new EndpointReference(
>                 "http://localhost:8080/axis2/services/WeatherSpringService";); 
>         
>         options.setTo(targetEPR);
>         // Get the weather (no setting, the Spring Framework has already 
> initialized it for us)
>         QName opGetWeather = new QName("http://service.spring.sample/xsd";, 
> "getWeather");
>         Object[] opGetWeatherArgs = new Object[] { };
>         Class[] returnTypes = new Class[] { Weather.class };
>         
>         
>         Object[] response = serviceClient.invokeBlocking(opGetWeather,
>                 opGetWeatherArgs, returnTypes);
>         
>         Weather result = (Weather) response[0];
>         
>         // display results
>         if (result == null) {
>             System.out.println("Weather didn't initialize!");
>         }else{
>             System.out.println("Temperature               : " +
>                                result.getTemperature());
>             System.out.println("Forecast                  : " +
>                                result.getForecast());
>             System.out.println("Rain                      : " +
>                                result.getRain());
>             System.out.println("How much rain (in inches) : " +
>                                result.getHowMuchRain());
>             System.out.println("Byte b1 : " +
>                                new String(result.getB1()));
>             System.out.println("Byte b2 : " +
>                                new String(result.getB2()));
>             System.out.println("Byte b3 : " +
>                                new String(result.getB3()));
>         }
>     }
> }
> /** WeatherSpringService */
> package sample.spring.service;
> import sample.spring.bean.Weather;
> public class WeatherSpringService{
>     Weather weather;
>     byte[] b1 = "Hello b1".getBytes();
>     byte[] b2 = "Hello b2".getBytes();
>     byte[] b3 = "Hello b3".getBytes();
>     
>     public void setWeather(Weather w){
>         weather = w;
>         w.setB1(b1);
>         w.setB2(b2);
>         w.setB3(b3);
>     }
>     public Weather getWeather(){
>         return weather;
>     }
> }
> /** The result printed out is */
> rpc.client.run:
>      [echo] F:\Software\java\axis2-1.3\samples\pojoguidespring\build.xml
>      [java] log4j:WARN No appenders could be found for logger 
> (org.apache.axis2.
> util.Loader).
>      [java] log4j:WARN Please initialize the log4j system properly.
>      [java] Temperature               : 89.9
>      [java] Forecast                  : Sunny
>      [java] Rain                      : false
>      [java] How much rain (in inches) : 0.2
>      [java] Byte b1 : Hello b1
>      [java] Byte b2 : Hello b1
>      [java] Byte b3 : Hello b1

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to