⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsnotifyservice.java

📁 中国联通短信通信协议
💻 JAVA
字号:
package com.wireless.sms.unsoap.axis;

import cn.com.chinaunicom.www.schema.cuc.sms.v2_1.DeliveryInformation;
import cn.com.chinaunicom.www.schema.cuc.sms.v2_1.SmsMessage;
import cn.com.chinaunicom.www.wsdl.cuc.sms.notification.v2_1._interface.SmsNotification;

public class SmsNotifyService implements SmsNotification,javax.xml.rpc.server.ServiceLifecycle {
	
//	static{
//		System.out.println("SmsNotification init...");
//		init();
//	}
	
	public void notifySmsReception(String registrationIdentifier, SmsMessage message)
		throws java.rmi.RemoteException{
    	System.out.println("-------MO Deliver-------");
    	CPHeaderHandler.writeLog();
    	System.out.println();
		System.out.println("registrationIdentifier = "+registrationIdentifier);
    	try {
			System.out.println("SenderAddress = "+message.getSenderAddress().toString()+"\n"+
					"ServiceActivationNumber = "+message.getSmsServiceActivationNumber().toString()+"\n"+
					"Message = "+message.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
		}
    	System.out.println("----end of MO Deliver----");
    	System.out.println();
	}
	
	public void notifySmsDeliveryReceipt(String correlator, DeliveryInformation deliveryStatus)
		throws java.rmi.RemoteException{
    	System.out.println("-------stat Deliver-------");
    	CPHeaderHandler.writeLog();
    	System.out.println();
		System.out.println("correlator = "+correlator);
    	System.out.println(deliveryStatus.getAddress());
    	cn.com.chinaunicom.www.schema.cuc.sms.v2_1.DeliveryStatus status = 
    		(cn.com.chinaunicom.www.schema.cuc.sms.v2_1.DeliveryStatus)deliveryStatus.getDeliveryStatus();
    	System.out.println(status==null?"":status.getValue());
    	System.out.println("----end of stat Deliver----");
    	System.out.println();
	}
	
	public void init(Object context) {
		System.out.println("init Going...");
		javax.xml.rpc.server.ServletEndpointContext servletEndpointContext = 
			(javax.xml.rpc.server.ServletEndpointContext)context;
		javax.servlet.ServletContext servletContext = servletEndpointContext.getServletContext();
		java.util.Enumeration en = servletContext.getInitParameterNames();
		while(en!=null && en.hasMoreElements()){
			Object el = en.nextElement();
			System.out.println(el);
		}
	}
	
	public void destroy() {
		System.out.println("run destroy...");
//		SMSSender.getInstance().stopSendMT();
//	    SmsGWIFGlobal.sendMonitor("I000011");
//	    ReloadProcess.getInstance().stopInterface();
	    System.out.println("destory over!");
	}

	protected static void init(){
		new Thread(){
			public void run(){
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e1) {
					e1.printStackTrace();
				}
				String outxml = "<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:Header>"+
  "<cuc:NotifySOAPHeader xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">"+
    "<cuc:spRevId xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">10001</cuc:spRevId>"+
    "<cuc:spRevpassword xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">10001</cuc:spRevpassword>"+
    "<cuc:spId xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">88888</cuc:spId>"+
    "<cuc:SAN xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">142401</cuc:SAN>"+
    "<cuc:serviceId xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">0100100100</cuc:serviceId>"+
    "<cuc:linkId xmlns:cuc=\"http://www.chinaunicom.com.cn/schema/cuc/common/v2_1\">123456</cuc:linkId>" +
  "</cuc:NotifySOAPHeader>"+
"</soap:Header>"+
"<soap:Body>"+
  "<ns2:notifySmsReception xmlns:ns2=\"http://www.chinaunicom.com.cn/schema/cuc/sms/notification/v2_1/local\">"+
    "<ns2:registrationIdentifier>tel:8613176661001</ns2:registrationIdentifier>"+
    "<ns2:message>"+
      "<message>12</message>"+
      "<senderAddress>tel:8613176661001</senderAddress>"+
      "<smsServiceActivationNumber>tel:142401</smsServiceActivationNumber>"+
    "</ns2:message></ns2:notifySmsReception>"+
  "</soap:Body>"+
"</soap:Envelope>";
				org.dom4j.io.SAXReader saxReader = new org.dom4j.io.SAXReader();
				org.dom4j.Document doc;
				try {
					doc = saxReader.read(new java.io.File("./localservices.xml"));
				} catch (java.net.MalformedURLException e) {
					e.printStackTrace();
					return;
				} catch (org.dom4j.DocumentException e) {
					e.printStackTrace();
					return;
				}
				org.dom4j.Element root = doc.getRootElement();
				java.util.Iterator iter = root.element("localservices").elementIterator("http_addr");
				while(iter.hasNext()){
					org.dom4j.Element http_addr = (org.dom4j.Element)iter.next();
					String addr = http_addr.getTextTrim();
					System.out.println(addr);
					System.out.println(do_postString(addr, outxml));
				}
			}
		}.start();
	}
	
	private static String do_postString(String requestURL, String outxml) {
		
		org.apache.commons.httpclient.methods.PostMethod post = 
			new org.apache.commons.httpclient.methods.PostMethod(requestURL);
		post.setRequestHeader("Content-type", "text/xml; charset=utf-8");
	    post.setRequestHeader("SOAPAction", "notifySmsReception");
		post.setRequestBody(outxml);
		org.apache.commons.httpclient.HttpClient httpclient = new org.apache.commons.httpclient.HttpClient();
		String response = "";
		try {
			int result = httpclient.executeMethod(post);
			response = "POST result code: " + result+"\nResponseBody: ";
			
			/**以下如果报"[Fatal Error] :1:1: Premature end of file",则说明
			 * "xml文件不是正确的xml文件.或者说xml文件解析的时候根节点没有找到"
			 * 一般都是由于post请求结果非法造成,OLGW平台没有给于响应的原因*/
			try {
				java.io.BufferedInputStream in = new java.io.BufferedInputStream(post.getResponseBodyAsStream());
				int len = 1024;//in.available();
				System.out.println("***********len = "+ len);
				byte[] temp = new byte[len];
				int length = in.read(temp,0,len);
				byte[] total = (byte[])temp.clone();
				while(length != -1){
					temp = new byte[len];
					length = in.read(temp,0,len);
					///////////////////////
					byte[] t = (byte[])total.clone();
					total = new byte[t.length+len];
					for(int i=0;i<t.length;i++){
						total[i]=t[i];
					}
					for(int i=0;i<len;i++){
						total[t.length+i]=temp[i];
					}
				}
				String s = new String(total,"UTF-8").trim();//post.getResponseBodyAsString();
				response = response+"\n"+s;//b.toString();
				in.close();
			} catch (Exception e) {
				return response;
			}
			
			if(result==400){//测试中如用结构不完整或异常请求时预期输出是一个tomcat 的error report 页面
				return response;
			}
			
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			post.releaseConnection();
		}
		return response;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -