1.SOAP请求报文 Request
POST /services/WorkflowService HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.4 Host: 127.0.0.1:8888 Cache-Control: no-cache Pragma: no-cache SOAPAction: "urn:weaver.workflow.webservices.WorkflowService.doCreateWorkflowRequest" Content-Length: 1425 <?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <doCreateWorkflowRequest xmlns="webservices.services.weaver.com.cn"> <in0> <!--流程创建人用户ID--> <ns1:creatorId xmlns:ns1="http://webservices.workflow.weaver">8</ns1:creatorId> <!--紧急程度 0 正常,1重要,2紧急--> <ns2:requestLevel xmlns:ns2="http://webservices.workflow.weaver">2</ns2:requestLevel> <!--流程标题--> <ns3:requestName xmlns:ns3="http://webservices.workflow.weaver">title....</ns3:requestName> <!--流程ID WorkFlowId--> <ns4:workflowBaseInfo xmlns:ns4="http://webservices.workflow.weaver"> <ns4:workflowId>3</ns4:workflowId> </ns4:workflowBaseInfo> <ns5:workflowMainTableInfo xmlns:ns5="http://webservices.workflow.weaver"> <ns5:requestRecords> <ns5:WorkflowRequestTableRecord> <ns5:workflowRequestTableFields> <ns5:WorkflowRequestTableField> <!--字段是否可编辑--> <ns5:edit>true</ns5:edit> <!--字段名称=加工仓库--> <ns5:fieldName>jgck</ns5:fieldName> <!--字段数据内容:文本类型--> <ns5:fieldValue>jia gong chang ku</ns5:fieldValue> <!--字段是否可见--> <ns5:view>true</ns5:view> </ns5:WorkflowRequestTableField> <ns5:WorkflowRequestTableField> <!--字段是否可编辑--> <ns5:edit>true</ns5:edit> <!--字段名称=质检日期--> <ns5:fieldName>zjrq</ns5:fieldName> <!--字段数据内容:文本类型--> <ns5:fieldValue>zhi jing ri qi</ns5:fieldValue> <!--字段是否可见--> <ns5:view>true</ns5:view> </ns5:WorkflowRequestTableField> </ns5:workflowRequestTableFields> </ns5:WorkflowRequestTableRecord> </ns5:requestRecords> </ns5:workflowMainTableInfo> </in0> <!--流程创建人用户ID--> <in1>8</in1> </doCreateWorkflowRequest> </soapenv:Body> </soapenv:Envelope>
2.SOAP响应报文 Response
HTTP/1.0 200 OK Server: WVS Cache-Control: no-cache X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1 Expires: Thu, 01 Dec 1994 16:00:00 GMT Set-Cookie: ecology_JSessionid=aaaFiDBaNSl5g41CfwX5x; path=/ Content-Type: text/xml; charset=UTF-8 Date: Wed, 19 Jan 2022 08:20:04 GMT <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <ns1:doCreateWorkflowRequestResponse xmlns:ns1="webservices.services.weaver.com.cn"> <ns1:out>4011</ns1:out> </ns1:doCreateWorkflowRequestResponse> </soap:Body> </soap:Envelope>
3.代码实现
package aaaaaaaaaaaaaaa; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class CURL { public static void main(String[] args) throws Exception { URL url=new URL("http://127.0.0.1:8888/services/WorkflowService"); //创建一个HttpURLConnection对象 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //设置content-type //服务端是soap1.2的协议 connection.setRequestProperty("Content-Type", " application/soap+xml; charset=utf-8;"); //设置使用connection对象进行输入输出 connection.setDoInput(true); connection.setDoOutput(true); connection.getOutputStream().write(getRequestBody().getBytes()); //接收服务端响应的内容 InputStream in = connection.getInputStream(); byte[] buffer=new byte[2048]; int len=0; StringBuilder sb=new StringBuilder(); while((len=in.read(buffer))!=-1) { String str=new String(buffer,0,len); sb.append(str); } in.close(); System.out.println(sb.toString()); } //拼接 SOAP请求报文 private static String getRequestBody() { String xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<soapenv:Envelope\n" + " xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " <soapenv:Body>\n" + " <doCreateWorkflowRequest\n" + " xmlns=\"webservices.services.weaver.com.cn\">\n" + " <in0>\n" + " <ns1:creatorId\n" + " xmlns:ns1=\"http://webservices.workflow.weaver\">8\n" + " </ns1:creatorId>\n" + " <ns2:requestLevel\n" + " xmlns:ns2=\"http://webservices.workflow.weaver\">2\n" + " </ns2:requestLevel>\n" + " <ns3:requestName\n" + " xmlns:ns3=\"http://webservices.workflow.weaver\">title....\n" + " </ns3:requestName>\n" + " <ns4:workflowBaseInfo\n" + " xmlns:ns4=\"http://webservices.workflow.weaver\">\n" + " <ns4:workflowId>3</ns4:workflowId>\n" + " </ns4:workflowBaseInfo>\n" + " <ns5:workflowMainTableInfo\n" + " xmlns:ns5=\"http://webservices.workflow.weaver\">\n" + " <ns5:requestRecords>\n" + " <ns5:WorkflowRequestTableRecord>\n" + " <ns5:workflowRequestTableFields>\n" + " <ns5:WorkflowRequestTableField>\n" + " <ns5:edit>true</ns5:edit>\n" + " <ns5:fieldName>jgck</ns5:fieldName>\n" + " <ns5:fieldValue>jia gong chang ku</ns5:fieldValue>\n" + " <ns5:view>true</ns5:view>\n" + " </ns5:WorkflowRequestTableField>\n" + " <ns5:WorkflowRequestTableField>\n" + " <ns5:edit>true</ns5:edit>\n" + " <ns5:fieldName>zjrq</ns5:fieldName>\n" + " <ns5:fieldValue>zhi jing ri qi</ns5:fieldValue>\n" + " <ns5:view>true</ns5:view>\n" + " </ns5:WorkflowRequestTableField>\n" + " </ns5:workflowRequestTableFields>\n" + " </ns5:WorkflowRequestTableRecord>\n" + " </ns5:requestRecords>\n" + " </ns5:workflowMainTableInfo>\n" + " </in0>\n" + " <in1>8</in1>\n" + " </doCreateWorkflowRequest>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; return xml; } }