Source Code Cross Referenced for FitServer.java in  » Wiki-Engine » fitnesse » fit » 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 » Wiki Engine » fitnesse » fit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
002:        // Copyright (c) 2002 Cunningham & Cunningham, Inc.
003:        // Released under the terms of the GNU General Public License version 2 or later.
004:        package fit;
005:
006:        import java.io.*;
007:        import java.net.Socket;
008:        import fitnesse.util.StreamReader;
009:        import fitnesse.components.*;
010:        import fit.exception.FitParseException;
011:
012:        public class FitServer {
013:            public String input;
014:            public Fixture fixture = new Fixture();
015:            public FixtureListener fixtureListener = new TablePrintingFixtureListener();
016:            private Counts counts = new Counts();
017:            private OutputStream socketOutput;
018:            private StreamReader socketReader;
019:            private boolean verbose = false;
020:            private String host;
021:            private int port;
022:            private int socketToken;;
023:            private Socket socket;
024:
025:            public FitServer(String host, int port, boolean verbose) {
026:                this .host = host;
027:                this .port = port;
028:                this .verbose = verbose;
029:            }
030:
031:            public FitServer() {
032:            }
033:
034:            public static void main(String argv[]) throws Exception {
035:                FitServer fitServer = new FitServer();
036:                fitServer.run(argv);
037:                System.exit(fitServer.exitCode());
038:            }
039:
040:            public void run(String argv[]) throws Exception {
041:                args(argv);
042:                establishConnection();
043:                validateConnection();
044:                process();
045:                closeConnection();
046:                exit();
047:            }
048:
049:            public void closeConnection() throws IOException {
050:                socket.close();
051:            }
052:
053:            public void process() {
054:                fixture.listener = fixtureListener;
055:                try {
056:                    int size = 1;
057:                    while ((size = FitProtocol.readSize(socketReader)) != 0) {
058:                        try {
059:                            print("processing document of size: " + size + "\n");
060:                            String document = FitProtocol.readDocument(
061:                                    socketReader, size);
062:                            //TODO MDM if the page name was always the first line of the body, it could be printed here.
063:                            Parse tables = new Parse(document);
064:                            newFixture().doTables(tables);
065:                            print("\tresults: " + fixture.counts() + "\n");
066:                            counts.tally(fixture.counts);
067:                        } catch (FitParseException e) {
068:                            exception(e);
069:                        }
070:                    }
071:                    print("completion signal recieved" + "\n");
072:                } catch (Exception e) {
073:                    exception(e);
074:                }
075:            }
076:
077:            public String readDocument() throws Exception {
078:                int size = FitProtocol.readSize(socketReader);
079:                return FitProtocol.readDocument(socketReader, size);
080:            }
081:
082:            protected Fixture newFixture() {
083:                fixture = new Fixture();
084:                fixture.listener = fixtureListener;
085:                return fixture;
086:            }
087:
088:            public void args(String[] argv) {
089:                CommandLine commandLine = new CommandLine(
090:                        "[-v] host port socketToken");
091:                if (commandLine.parse(argv)) {
092:                    host = commandLine.getArgument("host");
093:                    port = Integer.parseInt(commandLine.getArgument("port"));
094:                    socketToken = Integer.parseInt(commandLine
095:                            .getArgument("socketToken"));
096:                    verbose = commandLine.hasOption("v");
097:                } else
098:                    usage();
099:            }
100:
101:            private void usage() {
102:                System.out
103:                        .println("usage: java fit.FitServer [-v] host port socketTicket");
104:                System.out.println("\t-v\tverbose");
105:                System.exit(-1);
106:            }
107:
108:            protected void exception(Exception e) {
109:                print("Exception occurred!" + "\n");
110:                print("\t" + e.getMessage() + "\n");
111:                Parse tables = new Parse("span", "Exception occurred: ", null,
112:                        null);
113:                fixture.exception(tables, e);
114:                counts.exceptions += 1;
115:                fixture.listener.tableFinished(tables);
116:                fixture.listener.tablesFinished(counts); //TODO shouldn't this be fixture.counts
117:            }
118:
119:            public void exit() throws Exception {
120:                print("exiting" + "\n");
121:                print("\tend results: " + counts.toString() + "\n");
122:            }
123:
124:            public int exitCode() {
125:                return counts.wrong + counts.exceptions;
126:            }
127:
128:            public void establishConnection() throws Exception {
129:                establishConnection(makeHttpRequest());
130:            }
131:
132:            public void establishConnection(String httpRequest)
133:                    throws Exception {
134:                socket = new Socket(host, port);
135:                socketOutput = socket.getOutputStream();
136:                socketReader = new StreamReader(socket.getInputStream());
137:                byte[] bytes = httpRequest.getBytes("UTF-8");
138:                socketOutput.write(bytes);
139:                socketOutput.flush();
140:                print("http request sent" + "\n");
141:            }
142:
143:            private String makeHttpRequest() {
144:                return "GET /?responder=socketCatcher&ticket=" + socketToken
145:                        + " HTTP/1.1\r\n\r\n";
146:            }
147:
148:            public void validateConnection() throws Exception {
149:                print("validating connection...");
150:                int statusSize = FitProtocol.readSize(socketReader);
151:                if (statusSize == 0)
152:                    print("...ok" + "\n");
153:                else {
154:                    String errorMessage = FitProtocol.readDocument(
155:                            socketReader, statusSize);
156:                    print("...failed because: " + errorMessage + "\n");
157:                    System.out
158:                            .println("An error occured while connecting to client.");
159:                    System.out.println(errorMessage);
160:                    System.exit(-1);
161:                }
162:            }
163:
164:            public Counts getCounts() {
165:                return counts;
166:            }
167:
168:            private void print(String message) {
169:                if (verbose)
170:                    System.out.print(message);
171:            }
172:
173:            public static byte[] readTable(Parse table) throws Exception {
174:                ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
175:                OutputStreamWriter streamWriter = new OutputStreamWriter(
176:                        byteBuffer, "UTF-8");
177:                PrintWriter writer = new PrintWriter(streamWriter);
178:                Parse more = table.more;
179:                table.more = null;
180:                if (table.trailer == null)
181:                    table.trailer = "";
182:                table.print(writer);
183:                table.more = more;
184:                writer.close();
185:                return byteBuffer.toByteArray();
186:            }
187:
188:            public void writeCounts(Counts count) throws IOException {
189:                //TODO This can't be right.... which counts should be used?
190:                FitProtocol.writeCounts(counts, socketOutput);
191:            }
192:
193:            class TablePrintingFixtureListener implements  FixtureListener {
194:                public void tableFinished(Parse table) {
195:                    try {
196:                        byte[] bytes = readTable(table);
197:                        if (bytes.length > 0)
198:                            FitProtocol.writeData(bytes, socketOutput);
199:                    } catch (Exception e) {
200:                        e.printStackTrace();
201:                    }
202:                }
203:
204:                public void tablesFinished(Counts count) {
205:                    try {
206:                        FitProtocol.writeCounts(count, socketOutput);
207:                    } catch (IOException e) {
208:                        e.printStackTrace();
209:                    }
210:                }
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.