加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webService客户端参数为DataHandler类型时候的参数组装

发布时间:2020-12-16 23:43:13 所属栏目:安全 来源:网络整理
导读:一般我们webservice的方法参数或返回值为byte类型的时候,在生成的客户端代码里的参数却是DataHandler,为此我纠结了好久。网上查的全是什么图片上传,其实我就想传递一个简单的字符串的字节码,跟什么文件上传屁兜不打岔。最后我弄出来了。上代码,以便以后

一般我们webservice的方法参数或返回值为byte类型的时候,在生成的客户端代码里的参数却是DataHandler,为此我纠结了好久。网上查的全是什么图片上传,其实我就想传递一个简单的字符串的字节码,跟什么文件上传屁兜不打岔。最后我弄出来了。上代码,以便以后使用。

package com.imp;


import java.io.ByteArrayInputStream;

import java.io.InputStream;

import java.io.OutputStream;


import javax.activation.DataHandler;

import javax.activation.DataSource;


public class TestMain {


public static void main(String[] args) throws Exception {

// TODO Auto-generated method stub

HelloDaoImpStub stub =new HelloDaoImpStub();

Say say =new Say();

String s="23323232";

byte[] b= s.getBytes();

say.setB(createDataHandler(b)); ?

SayResponse response = stub.say(say);

DataHandler result = response.get_return();

System.out.println(result.getName());

}

public static DataHandler createDataHandler(final byte[] b) {

return new DataHandler(new DataSource() {

? ? ? ? ? ?public InputStream getInputStream() { ?

? ? ? ? ? ? ? ?return new ByteArrayInputStream(b); ?

? ? ? ? ? ?} ?

? ? ? ? ? ?public OutputStream getOutputStream() { ?

? ? ? ? ? ? ? ?return null; ?

? ? ? ? ? ?} ?

? ? ? ? ? ?public String getContentType() { ?

? ? ? ? ? ? ? ?return ""; ?

? ? ? ? ? ?} ?

? ? ? ? ? ?public String getName() { ?

? ? ? ? ? ? ? ?return ""; ?

? ? ? ? ? ?}

});

}


}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读