-
- // axis2通过反射得到一个soap连接工厂的实现类==================================================
- SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory
- .newInstance();
- //调用soap连接工厂实现类的creaateConnection()实例化soap连接类的实现类
- SOAPConnection connection = soapConnFactory.createConnection();
- // 创建消息对象,通过反射实例化了消息工厂抽象类
- // ===========================================
- MessageFactory messageFactory = MessageFactory.newInstance();
- //消息工厂抽象类通过调用子类(MessageFatoryImpl)实现了createMessage()的调用
- //【createMessage()方法通过SOAP12Factory.getDefaultEnvelope()实例化了soap信封(soapEnvelope),
- getDefaultEnvelope()方法,OMNamespace ns = new OMNamespaceImpl("http://schemas.xmlsoap.org/soap/envelope/", "soapenv");通过OMNamespace的实例化给命名空间加上了信封的地址,把soapenv前缀绑定到URI上 SOAPEnvelopeImpl env = new SOAPEnvelopeImpl(ns, this);("Envelope", ns, factory);把envelope绑定成了Element的元素,
- createSOAPHeader(env);createSOAPBody(env);把header,body绑定到envelope元素下作为envelope元素的子节点
- 然后 soapEnvelope.getOwnerDocument().appendChild(soapEnvelope);把信封添加到文档document中
-
创建soap消息实现类,创建soap消息实现类中有对消息的mine类型进行定义,同时创建soappart消息部分,soappart的mine类型必须为xml格式SOAPMessageImpl soapMessage = new SOAPMessageImpl(new SOAPEnvelopeImpl(soapEnvelope));soapMessage.setSaveRequired();】
-
- SOAPMessage message = messageFactory.createMessage();
- // message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "gb2312");
- // 创建soap消息主体==========================================
- SOAPPart soapPart = message.getSOAPPart();// 创建soap部分
- SOAPEnvelope envelope = soapPart.getEnvelope();
- SOAPBody body = envelope.getBody();
- // 根据要传给mule的参数,创建消息body内容。具体参数的配置可以参照应用集成接口技术范=====================================
-
- SOAPElement bodyElement = body.addChildElement(envelope.createName(
- "process", "Request", "http://esb.service.com/"));
- bodyElement.addChildElement("ServiceCode").addTextNode("10000061");
- bodyElement.addChildElement("OrigAppId").addTextNode("999");
- bodyElement.addChildElement("HomeAppId").addTextNode("998");
- Calendar c = Calendar.getInstance();
- String reqTime = String.valueOf(c.getTimeInMillis());
- bodyElement.addChildElement("ReqTime").addTextNode(reqTime);
- bodyElement.addChildElement("IpAddress").addTextNode("10.212.40.112");
- bodyElement.addChildElement("OrigSerialNo").addTextNode("201205242011");
- //(ServiceCode+ OrigAppId+ ReqTime+ IpAddress)签名
- String AppSignature = "10000061"+"999"+reqTime+"10.212.40.112"+"123456";
- bodyElement.addChildElement("AppSignature").addTextNode(EncoderUtil.md5(AppSignature));
- bodyElement.addChildElement("Version").addTextNode("014");
- // bodyElement.addChildElement("RelSessionId").addTextNode("RelSessionId");
- // bodyElement.addChildElement("ReplyCode").addTextNode("ReplyCode");
- bodyElement.addChildElement("ReplyVersion").addTextNode("05");
- bodyElement.addChildElement("TimeOut").addTextNode("30");
- // bodyElement.addChildElement("FtpDir").addTextNode("FtpDir");
- // bodyElement.addChildElement("FileList").addTextNode("FileList");
- bodyElement.addChildElement("serviceParas").addTextNode("<param><name>apptest</name><password>apptest</password></param>");
- // Save the message对消息mine类型再次进行设置
- message.saveChanges();
- // 打印客户端发出的soap报文,做验证测试
- System.out.println(" REQUEST: ");
- //以xml格式的字节流输出outputstream
- message.writeTo(System.out);
- System.out.println(" ");
-
服务调用者发送soap消息通过http发送服务器的过程解析
最新推荐文章于 2024-01-14 20:29:49 发布