root/www.mail/JavaPopWeb/src/jp/ac/nime/computer/websim/HTTPServItem.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. HTTPServItem
  2. onMousePressed
  3. postMailAction
  4. postPacketAction
  5. postEventAction

package jp.ac.nime.computer.websim;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

import jp.ac.nime.computer.*;

/**
 * WWWシミュレータ HTTPサーバーオブジェクトクラス
 * 
 * @version 1.00 2003/03/31
 * @author Toshikazu Matsumoto Avion Corp.
 */
public class HTTPServItem extends MachineItem
{
        private WebSim m_Applet;                                        //メインアプレットクラス
        private HTTPPacketData m_objPack;                       //対象パケットデータオブジェクト
        private TCPStatusDialog m_TCPDialog=null;       //TCP/IPダイアログクラス
        
        /**
         * クラスコンストラクタ
         * @param parent メインアプレットクラス
         * @param sIP IPアドレス
         * @param imSrc 表示画像
         * @param nX 表示X座標
         * @param nY 表示Y座標
         */
        public HTTPServItem(WebSim parent,String sIP,Image imSrc,int nX,int nY)
        {
                super(parent,"WWWサーバー",sIP,imSrc,nX,nY);
                this.m_Applet=parent;
        }
        /**
         * マウス押下時のアクション
         */
        public boolean onMousePressed()
        {
                return true;
        }
        /**
         * メールオブジェクト到達通知アクション
         * @param obj メールデータオブジェクト
         */
        public void postMailAction(MailDataObject obj)
        {
        }
        /**
         * HTTPパケットオブジェクト到達通知アクション
         * @param obj HTTPパケットオブジェクト
         */
        public void postPacketAction(HTTPPacketData obj)
        {
                String sText="";
                this.m_objPack=obj;
                int nStatus=obj.getStatus();
                HTTPPacketData objPack=null;
                
                switch(nStatus)
                {
                case HTTPPacketData.HTTP_PACKET_STATUS_TCP_TEST: //TCPテストパケット到達アクション
                        Point point=((Component)m_Applet).getLocationOnScreen();
                        point.setLocation(point.x+super.m_nPosX+super.getImage().getWidth(this.m_Applet),point.y+super.m_nPosY+super.getImage().getHeight(this.m_Applet));
                        if(this.m_TCPDialog==null)
                        {
                                this.m_TCPDialog=new TCPStatusDialog(super.getRootFrame(),point,this);
                        }
                        if(this.m_TCPDialog.isShowing()==false)
                        {
                                this.m_TCPDialog.show();
                        }
                        Random rand=new Random(System.currentTimeMillis());
                        int nRand=rand.nextInt(100);
                        objPack=new HTTPPacketData(this.m_Applet,this.m_Applet.getImageArray(2));
                        if(nRand>30)
                        {
                                this.m_TCPDialog.setPacket(obj.getNumber());
                                objPack.setMemo(obj.getMemo()+" OK");
                                objPack.setResult(true);
                        }
                        else
                        {
                                objPack.setMemo("");
                                objPack.setResult(false);
                                objPack.setIcon(null);
                        }
                        objPack.setNumber(obj.getNumber());
                        objPack.setStatus(HTTPPacketData.HTTP_PACKET_STATUS_TCP_RET);
                        objPack.setMoveObject(this,obj.getMoveFrom());
                        objPack.startThread();
                        this.m_Applet.addPacket(objPack);
                        break;
                case HTTPPacketData.HTTP_PACKET_STATUS_GET_OPEN_KEY: //公開キー到達アクション
                        objPack=new HTTPPacketData(this.m_Applet,this.m_Applet.getImageArray(4));
                        objPack.setMemo("公開鍵");
                        objPack.setServName(obj.getServName());
                        objPack.setStatus(HTTPPacketData.HTTP_PACKET_STATUS_OPEN_KEY_RET);
                        objPack.setMoveObject(this,obj.getMoveFrom());
                        objPack.startThread();
                        this.m_Applet.addPacket(objPack);
                        this.m_Applet.sentOpenKey();
                        break;
                case HTTPPacketData.HTTP_PACKET_STATUS_COMMON_KEY: //共通キー到達アクション
                        objPack=new HTTPPacketData(this.m_Applet,this.m_Applet.getImageArray(2));
                        objPack.setMemo("暗号化されたデータ");
                        objPack.setStatus(HTTPPacketData.HTTP_PACKET_STATUS_CRYPT_DATA);
                        objPack.setMoveObject(this,obj.getMoveFrom());
                        objPack.startThread();
                        this.m_Applet.addPacket(objPack);
                        this.m_Applet.recComKey();
                        break;
                default: //HTTP要求アクション
                        if(obj.getFileName().compareTo("/index.html")!=0&&obj.getFileName().compareTo("/cook.html")!=0)
                        {
                                sText="HTTP/1.1 404 Not Found\n";
                                this.m_objPack.setResult(false);
                        }
                        else
                        {
                                sText="HTTP/1.1 200 OK\n";
                                sText+="Date: Tue, 19 Dec 2002 06:06:19 GMT\n";
                                sText+="Server: Apache/1.3.12\n";
                                sText+="Content-Location: http-header.html.ja\n";
                                sText+="Vary: negotiate,accept-language,accept-charset\n";
                                sText+="TCN: choice\n";
                                sText+="P3P: plicyref=\"/w3c/p3p.xml\",\n";
                                sText+="CP=\"NOI DSP COR ADM DEV OUR STP\"\n";
                                sText+="Last-Modified: Tue, 19 Dec 2002 06:02:09 GMT\n";
                                sText+="Connection: close\n";
                                if(obj.getCookie().compareTo("")!=0)
                                {
                                        sText+="Set-Cookie: pass="+obj.getCookie()+" ; expires=Mon, 31-Mar-2004 08:00:00:\n";
                                }
                                sText+="Content-Type: text/html; charset=shift_jis\n";
                                sText+="Content-Language: ja\n";
                                this.m_objPack.setResult(true);
                        }
                        new TextAreaDialog(super.getRootFrame(),"レスポンス",sText,(MachineItem)this);
                        break;
                }
        }
        /**
         * 外部からのイベント通知
         * @param nEvent イベント種類
         */
        public void postEventAction(int nEvent)
        {
                if(nEvent==MachineItem.ON_TEXTAREA_DIALOG_CLOSED)
                {
                        m_objPack.setMemo("Response");
                        m_objPack.setProcess(1);
                        if(this.m_objPack.getCookie().compareTo("")!=0)
                        {
                                m_objPack.setStatus(HTTPPacketData.HTTP_PACKET_STATUS_RET_COOK);
                        }
                        else
                        {
                                m_objPack.setStatus(HTTPPacketData.HTTP_PACKET_STATUS_RET_HTTP);
                        }
                        m_objPack.setMoveObject(this,m_objPack.getMoveFrom());
                        this.m_Applet.addPacket(m_objPack);
                }
        }
}

/* [<][>][^][v][top][bottom][index][help] */