1

Application calling SOAP web services. One of the xml element is expecting data type as base64Binary like

<sessionPassword>base64Binary</sessionPassword>

1.I can read it while sax parsing like:

 setSessionPassword((new String(ch,start,length)).getBytes());

Is this correct?

2.I need to pass this password field to URI like this:

private static final String URI_BASE = "https://srini3000.com/Conversion/gateway.asmx/ASAPIDList?";   
String _sessionNum = "sessionNum=$1&";
String _sessionPaswrd = "sessionPassword=$2&sessionPassword=";

StringBuilder url = new StringBuilder(URI_BASE) ;
url.append(_sessionNum.replace("$1",Integer.toString(xmlHandler.getSessionNum())));
url.append(_sessionPaswrd.replace("$2",xmlHandler.getSessionPassword().toString()));

After making like in point2 I am facing Cannot convert [B@79be0360 to System.Byte.

Any suggestions please. FYI I am using restlet to make the uri calls. FYI XmlHandler is a pojo class, built after xml parsing. it has SessionNum, SessionPassword (declared as byte[]) fields.

albciff
  • 18,112
  • 4
  • 64
  • 89
User12377777
  • 145
  • 2
  • 20

1 Answers1

1

About your first question, depends on the bean representation of your xsd. There are some engines which internally encode\decode to base64 when set\ get method is invoked for fields of base64Binary type, but there are another ones which not perform this for you. So depends on implementation could be necessary to encode the password before invoke setSessionPassword().

About your second question, if sessionPassword is declared as follows inside your POJO:

public class yourPojo {
   private byte[] sessionPassword;
   ...
   public byte[] getSessionPassword(){
       return sessionPassword;
   }
}

Then the follow line is not working as you expect:

xmlHandler.getSessionPassword().toString()

Because byte type not override toString() method, so getSessionPassword().toString() is returning [B@79be0360 which is not the correct value (see this question to more info about default toString() behavior).

To solve your problem you've to use the follow code instead of invoke toString():

_sessionPaswrd.replace("$2",new String(xmlHandler.getSessionPassword(),"UTF-8"));

Hope it helps,

Community
  • 1
  • 1
albciff
  • 18,112
  • 4
  • 64
  • 89
  • By the way really great thought about "There are some engines which internally encode\decode to base64" cause in my case I did it "twice" on my side and then inside jax-ws impl automatically. Thanks again! – Dzmitry Hubin Aug 31 '23 at 10:46
  • 1
    nice that this explanation helps you @DzmitryHubin :) – albciff Aug 31 '23 at 10:50