服务端声明

@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 {/*** @param wsdl   wsdl地址* @param ns     命名空间* @param method 方法名* @param params   查收列表* @param result 是否需要返回结果* @return* @throws Exception*/@SuppressWarnings("null")public synchronized static String accessService(String wsdl, String ns, String method, Map<String,String> params, String result) throws Exception {StringBuffer stringBuffer = new StringBuffer();//拼接参数for (Map.Entry<String,String> entry: params.entrySet()) {stringBuffer.append("<"+entry.getKey()+">" + entry.getValue() + "</" + entry.getKey() + ">");}String soapReponseDatea = "";//拼接SOAPStringBuffer soapRequestData = new StringBuffer("");soapRequestData.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"" + ns + "\">");//soapRequestData.append(ns);soapRequestData.append("<soapenv:Header/>");soapRequestData.append("<soapenv:Body>");soapRequestData.append("<web:" + method + ">");soapRequestData.append(stringBuffer);soapRequestData.append("</web:" + method + ">");soapRequestData.append("</soapenv:Body>" + "</soapenv:Envelope>");System.out.println("********传递参数" + soapRequestData.toString() + "****");PostMethod postMethod = new PostMethod(wsdl);//将Soap请求数据添加到postMethod中byte[] b = null;InputStream is = null;try {b = soapRequestData.toString().getBytes("utf-8");is = new ByteArrayInputStream(b, 0, b.length);RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=UTF-8");postMethod.setRequestEntity(re);HttpClient httpClient = new HttpClient();int status = httpClient.executeMethod(postMethod);if (status == 200) {soapReponseDatea = getMesage(postMethod.getResponseBodyAsString(), result);}} catch (Exception e) {e.printStackTrace();} finally {if (is == null) {is.close();}}return soapReponseDatea;}/*** 处理返回结果** @param result* @return*/private static String getMesage(String soapAttachment, String result) {if (result == null) {return null;}if (soapAttachment != null && soapAttachment.length() > 0) {int begin = soapAttachment.indexOf("<result>");begin = soapAttachment.indexOf(">", begin);int end = soapAttachment.indexOf("</result>");String str = soapAttachment.substring(begin + 1, end);str = str.replaceAll("<", "<");str = str.replaceAll(">", ">");return str;} else {return null;}}/*** 测试 用例** @param args*/public static void main(String[] args) {try {createKnwlFile();} catch (Exception e) {e.printStackTrace();}}public static String createKnwlFile() {CallKms call = new CallKms();String wsdl = "http://localhost:8088/portal/r/s?id=createKnwlFile";String ns = "http://web.software_test.apps.user.awspaas.com/";//名称空间可以在wsdl文件中获取String method = "createKnwlFile";Map<String,String> params = new HashMap<String,String>();params.put("fileName", "temp.txt");String result = "result";try {//放入文件流params.put("fileContent", Base64.encode(fileConvertToByteArray(new File("C:\\Users\\test\\Desktop\\temp.txt"))));String callResult = accessService(wsdl, ns, method, params, result);//处理成功System.out.println("-->"+callResult);return callResult;} catch (Exception e) {e.printStackTrace();}return "null";}//获取参数编码字符private static String getEncodeStr(String params) {String encode = "";try {encode = URLEncoder.encode(params, "UTF-8");} catch (UnsupportedEncodingException e) {e.printStackTrace();}return encode;}//将文件转换为二进制数组private static byte[] fileConvertToByteArray(File file) {byte[] data = null;try {FileInputStream fis = new FileInputStream(file);ByteArrayOutputStream baos = new ByteArrayOutputStream();int len;byte[] buffer = new byte[1024];while ((len = fis.read(buffer)) != -1) {baos.write(buffer, 0, len);}data = baos.toByteArray();fis.close();baos.close();} catch (Exception e) {e.printStackTrace();}return data;}}

webService接口wsdl以byte[]方式上传附件相关推荐

  1. salesforce零基础学习(八十九)使用 input type=file 以及RemoteAction方式上传附件

    在classic环境中,salesforce提供了<apex:inputFile>标签用来实现附件的上传以及内容获取.salesforce 零基础学习(二十四)解析csv格式内容中有类似的 ...

  2. Android开发中Post方式上传文件(头像之类的)

    /*** 文件上传* @param actionUrl:上传接口地址* @param files:需上传的文件集合* @return* @throws IOException*/ public sta ...

  3. SoapUI调用webservice接口,http+post方式模仿soapui调用webservice接口

    ` SoapUI调用webservice接口,http+post方式模仿soapui调用webservice接口 项目上调用一个第三方公司提的的webservice短信接口,使用了以下几种接口调用技术 ...

  4. winform的ftp方式上传

    //ftp方式上传         public static int UploadFtp(string filePath, string filename, string ftpServerIP, ...

  5. 更正:解决报告无法下载的问题-跟国家虚拟仿真实验平台对接上传附件接口遇到的问题

    开发原由: 跟国家虚拟仿真实验平台对接,需要上传报告至国家平台,虽然国家平台提供了接口详情,但在对接的过程中还是遇到了许多问题,因此记录下来. 国家虚拟仿真实验平台 更正: 上传代码做了修改.解决从国 ...

  6. dtu无线 服务器端,4G DTU将数据无线方式上传上位机软件。服务器PC端扩展功能

    原标题:4G DTU将数据无线方式上传上位机软件.服务器PC端扩展功能 方案需求 工业生产很多生产商喜欢利用颜色检测工具来完成颜色评定和分析,一定要对色灯箱和测色仪这些颜色检测分析仪器才能正确的得到颜 ...

  7. python post 上传文件_Python通过POST方式上传文件及提交参数到远程服务器

    前言 在树莓派开发过程中,因为没有公网IP,为了方便访问获取信息,有时候我们需要将树莓派获取到的一些数据或文件上传到云端服务器.这是一个比较简便的方法. Python代码 需要用到requests库, ...

  8. 淘宝店铺订单解密接口/淘宝店铺订单插旗接口/淘宝店铺订单交易接口/淘宝店铺商品上传接口/淘宝店铺订单明文接口/代码对接分享

    淘宝店铺订单解密接口/淘宝店铺订单插旗接口/淘宝店铺订单交易接口/淘宝店铺商品上传接口/淘宝店铺订单明文接口/代码对接分享: 1.公共参数 名称 类型 必须 描述 (接口代码分享交流wx1997010 ...

  9. 淘宝店铺订单交易接口/淘宝店铺商品上传接口/淘宝店铺订单解密接口/淘宝店铺订单明文接口/淘宝店铺订单插旗接口代码对接分享

    淘宝店铺订单交易接口/淘宝店铺商品上传接口/淘宝店铺订单解密接口/淘宝店铺订单明文接口/淘宝店铺订单插旗接口代码对接分享如下: 1.公共参数 名称 类型 必须 描述 (接口代码交流wx:1997010 ...

最新文章

  1. 给女友讲讲设计模式——适配器模式(JAVA实例)5
  2. android中获取版本号,如何获取Android应用程序的构建/版本号?
  3. VTK:隐藏线移除用法实战
  4. MySQL动态行转列
  5. 你真的理解事件绑定、事件冒泡和事件委托吗?
  6. leetcode - 343. 整数拆分
  7. 4-1 简单输出整数 (10分)
  8. WebKit编译小结
  9. 深入浅出JMS(三)--ActiveMQ简单的HelloWorld实例
  10. 程序员电脑屏保画面,显示时间
  11. CMakeLists写法总结
  12. ****怎么解决UBUNTU里面VIM编辑器键盘错乱问题****
  13. 智能和弦生成工具-Plugin Boutique Scaler 2 v2.3.1 WiN-MAC
  14. 安全扫描无法加载目标网站
  15. 使用SpotBugs 进行代码检查
  16. 2个相同的 stm32 can通讯不成功_CAN通讯系列--CAN通讯简介1
  17. 基于mochiweb的chatty聊天室1
  18. 安卓WebView的那些坑
  19. Win7 的安全快捷键使用技巧
  20. 00后南航大二学生自制火箭,成功发射后回收

热门文章

  1. Springboot redis多数据源过期监听案例
  2. 个人....LATEX常用数学符号
  3. 发论文时遇到的问题汇总
  4. 蓝桥 Python 大于等于n的最小完全平方数
  5. 360°全景影像优化建议
  6. 滴滴出行2017秋招编程题
  7. 一些用于聚类和分类问题的数据集
  8. Docker容器时间与宿主机不一致?3个解决方案
  9. 最长回文子串——动态规划
  10. javase基础持续更新