Source Code Cross Referenced for debugserver.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » Laszlo 4.0.10 » org.openlaszlo.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* J_LZ_COPYRIGHT_BEGIN *******************************************************
002:         * Copyright 2001-2006 Laszlo Systems, Inc.  All Rights Reserved.              *
003:         * Use is subject to license terms.                                            *
004:         * J_LZ_COPYRIGHT_END *********************************************************/
005:
006:        package org.openlaszlo.test;
007:
008:        import java.net.*;
009:        import java.io.*;
010:
011:        public class debugserver {
012:            static boolean closed = false;
013:
014:            public static void main(String[] args) throws IOException {
015:
016:                ServerSocket serverSocket = null;
017:                int port = 5559;
018:                if (args.length > 0) {
019:                    try {
020:                        port = Integer.parseInt(args[0]);
021:                    } catch (NumberFormatException e) {
022:                        System.err.println("could not parse port number "
023:                                + args[0]);
024:                    }
025:                }
026:
027:                while (true) {
028:
029:                    try {
030:                        serverSocket = new ServerSocket(port);
031:                    } catch (IOException e) {
032:                        System.err.println("Could not listen on port " + port);
033:                        System.exit(1);
034:                    }
035:
036:                    closed = false;
037:                    try {
038:                        System.out.println("Listening on port " + port);
039:                        final Socket clientSocket = serverSocket.accept();
040:
041:                        System.out.println("Accepting connection on port "
042:                                + port);
043:
044:                        PrintWriter out = new PrintWriter(clientSocket
045:                                .getOutputStream(), true);
046:                        final BufferedReader in = new BufferedReader(
047:                                new InputStreamReader(clientSocket
048:                                        .getInputStream()));
049:                        String inputLine, outputLine;
050:
051:                        int seqnum = 1;
052:
053:                        // socket reader thread
054:                        new Thread() {
055:                            public void run() {
056:                                try {
057:                                    FileWriter of = new FileWriter(
058:                                            "lzdebug.log");
059:                                    PrintWriter outf = new PrintWriter(of);
060:                                    while (true) {
061:                                        try {
062:                                            int ch = in.read();
063:                                            if (ch == -1) {
064:                                                debugserver.closed = true;
065:                                                return;
066:                                            }
067:                                            if (ch == 0) {
068:                                                System.out.println("");
069:                                                outf.println("");
070:                                                outf.flush();
071:                                            } else {
072:                                                System.out.write(ch);
073:                                                outf.write(ch);
074:                                            }
075:                                            if (clientSocket.isClosed()) {
076:                                                debugserver.closed = true;
077:                                                return;
078:                                            }
079:                                        } catch (IOException e) {
080:                                            System.out.println(e);
081:                                            debugserver.closed = true;
082:                                            return;
083:                                        }
084:                                    }
085:                                } catch (IOException e) {
086:                                }
087:                            }
088:                        }.start();
089:
090:                        // If there are command line args, open each one as a filename and send as exec
091:                        if (args.length > 1) {
092:                            for (int n = 1; n < args.length; n++) {
093:                                String fname = args[n];
094:                                try {
095:                                    FileInputStream fis = new FileInputStream(
096:                                            fname);
097:                                    byte b[] = new byte[fis.available()];
098:                                    fis.read(b);
099:                                    String cmd = new String(b);
100:                                    System.out.println("Sent: " + cmd);
101:                                    out.write("<exec seq='" + (seqnum++) + "'>"
102:                                            + escapeXml(cmd) + "</exec>\000");
103:                                    out.flush();
104:                                } catch (IOException e) {
105:                                    System.out.println(e);
106:                                }
107:                            }
108:                        }
109:
110:                        BufferedReader tty = new BufferedReader(
111:                                new InputStreamReader(System.in));
112:                        String expr;
113:
114:                        while (!closed && (expr = tty.readLine()) != null) {
115:                            if (expr.trim().equals(""))
116:                                continue;
117:                            out.write("<eval seq='" + (seqnum++) + "'>"
118:                                    + escapeXml(expr) + "</eval>\000");
119:                            out.flush();
120:                        }
121:
122:                        out.close();
123:                        in.close();
124:                        clientSocket.close();
125:                        serverSocket.close();
126:                        System.out.println("Connection closed");
127:                    } catch (RuntimeException e) {
128:                        System.out.println("Exception " + e);
129:                    }
130:                }
131:            }
132:
133:            /**
134:             * Escape the 5 entities defined by XML. 
135:             * These are: '<', '>', '\', '&', '"'.
136:             * 
137:             * @param s an xml string
138:             * @return an escaped xml string
139:             */
140:            public static String escapeXml(String s) {
141:                if (s == null)
142:                    return null;
143:                StringBuffer sb = new StringBuffer();
144:                for (int i = 0; i < s.length(); i++) {
145:                    char c = s.charAt(i);
146:                    if (c == '<') {
147:                        sb.append("&lt;");
148:                    } else if (c == '>') {
149:                        sb.append("&gt;");
150:                    } else if (c == '\'') {
151:                        sb.append("&apos;");
152:                    } else if (c == '&') {
153:                        sb.append("&amp;");
154:                    } else if (c == '"') {
155:                        sb.append("&quot;");
156:                    } else {
157:                        sb.append(c);
158:                    }
159:                }
160:                return sb.toString();
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.