简体   繁体   English

SOAP Web服务中的base64Binary

[英]base64Binary in soap web service

Application calling SOAP web services. 应用程序调用SOAP Web服务。 One of the xml element is expecting data type as base64Binary like xml元素之一期望数据类型为base64Binary

<sessionPassword>base64Binary</sessionPassword>

1.I can read it while sax parsing like: 1.我可以在解析时像下面这样阅读:

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

Is this correct? 这个对吗?

2.I need to pass this password field to URI like this: 2.我需要将此密码字段传递给URI,如下所示:

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. 像在point2中一样,我面临无法将[B @ 79be0360转换为System.Byte。

Any suggestions please. 有任何建议请。 FYI I am using restlet to make the uri calls. 仅供参考,我正在使用restlet来拨打uri电话。 FYI XmlHandler is a pojo class, built after xml parsing. FYI XmlHandler是一个pojo类,是在xml解析之后构建的。 it has SessionNum , SessionPassword (declared as byte[] ) fields. 它具有SessionNumSessionPassword (声明为byte[] )字段。

About your first question, depends on the bean representation of your xsd . 关于第一个问题,取决于xsd的bean表示形式。 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. 当为base64Binary类型的字段调用set \\ get方法时,有些引擎会内部对\\ base64进行编码\\解码,但是还有一些引擎无法为您执行此操作。 So depends on implementation could be necessary to encode the password before invoke setSessionPassword() . 因此,取决于实现可能需要在调用setSessionPassword()之前对password进行编码。

About your second question, if sessionPassword is declared as follows inside your POJO : 关于第二个问题,如果您的POJO中的 sessionPassword声明如下:

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). 因为byte类型没有覆盖toString()方法,所以getSessionPassword().toString()返回的不是正确值[B@79be0360 (有关默认toString()行为的更多信息,请参见此问题 )。

To solve your problem you've to use the follow code instead of invoke toString() : 为了解决您的问题,您必须使用以下代码而不是调用toString()

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

Hope it helps, 希望能帮助到你,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM