EKP jd 上传附件(四) soap+xml
一. jd Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | package com.landray.kmss.gemdale.webservice; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.io.FileInputStream; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.codec.binary.Base64; import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.apache.http.entity.StringEntity; public class WebServiceTest { private static String url = "http://:8080/sys/webservice/commonWorkflowService?wsdl" ; private static String localUrl = "http://localhost:8080/sys/webservice/commonWorkflowService?wsdl" ; private static String targetNamespace = "http:///" ; public static void main(String[] args) throws IOException { ICommonWorkflowService webService = new ICommonWorkflowServiceProxy(url); // String fd_id = webService.addReview(createForm()); // System.out.println(fd_id); String result = doPostSoap(); System.out.println(result); } public static String doPostSoap() throws IOException,Exception { //为服务请求方请求服务时服务器运行时间,格式为 YYYYMMDDHHMMSS Date date = new Date(); SimpleDateFormat sf = new SimpleDateFormat( "yyyyMMddHHmmss" ); String ServiceTime = sf.format(date); //传入当前时间、 byte [] bytes = file2bytes( "F:\\" + "ceshi2.txt" ); String fileBase64 = Base64.encodeBase64String(bytes); String soapXml= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<SOAP-ENV:Envelope\n" + " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + " xmlns:web=\"http://webservice.gemdale.kmss.landray.com/\">\n" + " <SOAP-ENV:Header/>\n" + " <SOAP-ENV:Body>\n" + " <web:addReview>\n" + " <arg0>\n" + " <attachmentForms>\n" + " <fdKey>" + "fd_file" + "</fdKey>\n" + " <fdFileName>" + "ceshi2.txt" + "</fdFileName>\n" + // " <fdAttachment>"+"VGhyb3VnaCB0aGUgZGFya2VzdCBhbGxleXMgYW5kIGxvbmVsaWVzdCB2YWxsZXlz"+"</fdAttachment>\n" + " <fdAttachment>" +fileBase64+ "</fdAttachment>\n" + " </attachmentForms>\n" + " <docCreator>admin</docCreator>\n" + " <docStatus>10</docStatus>\n" + " <docSubject>" +ServiceTime+ "_add" + "</docSubject>\n" + " <fdTemplateKeyword>SGSY-XQ</fdTemplateKeyword>\n" + " </arg0>\n" + " </web:addReview>\n" + " </SOAP-ENV:Body>\n" + "</SOAP-ENV:Envelope>\n" + "" ; int socketTimeout = 10000 ; // 请求超时时间 int connectTimeout = 10000 ; // 传输超时时间 final String soap = "text/xml;charset=UTF-8" ; // 创建HttpClient HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); // 创建Post请求 HttpPost httpPost = new HttpPost(localUrl); // 设置请求和传输超时时间 RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout) .setConnectTimeout(connectTimeout).build(); httpPost.setConfig(requestConfig); // 设置Post请求报文头部 httpPost.setHeader( "Content-Type" , soap); httpPost.setHeader( "SOAPAction" , "" ); // 添加报文内容 StringEntity data = new StringEntity(soapXml, Charset.forName( "UTF-8" )); httpPost.setEntity(data); try { // 执行请求获取返回报文 CloseableHttpResponse response = closeableHttpClient.execute(httpPost); HttpEntity httpEntity = response.getEntity(); if (httpEntity != null ) { // 打印响应内容 return EntityUtils.toString(httpEntity, "UTF-8" ); } // 释放资源 closeableHttpClient.close(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null ; } /* * 创建流程文档 */ public static ReviewHandlerParamter createForm() throws IOException { ReviewHandlerParamter reviewHandlerParamter = new ReviewHandlerParamter(); // 本地环境模板 reviewHandlerParamter.setFdTemplateKeyword( "SGSY-XQ" ); SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm" ); reviewHandlerParamter.setDocSubject(df.format( new Date()) + " add 附件上传" ); reviewHandlerParamter.setDocCreator( "admin" ); AttachmentForm[] attForms = createAllAtts(); reviewHandlerParamter.setAttachmentForms(attForms); return reviewHandlerParamter; } /* * 创建附件列表 */ static AttachmentForm[] createAllAtts() throws IOException { AttachmentForm[] attForms = new AttachmentForm[ 3 ]; String fileName = "TEST1.rtf" ; AttachmentForm attForm01 = createAtt(fileName); attForms[ 0 ] = attForm01; return attForms; } /* * 创建附件对象 */ static AttachmentForm createAtt(String fileName) throws IOException { AttachmentForm attForm = new AttachmentForm(); attForm.setFdFileName(fileName); // 设置附件关键字,表单模式下为附件控件的id attForm.setFdKey( "fd_file" ); byte [] data = file2bytes( "F:\\" + "FILE-10-35-21-34-6333872054413443-1623835937850.rtf" ); attForm.setFdAttachment(data); return attForm; } /* * 将文件转换为字节编码 */ static byte [] file2bytes(String fileName) throws IOException { InputStream in = new FileInputStream(fileName); byte [] data = new byte [in.available()]; try { in.read(data); } finally { try { in.close(); } catch (IOException ex) { } } return data; } } |
二. ny Demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | package com.landray.kmss.sec.org.util; import java.io.IOException; import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.StringEscapeUtils; import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import com.alibaba.fastjson.JSONObject; import com.landray.kmss.util.StringUtil; /** * 模块基础工具类 */ public class SecOrgPushUtil{ /** * 同步HttpPost请求发送SOAP格式的消息 * * @param webServiceURL * WebService接口地址 * @param soapXml * 消息体 * @param soapAction * soapAction * @param soapType * soap版本 * @return */ static int socketTimeout = 10000 ; // 请求超时时间 static int connectTimeout = 10000 ; // 传输超时时间 static final String soap = "text/xml;charset=UTF-8" ; public static String doPostSoap(String webServiceURL, String soapXml,String soapAction) { // 创建HttpClient HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); // 创建Post请求 HttpPost httpPost = new HttpPost(webServiceURL); // 设置请求和传输超时时间 RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(socketTimeout) .setConnectTimeout(connectTimeout).build(); httpPost.setConfig(requestConfig); // 设置Post请求报文头部 httpPost.setHeader( "Content-Type" , soap); httpPost.setHeader( "SOAPAction" , soapAction); // 添加报文内容 StringEntity data = new StringEntity(soapXml, Charset.forName( "UTF-8" )); httpPost.setEntity(data); try { // 执行请求获取返回报文 CloseableHttpResponse response = closeableHttpClient.execute(httpPost); HttpEntity httpEntity = response.getEntity(); if (httpEntity != null ) { // 打印响应内容 return EntityUtils.toString(httpEntity, "UTF-8" ); } // 释放资源 closeableHttpClient.close(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null ; } //截取<Response>(.*)</Response> public static JSONObject unResponseXml(String str) { JSONObject jsonGroup = new JSONObject(); String regex = "<Response>(.*)</Response>" ; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(str); //匹配类 while (matcher.find()) { String group = matcher.group( 1 ); group = StringEscapeUtils.unescapeXml(group); if (StringUtil.isNotNull(group)) { jsonGroup = JSONObject.parseObject(group); } } return jsonGroup; } //利用List的contains方法循环遍历,重新排序,只添加一次数据,避免重复: private static List<String> removeDuplicate(List<String> list) { List<String> result = new ArrayList<String>(list.size()); for (String str : list) { if (!result.contains(str)) { result.add(str); } } list.clear(); list.addAll(result); return result; } } |
推送接口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | /** * 调用推送接口 * @param jsonAll * @param SourceSysID * @param jsonAll * @param ServiceID * @param SerialNO * @param configLink * @return */ public String pushJsonData(JSONObject jsonAll, String SourceSysID, String ServiceID, String SerialNO, String configLink) { String result = "" ; try { //为服务请求方请求服务时服务器运行时间,格式为 YYYYMMDDHHMMSS Date date = new Date(); SimpleDateFormat sf = new SimpleDateFormat( "yyyyMMddHHmmss" ); String ServiceTime = sf.format(date); //传入当前时间 String soapXml= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<SOAP-ENV:Envelope\n" + " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + " xmlns:impl=\"http://smile.web.com/webservice\">\n" + " <SOAP-ENV:Header/>\n" + " <SOAP-ENV:Body>\n" + " <impl:esbServiceOperation>\n" + " <arg0>\n" + " <Service>\n" + " <Route>\n" + " <ServiceID>" +ServiceID+ "</ServiceID>\n" + " <SerialNO>" +SerialNO+ "</SerialNO>\n" + " <ServiceTime>" +ServiceTime+ "</ServiceTime>\n" + " <SourceSysID>" +SourceSysID+ "</SourceSysID>\n" + " </Route>\n" + " <Data>\n" + " <Request>" +jsonAll+ "</Request>\n" + " <Control/>\n" + " </Data>\n" + " </Service>\n" + " </arg0>\n" + " </impl:esbServiceOperation>\n" + " </SOAP-ENV:Body>\n" + "</SOAP-ENV:Envelope>\n" + "" ; //result= doPostSoap("http://10.62.16.56:7080/ESBWS/services/RequestInPort", soapXml, "", soap); result= SecOrgPushUtil.doPostSoap(configLink, soapXml, "" ); //result= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><impl:esbServiceOperationResponse xmlns:impl=\"http://impl.webservice.eis.com/\"><return><Service><Route><ServiceID>10000000000001</ServiceID><SerialNO>202203230100000001</SerialNO><ServiceTime>20220323090756</ServiceTime><SourceSysID>0100</SourceSysID><ServiceResponse><Status>COMPLETE</Status><Code>S000M000</Code><Desc>通信正常完成</Desc></ServiceResponse></Route><Data><Request>{"sourceSysId":"0100","dataType":"40000001","data":{"f_sjzzbm_cq":"1","f_sjzzbm_xz":"1","f_zczb":"475738.99","f_clrq":"1993-08-21","f_zzzjm":"SZNYJT","f_zzyh":[{"f_bzmc":"CNY","f_yhmc":"1","f_zhmc":"zs2022","f_zhlx":"1","f_bzbm":"CNY","f_yhhh":"1234500","f_zhhm":"zs1980"}],"f_sfstdw":"1","f_tgt_sys":"","f_bmxx":[{"f_name":"信息部","f_bmcj":"01","f_code":"nyjt2022","f_bmlx":"1","f_sjbmmc":"1","f_sjbmbm":"1","f_bmjc":"XXB"}],"f_ename":"SZNYJTYSGS","f_sjzzmc_xz":"组织1","f_jyfw":"中国大陆","f_zcbzbm":"CNY","f_zzcj_cq":"1","f_code":"SE0000000","f_dqrq":"2043-08-21","f_ssywbk":"FD","f_zzjc":"深圳能源集团","f_sjzzmc_cq":"组织1","f_zzcj_xz":"01","f_gj":"CHN","f_name":"深圳能源集团股份有限公司","f_id":"17fb44b6bdfc92dcb03cb544be0a732e","f_jwzjbm":"nyjt","f_zcdz":"深圳市福田区福田街道金田路2026号能源大厦北塔楼9层、29-31层、34-41层","f_qyfr":"王平洋","f_zcbzmc":"人民币元","f_sf":"2","f_zzlx":"1","f_jthjcgbl":"20.0","f_zzxz":"1","f_tyshxydm":"91440300192241158P","f_zzzt":"1"},"msgId":"202203230100000001"}</Request><Response>{"msg":"","code":"0","data":[{"f_code":"SE0000000","f_id":"17fb44b6bdfc92dcb03cb544be0a732e","f_status":"0"}]}</Response></Data></Service></return></impl:esbServiceOperationResponse></soapenv:Body></soapenv:Envelope>"; } catch (Exception e) { e.printStackTrace(); } return result; } |
1 2 3 4 5 | <soap:Envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" > <soap:Body><ns1:addReviewResponse xmlns:ns1= "http://webservice.gemdale.kmss.landray.com/" > < return >{ "processId" : "1847b4939130dd0a06ac5e8426ba388f" , "code" : 1 , "success" : true , "message" : "流程成功启动" }</ return > </ns1:addReviewResponse> </soap:Body></soap:Envelope> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2020-11-07 XH BT