webService接口wsdl以byte[]方式上传附件

本文介绍如何在WebService接口中以byte[]类型处理附件上传,通过SoupUI进行测试和发布,确保服务端正确实现。
摘要由CSDN通过智能技术生成

服务端声明

@WebService(serviceName = "CreateKnwlFileService")
public class CreateKnwlFile {
   
    /* 接口声明 */
    @WebMethod(operationName = "createKnwlFile")
    public  @WebResult(name="result")String createKnwlFile2(@WebParam(name="fileContent")String fileContent,
        @WebParam(name = "fileName") String fileName) {
   
        	 try {
   
        	    //测试:将收到的文件内容转换写入临时文件查看
	            byte[] bytes = Base64.decode(fileContent);
	            String path = "C:\\Users\\test\\Desktop\\206\\";
	            FileOutputStream out = new FileOutputStream(path+fileName);
	            out.write(bytes);
	            out.flush();
	            out.close();

			  //将收到的文件内容重新转换为输入流
//            byte[] bytes = Base64.decode(fileContent);
//            new ByteArrayInputStream(bytes);
        } catch (Exception e) {
   
            e.printStackTrace();
        }
        }
}

使用soupui发布后如图:
在这里插入图片描述
PostMethod 测试


import jpack.util.Base64;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;

import java.io.*;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;


/**
 * SOAP客户端工具类
 * @author Administrator
 *
 */
public class CallKms 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值