《SP业务开发实例_说明.docx》由会员分享,可在线阅读,更多相关《SP业务开发实例_说明.docx(14页珍藏版)》请在三一办公上搜索。
1、1、 工具下载1.1 JDKJDK1.5下载页面:jdk-1_5_0_13-windows-i586-p.exe下载链接:http:/192.18.108.145/ECom/EComTicketServlet/BEGINA3B0EEAA08A312C1FAEC55BAC2297BBB/-2147483648/2402513439/1/852050/851882/2402513439/2ts+/westCoastFSEND/jdk-1.5.0_13-oth-JPR/jdk-1.5.0_13-oth-JPR:3/jdk-1_5_0_13-windows-i586-p.exe双击jdk-1_5_0_
2、13-windows-i586-p.exe安装JDK1.5。1.2 Eclipse(开发环境)Eclipse下载页面:http:/www.eclipse.org/downloadseclipse-SDK-3.3.1-win32.zip下载链接:http:/www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.3.1-200709211145/eclipse-SDK-3.3.1-win32.zip&url=解压缩eclipse-SDK-3.3.1-win32.zip即可(不需安装)。1.3 Tomcat(
3、Web服务器)Tomcat6.0下载页面:http:/tomcat.apache.org/download-60.cgiapache-tomcat-6.0.14.zip下载链接:解压缩apache-tomcat-6.0.14.zip即可(不需安装)。1.4 AXIS2(SOAP引擎)AXIS2下载页面:http:/ws.apache.org/axis2/download.cgiaxis2-1.3-bin.zip下载链接:解压缩axis2-1.3-bin.zip,lib目录下的jar包是WebService业务开发需要的库文件。axis2-1.3-war.zip下载链接:2、 Tomcat +
4、AXIS2 配置1 解压缩apache-tomcat-6.0.14.zip,axis2-1.3-bin.zip,axis2-1.3-war.zip。2 配置AXIS2环境变量:右击“我的电脑” - 属性 - 高级 - 选择“环境变量”将axis2-1.3下的bin目录增加到Path系统环境变量中(其中D:axis2-1.3bin需要根据实际情况设置):3 解压缩axis2-1.3-war.zip后,将axis2.war复制到webapps 下。4 双击binstartup.bat 启动Tomcat服务器,启动过程会自动将axis2.war解压缩,在webapps 下生成axis2目录。3、 客
5、户端业务开发实例本节以向用户发送彩信的业务为例讲解客户端业务开发的实例,其他业务能力的业务开发实例请参见各业务实例代码文件夹中的_readme.txt。彩信发送业务:SP作为客户端调用ParlayX GW开放的SendMessage接口发送彩信。3.1 由WSDL文件生成客户端代码使用到的WSDL文件包括:cuc_common_faults_2_0.wsdl,cuc_common_types_2_1.xsd,cuc_mm_send_interface_2_2.wsdl,cuc_mm_send_service_2_2.wsdl,cuc_mm_types_2_2.xsd在命令行下执行:WSDL2J
6、ava.bat -uri cuc_mm_send_service_2_2.wsdl生成的代码在src目录下:src |-cncomchinaunicomwwwwsdlcucmultimedia_messagingsendv2_2service3.2 在Eclipse中创建工程, 将WSDL生成的代码中src文件夹下的cn目录复制到工程中3.3 在工程中加入AXIS2的lib库选中工程cuc_mms,右击 - 选择Properties - 在工程属性对话框左边选择“Java Build Path”,然后选择右边的“Libraries”属性页 - 点击“Add External JARs.”按钮,
7、选择lib 目录下所有的jar文件,加入到工程的Libraries中 - OK3.4 编写客户端代码,开发彩信发送业务3.4.1 设置SOAPHeader新建类HeaderSetter,在HeaderSetter.java中编写代码:(完整代码见“cuc_mmsHeaderSetter.java”)public class HeaderSetter protected static final String nameSpace = protected static final String SOAPHEADER_spId = spId; protected static final Strin
8、g SOAPHEADER_spPassword = spPassword; /.(略) public static void setAOMTSoapHeader(ServiceClient serviceClient) /SOAPHeader字段赋值 String spId = 41999; String spPassword = 41999; /.(略) try /获取AXIOM的对象工厂 OMFactory fac = OMAbstractFactory.getOMFactory(); SOAPFactory sfac = OMAbstractFactory.getSOAP11Factor
9、y(); /创建名字空间NameSpace OMNamespace omNs = fac.createOMNamespace(nameSpace, tns); /创建RequestSOAPHeader SOAPHeaderBlock block_RequestSOAPHeader = sfac.createSOAPHeaderBlock( SOAPHEADER_RequestSOAPHeader, omNs); /设置spId SOAPHeaderBlock block_spId = sfac.createSOAPHeaderBlock(SOAPHEADER_spId, omNs); bloc
10、k_spId.addChild(sfac.createOMText(spId); /.(略) /将字段spId,spPassword,timeStamp,serviceId,. /作为RequestSOAPHeader的子节点 block_RequestSOAPHeader.addChild(block_spId); block_RequestSOAPHeader.addChild(block_spPassword); block_RequestSOAPHeader.addChild(block_timeStamp); block_RequestSOAPHeader.addChild(bloc
11、k_serviceId); block_RequestSOAPHeader.addChild(block_SPNumber); block_RequestSOAPHeader.addChild(block_sessionId); block_RequestSOAPHeader.addChild(block_sessionEnd); block_RequestSOAPHeader.addChild(block_linkId); block_RequestSOAPHeader.addChild(block_OA); block_RequestSOAPHeader.addChild(block_FA
12、); block_RequestSOAPHeader.addChild(block_groupMessaging); serviceClient.addHeader(block_RequestSOAPHeader); catch (Exception e) e.printStackTrace(); /.(略)3.4.2 修改存根类SendMessageServiceStub的sendMessage方法, 设置SOAP附件cncomchinaunicomwwwwsdlcucmultimedia_messagingsendv2_2serviceSendMessageServiceStub.java
13、第168行: /【增加org.apache.axiom.attachments.Attachments attachments参数用于发送附件】 public .chinaunicom.www.wsdl.cuc.multimedia_messaging.send.v2_2.service.SendMessageServiceStub.SendMessageResponse6 sendMessage( .chinaunicom.www.wsdl.cuc.multimedia_messaging.send.v2_2.service.SendMessageServiceStub.SendMessag
14、e7 sendMessage0, org.apache.axiom.attachments.Attachments attachments)第203行: /* * 增加以下代码用于设置SOAP附件 */ /*begin - 设置SOAP附件的代码*/ if (attachments != null) _operationClient.getOptions().setProperty( org.apache.axis2.Constants.Configuration.ENABLE_SWA, org.apache.axis2.Constants.VALUE_TRUE); _messageConte
15、xt.setAttachmentMap(attachments); /*end - 设置附件的代码*/3.4.3 调用SendMessage接口发送彩信新建类TestSendMms,在TestSendMms.java中编写代码:(完整代码见“cuc_mmsTestSendMms.java”)public class TestSendMms public static void main(String args) try /* * MMS接口规范中定义的sendMessage接口参数: * * DestinationAddress xsd:anyURI 0.unbounded * SenderA
16、ddress xsd:anyURI * Subject xsd:String * Priority MessagePriority * Charging Common:ChargingInformation * ReceiptRequest Common:SimpleReference */ /*begin - sendMessage接口参数设置*/ SendMessage param = new SendMessage(); /DestinationAddress, 目的地址(群发的情况下, DestinationAddress为URI数组) URI addr = new URI1; add
17、r0 = new URI(tel:+8613156111754); param.setDestinationAddress(addr); /SenderAddress param.setSenderAddress(14244518); /Subject param.setSubject(MMSTest); /Priority param.setPriority(MessagePriority.Default); /Charging(可选) param.setCharging(null); /ReceiptRequest, 为null表示SP不需要状态报告; 非null表示SP需要状态报告 Si
18、mpleReference simpleRef = new SimpleReference(); simpleRef.setEndpoint(new URI(http:/localhost:8080); simpleRef.setCorrelator(123456); simpleRef.setInterfaceName(test);/ param.setReceiptRequest(simpleRef); /ReceiptRequest非null表示SP需要状态报告 param.setReceiptRequest(null); /ReceiptRequest为null表示SP不需要状态报告
19、/设置彩信附件, 从磁盘读取图片文件 File f = new File(D:1.txt); Attachments attachments = new Attachments(); FileDataSource ds = new FileDataSource(f); DataHandler dh = new DataHandler(ds); attachments.addDataHandler(12345678, dh); /*end - sendMessage接口参数设置*/ /ParlayX GW的sendMessage开放接口URI String sendMessageURI = ht
20、tp:/127.0.0.1:18080/wespa_mms/services/SendMessage; /创建客户端Stub类的对象 SendMessageServiceStub sendMessageStub = new SendMessageServiceStub(sendMessageURI); ServiceClient client = sendMessageStub._getServiceClient(); /【设置SOAPHeader】 HeaderSetter.setAOMTSoapHeader(client); /【设置请求消息】 SendMessage7 reqMessag
21、e = new SendMessage7(); reqMessage.setSendMessage(param); /【调用sendMessage接口并获取响应消息, 由AXIS2完成SOAP消息的封装、发送请求消息、接收响应消息】 /需要修改SendMessageServiceStub类的sendMessage方法 /需要增加参数org.apache.axiom.attachments.Attachments attachments用于传递附件 /并在sendMessage方法中增加以下代码, 用于设置SOAP附件 : / if (attachments != null) / / _oper
22、ationClient.getOptions().setProperty( / org.apache.axis2.Constants.Configuration.ENABLE_SWA, / org.apache.axis2.Constants.VALUE_TRUE); / _messageContext.setAttachmentMap(attachments); / /见SendMessageServiceStub.java第203行 SendMessageResponse6 rspMessage = sendMessageStub.sendMessage(reqMessage, attac
23、hments); System.out.println(rspMessage.getSendMessageResponse().getResult(); /.(略) 4、 服务端业务开发实例本节以接收用户上发彩信的业务为例讲解服务端业务开发的实例,其他业务能力的服务端业务开发实例请参见各业务实例代码文件夹中的_readme.txt。接收用户上发彩信业务:SP作为服务端,当用户上发彩信时ParlayX GW调用SP开放的NotifyMessageReception接口发送用户上发的彩信。4.1 由WSDL文件生成服务端代码使用到的WSDL文件包括:cuc_common_faults_2_0.ws
24、dl,cuc_common_types_2_1.xsd,cuc_mm_notification_interface_2_2.wsdl,cuc_mm_notification_service_2_2.wsdl,cuc_mm_types_2_2.xsd在命令行下执行:WSDL2Java.bat -uri cuc_mm_notification_service_2_2.wsdl -ss -sd生成的代码在src目录下:src |-cncomchinaunicomwwwschema |-cncomchinaunicomwwwwsdlcucmultimedia_ messagingnotificatio
25、nv2_2service生成的资源文件在resource目录下:resource |-services.xmlservices.xml是用于发布接口的资源文件。4.2 在Eclipse中创建工程, 将WSDL生成的代码中src文件夹下的cn目录复制到工程中同3.2。4.3 在工程中加入AXIS2的lib库同3.3。4.4 编写服务端代码,接收用户上发的彩信修改cncomchinaunicomwwwwsdlcucmultimedia_ messagingnotificationv2_2serviceMessageNotificationServiceSkeleton.java代码如下: publ
26、ic .chinaunicom.www.schema.cuc.multimedia_messaging.notification.v2_2.local.NotifyMessageReceptionResponse5 notifyMessageReception( .chinaunicom.www.schema.cuc.multimedia_messaging.notification.v2_2.local.NotifyMessageReception4 notifyMessageReception) MessageReference msgRef = notifyMessageReceptio
27、n.getNotifyMessageReception().getMessage(); /打印消息 System.out.println(Get notifyMessageReception message :); System.out.println(RegistrationIdentifier = + notifyMessageReception.getNotifyMessageReception().getRegistrationIdentifier(); System.out.println( MessageIdentifier = + msgRef.getMessageIdentif
28、ier(); System.out.println( ActivationNumber = + msgRef.getMessageServiceActivationNumber(); System.out.println( SenderAddress = + msgRef.getSenderAddress(); System.out.println( Subject = + msgRef.getSubject(); System.out.println( Priority = + msgRef.getPriority().getValue(); System.out.println( Mess
29、age = + msgRef.getMessage(); /保存附件 try Attachments attachments = new Attachments();MessageContext msgCtx = MessageContext.getCurrentMessageContext();attachments = msgCtx.getAttachmentMap();String content_id = attachments.getAllContentIDs();for (int i = 0; i Export - 选择Java目录下的JAR file, 点击Next。(2)选择aar包路径并以.aar作为后缀名 - Finish。(3)用winRar打开aar包,将资源文件中的services.xml加入到META-INF目录下。4.6 在Tomcat服务器部署服务(1)将aar包复制到 webappsaxis2WEB-INFservices 下。(2)启动Tomcat服务器,可以在http:/localhost:8080/axis2/services/listServices中看到发布的服务“MessageNotificationService”。