Exemplo n.º 1
0
 public override void handleGETRequest( HttpProcessor p )
 {
     try
     {
         string contextPath = p.ContextPath;
         if ("/document".Equals( contextPath ))
         {
             processDocument( p );
         }
         else if (contextPath.StartsWith( "/tsf" ))
         {
             processTSF( p );
         }
         else
         {
             Dictionary<String, String> properties = p.Properties;
             p.writeSuccess();
             p.outputStream.WriteLine( "<html><body><h1>Test Document Server (GET)</h1>" );
             p.outputStream.WriteLine( "Current Time: " + DateTime.Now );
             p.outputStream.WriteLine( "url : {0}", p.http_url );
             p.outputStream.WriteLine( "context: {0}", contextPath );
             p.outputStream.WriteLine( "<table>" );
             foreach (string key in properties.Keys)
             {
                 p.outputStream.WriteLine( "\t<tr>" );
                 p.outputStream.Write( "\t\t<td>" );
                 p.outputStream.Write( properties[key] );
                 p.outputStream.Write( "\t\t</td>" );
                 p.outputStream.WriteLine( "\t<;tr>" );
             }
             p.outputStream.WriteLine( "</table>" );
         }
     }
     catch (Exception e)
     {
         //p.writeFailure();
         p.outputStream.WriteLine( "<html><body style=\"color:red\"><h1>Error</h1><p>" );
         p.outputStream.WriteLine( e.Message );
         p.outputStream.WriteLine( "</p></body></html>" );
     }
 }
Exemplo n.º 2
0
        private void processDocument( HttpProcessor p )
        {
            const string key = "uuid";
            const string name = "name";
            Document document;
            string uuid = "";
            string fileName = "";
            Dictionary<String, String> properties = p.Properties;
            if (!properties.ContainsKey( key ) && !properties.ContainsKey( name ))
                throw new Exception( "Missing uuid or name" );
            if (properties.ContainsKey( key ))
                uuid = properties[key];
            if (properties.ContainsKey( name ))
                fileName = properties[name];
            if (!string.IsNullOrWhiteSpace( uuid ))
                document = DocumentManager.GetDocument( uuid );
            else
                document = DocumentManager.GetDocumentByName( fileName );

            if (document == null)
                throw new Exception( String.Format( "Document \"{0}\" was not found.", uuid ) );
            p.httpHeaders.Add( "Content-Type", document.ContentType );
            p.httpHeaders.Add( "Content-Disposition", "Attachment; filename=" + document.name );
            var writer = new BinaryWriter( p.outputStream.BaseStream, Encoding.UTF8 );
            writer.Write( document.DocumentContent );
        }
Exemplo n.º 3
0
 public override void handlePOSTRequest( HttpProcessor p, StreamReader inputData )
 {
     throw new NotImplementedException();
 }
Exemplo n.º 4
0
        private void processTSF( HttpProcessor p )
        {
            string url = p.http_url;
            //Strip off /tsf/
            url = url.Substring( 5 );
            string[] parts = url.Split( '/' );
            if (parts.Length != 2)
                throw new Exception( "Invalid URL" );
            string name = parts[0];
            string version = parts[1];

            SignalDAO dao = DataManager.getSignalDAO();
            dbTSFLibrary lb = dao.getTSFLibraryByName( name );
            if (lb == null || lb.content == null)
                throw new Exception( string.Format( "Signal Model Library \"{0}\" was not found.", name ) );
            p.httpHeaders.Add( "Content-Type", "text/xml" );
            p.httpHeaders.Add( "Content-Disposition", "inline; filename=" + name + ".xml" );
            var writer = new BinaryWriter( p.outputStream.BaseStream, Encoding.UTF8 );
            writer.Write( Encoding.UTF8.GetBytes( lb.content ) );
        }
Exemplo n.º 5
0
        public override void handlePOSTRequest( HttpProcessor p, StreamReader inputData )
        {
            Console.WriteLine( "POST request: {0}", p.http_url );
            string data = inputData.ReadToEnd();

            p.writeSuccess();
            p.outputStream.WriteLine( "<html><body><h1>test server</h1>" );
            p.outputStream.WriteLine( "<a href=/test>return</a><p>" );
            p.outputStream.WriteLine( "postbody: <pre>{0}</pre>", data );
        }
Exemplo n.º 6
0
        public override void handleGETRequest( HttpProcessor p )
        {
            string contextPath = p.ContextPath;
            Dictionary<String, String> properties = p.Properties;

            if (p.http_url.Equals( "/Test.png" ))
            {
                Stream fs = File.Open( "../../Test.png", FileMode.Open );

                p.writeSuccess( "image/png" );
                fs.CopyTo( p.outputStream.BaseStream );
                p.outputStream.BaseStream.Flush();
            }

            Console.WriteLine( "request: {0}", p.http_url );
            p.writeSuccess();
            p.outputStream.WriteLine( "<html><body><h1>test server</h1>" );
            p.outputStream.WriteLine( "Current Time: " + DateTime.Now );
            p.outputStream.WriteLine( "url : {0}", p.http_url );

            p.outputStream.WriteLine( "<form method=post action=/form>" );
            p.outputStream.WriteLine( "<input type=text name=foo value=foovalue>" );
            p.outputStream.WriteLine( "<input type=submit name=bar value=barvalue>" );
            p.outputStream.WriteLine( "</form>" );
        }
Exemplo n.º 7
0
 public void listen()
 {
     try
     {
         if (error != null)
             throw new Exception( error );
         listener = new TcpListener( port );
         listener.Start();
         OnStart( parent );
         Console.WriteLine( "HTTP Server has started..." );
         while (is_active)
         {
             TcpClient s = listener.AcceptTcpClient();
             var processor = new HttpProcessor( s, this );
             var thread = new Thread( processor.process );
             thread.Start();
             Thread.Sleep( 1 );
         }
     }
     catch (Exception e)
     {
         if (!e.Message.Contains( "WSACancelBlockingCall" ))
         {
             Console.WriteLine( e.Message );
             OnOnError( e.Message );
         }
     }
     Console.WriteLine( "HTTP Server has stopped..." );
 }
Exemplo n.º 8
0
 public abstract void handlePOSTRequest( HttpProcessor p, StreamReader inputData );
Exemplo n.º 9
0
 public abstract void handleGETRequest( HttpProcessor p );