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

📄 nokiagetter.java

📁 mmslib1.0 支持彩信制作、解析
💻 JAVA
字号:
/** * MMSLIB - A Java Implementation of the MMS Protocol * Copyright (C) 2004 Simon Vogl  * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package at.jku.soft.mms.nokia;import java.util.Vector;import net.sourceforge.jwap.wsp.*;import java.net.*;import java.io.*;import java.util.*;import org.apache.log4j.*;import com.nokia.mms.*;public class NokiaGetter implements IWSPUpperLayer {    protected static Logger logger = Logger.getLogger(NokiaGetter.class);    /**     * The actual WSP Session.     * You need one instance of CWSPSession for each WAP session.     */    private CWSPSession session;    /**     * the URI we would like to get in this example     */    private String uriToGet;    /**     * You will get an instance of CWSPMethodManger for each invoked     * method (GET or POST). In this Vector we collect all invoked methods.     */    private Vector invokedMethods = new Vector();    /**     *     * @param wapGwAddress Adress of the WAP-Gateway     * @param wapGwPort Port of the WAP-Gateway     * @param uriToGet the URI we would like to GET     */    public NokiaGetter(InetAddress wapGwAddress,		       int         wapGwPort,		       String      uriToGet)      {	// GET-URI ablegen	this.uriToGet = uriToGet;			// neue Session 黚er Wap-Gateway	try{	    if ( ! uriToGet.startsWith("http://")) {		// decode local pdu if file is passed -- for debugging		File f = new File(uriToGet);		long len = f.length();		byte b[] = new byte[(int)len];		FileInputStream fi = new FileInputStream(f);		fi.read(b);		decode(b);		return;	    }	    	    session = new CWSPSession(wapGwAddress, // URI of WAP gateway				      wapGwPort,    // port of wap gateway				      this,         // WE would like to be informed of occuring events				      true);        // be verbose	    logger.debug("Connecting to WAP-Gateway");	    session.s_connect();	    // we will get a s.connect.cnf, when we are connected.	    // @see #s_connect_cnf()	} catch (Exception e){	    // UDP Socket problem	    e.printStackTrace();	}    }        private void saveToFile(String filename, byte[]b) {	try{	    FileOutputStream fo;	    fo = new FileOutputStream(filename);	    fo.write(b);	    fo.close();	} catch (Exception e){	    // Host address not ok	    e.printStackTrace();	    System.exit(1);	}    }    //------------------ from here on we implement IWSPUpperLayer ---------------    /**     * called by jwap stack, when we are connectedwith the WAP gateway     */    public void s_connect_cnf() {	logger.debug("connected to WAP gateway");	logger.debug("GET " + uriToGet);	// now we do call GET!	// jwap returns an instance of CWSPMethodManager, that manages	// the method call	// We put it into the vector above.	invokedMethods.addElement(session.s_get(uriToGet));    }    /**     * called by jwap stack, to announce a response to a GET/POST method invocation     *     * @param payload     * @param contentType     * @param moreData     */    public void s_methodResult_ind(byte[] payload, String contentType, boolean moreData) {	logger.debug("Antwort erhalten:");	logger.debug("Content Type: "+ contentType);	logger.debug("More Data: "+ moreData);	logger.debug("Payload length: "+ payload.length + " bytes");	/*	  for (int i=0;i<payload.length;i++) {	  System.out.print((char)payload[i]);	  }	*/	saveToFile(contentType + "_" + System.currentTimeMillis() +".mms", payload); 	decode(payload);	// if we do not need any more invocations of a GET/POST methode, we will	// disconnect from WAP gateway	logger.debug("\n\nDisconnecting from WAP-Gateway");	if (!moreData)	    session.s_disconnect();    }    public void decode(byte[] buf)    {	// instantiate the MMDecoder object	MMDecoder mmDecoder = new MMDecoder();	// set the buffer	mmDecoder.setMessage(buf);	// decode the message	try {	    mmDecoder.decodeMessage();	} catch (Exception e) {	    System.err.println(e.getMessage());	    e.printStackTrace();	}	// retrieve the message	MMMessage mm=mmDecoder.getMessage();	// read the message type	if (mm.getMessageType()==IMMConstants.MESSAGE_TYPE_M_SEND_REQ) {	    System.out.println(" Message Type: m-send-req");	} 	if (mm.getMessageType()==0x04) {	    System.out.println(" Message Type: m-retrieve-conf");	} 	// read the transaction ID	System.out.println(" Transaction Id: "+mm.getTransactionId());	// read the version	System.out.println(" Version: "+mm.getVersionAsString());	// read the recipients of the Multimedia Message	if (mm.isToAvailable()) {	    Vector list=mm.getTo();	    for (int n=0; n<list.size(); n++) {		MMAddress to=(MMAddress)list.elementAt(n);		System.out.println(" To : "+to.getAddress()+" - type="+to.getType());	    }	} else {	    System.out.println("  TO absent !!!");	}	// read the date of the Multimedia Message	if (mm.isDateAvailable()) {	    System.out.println(" Date: "+mm.getDate());	}	// read the sender of the Multimedia Message	if (mm.isFromAvailable()) {	    MMAddress from = new MMAddress( mm.getFrom() );	    System.out.println(" From: "+from.getAddress()+" - type="+from.getType());	}	// read the subject of the Multimedia Message	if (mm.isSubjectAvailable()) {	    System.out.println(" Subject: "+mm.getSubject());	}	// read the content type of the Multimedia Message	if (mm.isContentTypeAvailable()) {	    System.out.println(" Content Type: "+mm.getContentType());	}	// read the kind of the presentation type	if (mm.isPresentationAvailable()) {	    System.out.println(" MultipartRelatedType: "+mm.getMultipartRelatedType());	}	// read the Multimedia Message entries and store them in files	MMContent mmContent=null;		try { for (int j=0; j <mm.getNumContents(); j++) {	    	    mmContent=mm.getContent(j);	    System.out.println( " Content --> ID = "+mmContent.getContentId()+", TYPE = "+mmContent.getType()+", LENGTH = "+mmContent.getLength() );	    	    if ((mmContent.getType()).compareTo(IMMConstants.CT_TEXT_PLAIN)==0) {		mmContent.saveToFile(mmContent.getContentId()+".txt");	    } else {		if ((mmContent.getType()).compareTo(IMMConstants.CT_IMAGE_JPEG)==0) {		    mmContent.saveToFile(mmContent.getContentId()+".jpg");		} else {		    if ((mmContent.getType()).compareTo(IMMConstants.CT_IMAGE_GIF)==0) {			mmContent.saveToFile(mmContent.getContentId()+".gif");		    } else {			mmContent.saveToFile(mmContent.getContentId());		    }		}	    }	} } catch(Exception e) {e.printStackTrace();}    }           /**     * will be incoked by jwap stack, when we are disconnected from the WAP gateway     * @param reason     */    public void s_disconnect_ind(short reason) {	logger.debug("Disconnected.");    }    /**     * will be invoked by jwap stack, when we are disconnected by the WAP gateway     * because it is redirected.     *     * @param redirectInfo     */    public void s_disconnect_ind(InetAddress[] redirectInfo) {	logger.debug("WTP session  disc_ind");    }    /**     * invoked ba the jwap stack to show, that the session is suspended     * @param reason     */    public void s_suspend_ind(short reason) {	logger.debug("WTP session susp_ind");    }    /**     * invoked, when a suspended session will be resumed     */    public void s_resume_cnf() {	logger.debug("WTP session resume_cnf");    }    public static void main(String[] args) {	try{	    // we use an open wap gateway by www.waptunnel.com	    InetAddress gateway = InetAddress.getByName("194.24.131.17");	    //      NokiaGetter getter = new NokiaGetter(gateway, 9201, "http://mmsc.one.at/mms/wapenc?location=4369914219502_uipr02");	    String addr="http://mmsc.one.at/mms/wapenc?location=4369918010000_lapc02";	    if (args.length>0)		addr = args[0];	    NokiaGetter getter = new NokiaGetter(gateway, 9201, addr);	} catch (UnknownHostException e){	    // Host address not ok	    e.printStackTrace();	}    }}

⌨️ 快捷键说明

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